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