76 lines
1.5 KiB
Bash
Executable file
76 lines
1.5 KiB
Bash
Executable file
#! /usr/bin/env sh
|
|
|
|
# state
|
|
|
|
## user-configured settings
|
|
TORI_ROOT="$HOME/.config/tori"
|
|
|
|
## global constants
|
|
OS="$(uname -s)"
|
|
|
|
## global state
|
|
base_files=
|
|
bkp_files=
|
|
user_packages=
|
|
system_packages=
|
|
|
|
# behavior
|
|
|
|
## utility functions
|
|
|
|
log() {
|
|
local level="$1" # unimplemented
|
|
local message="$2"
|
|
|
|
if [ -n "$DEBUG" ] && [ $level = debug ]; then
|
|
printf "$(date "+%H:%M:%N") $message\n"
|
|
fi
|
|
}
|
|
|
|
## configuration processing functions
|
|
|
|
scan_directory() {
|
|
local target="$1"
|
|
local files=
|
|
local escaped_config_root="$(echo $TORI_ROOT | sed 's/\//\\\//g')"
|
|
|
|
if [ -d "$target" ]; then
|
|
scan="$(find "$target" -type f)"
|
|
for line in $scan; do
|
|
line="$(echo $line | sed "s/$escaped_config_root\///")"
|
|
files="$line\n$files"
|
|
done
|
|
fi
|
|
|
|
echo "$files"
|
|
}
|
|
|
|
scan_packages() {
|
|
local package_manager
|
|
local args__get_manually_installed
|
|
local system_packages_eval
|
|
|
|
if [ $OS = "FreeBSD" ]; then
|
|
package_manager="pkg"
|
|
args__get_manually_installed='query -e "%a = 0" "%n"'
|
|
fi
|
|
|
|
system_packages=$(eval "$package_manager $args__get_manually_installed")
|
|
user_packages="$(cat $TORI_ROOT/packages | sort | uniq)"
|
|
|
|
if [ "$system_packages" = "$user_packages" ]; then
|
|
log debug "packages match"
|
|
else
|
|
log debug "packages mismatch"
|
|
log debug "system: $system_packages"
|
|
log debug "user: $user_packages"
|
|
fi
|
|
}
|
|
|
|
base_files="$(scan_directory "$TORI_ROOT/base")"
|
|
bkp_files="$(scan_directory "$TORI_ROOT/bkp")"
|
|
|
|
log debug "collected base files:\n$base_files"
|
|
log debug "collected bkp files:\n$bkp_files"
|
|
|
|
scan_packages
|