dotfiles/sync.sh
2022-12-16 14:28:48 +01:00

62 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
SYNC_FILES=${SYNC_FILES:-yes}
INSTALL_PKGS=${INSTALL_PKGS:-yes}
RUN_CMDS=${RUN_CMDS:-yes}
PULL_GIT=${PULL_GIT:-yes}
. ./lib/lib.sh
. ./sync.conf
set -e # Exit on error
_install_pkgs() {
while read -r pkg; do
run $SYS_SUDO $PM_COMMAND $PM_INSTALL_ARG $PM_NOCONFIRM_ARG $pkg
done <$1
}
_sync_files() {
#copy all files and folders from ./files to /
#except for ./files/%HOME
for item in ./files/*; do
[ "$item" = "./files/%HOME" ] && continue
# e.g. ./files/etc -> /etc
run mkdir -p "$SYS_ROOT/$(basename "${item#./files/}")"
run $SYS_SUDO cp -r "$item/." "$SYS_ROOT/${item#./files/}"
done
}
_run_cmds() {
while read -r cmd; do
if [ "$(echo "$cmd" | cut -c1)" = "^" ]; then
run $SYS_SUDO sh -c "$(echo "$cmd" | cut -c2-)"
else
run sh -c "$cmd"
fi
done <./command.list
}
arg_handler() {
case $1 in
--graphical|-g)
bool "$INSTALL_PKGS" && _install_pkgs ./gpackage.list
;;
esac
}
main() {
bool "$PULL_GIT" && run git pull
bool "$SYNC_FILES" && run cp -a "./files/%HOME/." "$HOME"
bool "$SYNC_FILES" && _sync_files
bool "$INSTALL_PKGS" && _install_pkgs ./package.list
arg_handler "$@"
bool "$RUN_CMDS" && _run_cmds
}
echo "# exec: start."
time main "$@"
echo "# exec: done."