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}
|
2023-01-26 15:13:35 +01:00
|
|
|
TIME_TRACK=${TIME_TRACK:-no}
|
|
|
|
|
|
|
|
ARGS="$@"
|
2022-12-16 14:23:28 +01:00
|
|
|
|
|
|
|
. ./lib/lib.sh
|
|
|
|
|
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
|
2023-01-26 15:13:35 +01:00
|
|
|
_APPLICATIONS=""
|
2022-12-16 14:23:28 +01:00
|
|
|
while read -r pkg; do
|
2023-01-26 15:13:35 +01:00
|
|
|
[ -z "$pkg" ] && continue
|
|
|
|
[ "$(echo "$pkg" | cut -c1)" = "#" ] && continue
|
|
|
|
_APPLICATIONS="$_APPLICATIONS $pkg"
|
|
|
|
done <"$1"
|
|
|
|
run $SYS_SUDO $PM_COMMAND $PM_INSTALL $PM_NOCONFIRM $_APPLICATIONS
|
2022-12-16 14:23:28 +01: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-01-26 15:13:35 +01:00
|
|
|
ARGS="$@"
|
|
|
|
_skip_next_arg="n"
|
2022-12-16 14:23:28 +01:00
|
|
|
arg_handler() {
|
2023-01-26 15:13:35 +01: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
|
2022-12-16 14:23:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2023-01-26 15:13:35 +01:00
|
|
|
arg_handler
|
|
|
|
|
|
|
|
echo "# hook: PULL_GIT"
|
2022-12-16 14:23:28 +01:00
|
|
|
bool "$PULL_GIT" && run git pull
|
2023-01-26 15:13:35 +01:00
|
|
|
|
|
|
|
echo "# hook: SYNC_FILES (/)"
|
2022-12-16 14:23:28 +01:00
|
|
|
bool "$SYNC_FILES" && run cp -a "./files/%HOME/." "$HOME"
|
2023-01-26 15:13:35 +01:00
|
|
|
|
|
|
|
echo "# hook: SYNC_FILES"
|
2022-12-16 14:23:28 +01:00
|
|
|
bool "$SYNC_FILES" && _sync_files
|
2023-01-26 15:13:35 +01:00
|
|
|
|
|
|
|
echo "# hook: INSTALL_PKGS"
|
2022-12-16 14:23:28 +01:00
|
|
|
bool "$INSTALL_PKGS" && _install_pkgs ./package.list
|
|
|
|
|
2023-01-26 15:13:35 +01:00
|
|
|
echo "# hook: RUN_CMDS"
|
2022-12-16 14:23:28 +01:00
|
|
|
bool "$RUN_CMDS" && _run_cmds
|
2023-01-26 15:13:35 +01:00
|
|
|
|
|
|
|
return 0
|
2022-12-16 14:23:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "# exec: start."
|
2023-01-26 15:13:35 +01:00
|
|
|
if bool $TIME_TRACK; then
|
|
|
|
time main "$@"
|
|
|
|
else
|
|
|
|
main "$@"
|
|
|
|
fi
|
2022-12-16 14:23:28 +01:00
|
|
|
echo "# exec: done."
|