dotfiles/sync.sh

64 lines
1.3 KiB
Bash
Raw Normal View History

2022-12-16 14:23:28 +01:00
#!/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
2022-12-16 14:28:48 +01:00
set -e # Exit on error
2022-12-16 14:23:28 +01:00
_install_pkgs() {
2022-12-18 21:43:34 +01:00
run $SYS_SUDO $PM_COMMAND $PM_UPDATE $PM_NOCONFIRM
2022-12-16 14:23:28 +01:00
while read -r pkg; do
2022-12-18 21:43:34 +01:00
run $SYS_SUDO $PM_COMMAND $PM_INSTALL $PM_NOCONFIRM $pkg
2022-12-16 14:23:28 +01:00
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."
2022-12-18 21:43:34 +01:00
[ bool ${TIME_TRACK:-no} ] && time main "$@" || main "$@"
2022-12-16 14:23:28 +01:00
echo "# exec: done."