2023-10-14 22:38:03 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
SYNC_FILES=${SYNC_FILES:-yes}
|
|
|
|
INSTALL_PKGS=${INSTALL_PKGS:-yes}
|
|
|
|
RUN_CMDS=${RUN_CMDS:-yes}
|
|
|
|
PULL_GIT=${PULL_GIT:-yes}
|
2023-10-14 22:38:06 +02:00
|
|
|
TIME_TRACK=${TIME_TRACK:-no}
|
|
|
|
|
|
|
|
ARGS="$@"
|
2023-10-14 22:38:03 +02:00
|
|
|
|
|
|
|
. ./lib/lib.sh
|
|
|
|
|
2023-10-14 22:38:03 +02:00
|
|
|
set -e # Exit on error
|
|
|
|
|
2023-10-14 22:38:03 +02:00
|
|
|
_install_pkgs() {
|
2023-10-14 22:38:04 +02:00
|
|
|
run $SYS_SUDO $PM_COMMAND $PM_UPDATE $PM_NOCONFIRM
|
2023-10-14 22:38:06 +02:00
|
|
|
_APPLICATIONS=""
|
2023-10-14 22:38:03 +02:00
|
|
|
while read -r pkg; do
|
2023-10-14 22:38:06 +02:00
|
|
|
[ -z "$pkg" ] && continue
|
|
|
|
[ "$(echo "$pkg" | cut -c1)" = "#" ] && continue
|
|
|
|
_APPLICATIONS="$_APPLICATIONS $pkg"
|
|
|
|
done <"$1"
|
|
|
|
run $SYS_SUDO $PM_COMMAND $PM_INSTALL $PM_NOCONFIRM $_APPLICATIONS
|
2023-10-14 22:38:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_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
|
|
|
|
}
|
|
|
|
|
2023-10-14 22:38:06 +02:00
|
|
|
ARGS="$@"
|
|
|
|
_skip_next_arg="n"
|
2023-10-14 22:38:03 +02:00
|
|
|
arg_handler() {
|
2023-10-14 22:38:06 +02:00
|
|
|
for arg in $ARGS; do
|
|
|
|
bool $_skip_next_arg && continue
|
|
|
|
|
|
|
|
case $arg in
|
|
|
|
+files) SYNC_FILES=yes ;;
|
|
|
|
-files) SYNC_FILES=no ;;
|
|
|
|
+pkgs) INSTALL_PKGS=yes ;;
|
|
|
|
-pkgs) INSTALL_PKGS=no ;;
|
|
|
|
+cmds) RUN_CMDS=yes ;;
|
|
|
|
-cmds) RUN_CMDS=no ;;
|
|
|
|
+git) PULL_GIT=yes ;;
|
|
|
|
-git) PULL_GIT=no ;;
|
|
|
|
+) SYNC_FILES=yes; INSTALL_PKGS=yes; RUN_CMDS=yes; PULL_GIT=yes ;;
|
|
|
|
-) SYNC_FILES=no; INSTALL_PKGS=no; RUN_CMDS=no; PULL_GIT=no ;;
|
|
|
|
+*)
|
|
|
|
echo "# Unknown argument: $arg"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
echo "# Unknown argument: $arg"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2023-10-14 22:38:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2023-10-14 22:38:06 +02:00
|
|
|
arg_handler
|
|
|
|
|
|
|
|
echo "# hook: PULL_GIT"
|
2023-10-14 22:38:03 +02:00
|
|
|
bool "$PULL_GIT" && run git pull
|
2023-10-14 22:38:06 +02:00
|
|
|
|
|
|
|
echo "# hook: SYNC_FILES (/)"
|
2023-10-14 22:38:03 +02:00
|
|
|
bool "$SYNC_FILES" && run cp -a "./files/%HOME/." "$HOME"
|
2023-10-14 22:38:06 +02:00
|
|
|
|
|
|
|
echo "# hook: SYNC_FILES"
|
2023-10-14 22:38:03 +02:00
|
|
|
bool "$SYNC_FILES" && _sync_files
|
2023-10-14 22:38:06 +02:00
|
|
|
|
|
|
|
echo "# hook: INSTALL_PKGS"
|
2023-10-14 22:38:03 +02:00
|
|
|
bool "$INSTALL_PKGS" && _install_pkgs ./package.list
|
|
|
|
|
2023-10-14 22:38:06 +02:00
|
|
|
echo "# hook: RUN_CMDS"
|
2023-10-14 22:38:03 +02:00
|
|
|
bool "$RUN_CMDS" && _run_cmds
|
2023-10-14 22:38:06 +02:00
|
|
|
|
|
|
|
return 0
|
2023-10-14 22:38:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "# exec: start."
|
2023-10-14 22:38:06 +02:00
|
|
|
if bool $TIME_TRACK; then
|
|
|
|
time main "$@"
|
|
|
|
else
|
|
|
|
main "$@"
|
|
|
|
fi
|
2023-10-14 22:38:03 +02:00
|
|
|
echo "# exec: done."
|