#!/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 set -e # Exit on error _install_pkgs() { run $SYS_SUDO $PM_COMMAND $PM_UPDATE $PM_NOCONFIRM while read -r pkg; do run $SYS_SUDO $PM_COMMAND $PM_INSTALL $PM_NOCONFIRM $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 } err_handler() { echo "Something went wrong!" echo "You can look at what went wrong by running this script more verbosely" echo "Sorry!" } trap err_handler ERR echo "# exec: start." bool ${TIME_TRACK:-no} && time main "$@" || main "$@" echo "# exec: done."