diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2020-06-12 16:24:12 +0100 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2020-06-12 16:24:12 +0100 |
| commit | cfbbf284e8eefd0f84f5c4e4fb76277a79325571 (patch) | |
| tree | 862c70b8038ba666c44cb79c7b6181766c8b3528 | |
| parent | 6d6c836790c726a3add220eaeef225a8b895e165 (diff) | |
Add dotfiles
| -rw-r--r-- | gohan.sh | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -6,11 +6,13 @@ ### OPTIONS AND VARIABLES ### while getopts ":p:h" o; do case "${o}" in - h) printf "Optional arguments for custom use:\\n -p: Dependencies and programs csv (local file or url)\\n -h: Show this message\\n" && exit ;; + h) printf "Optional arguments for custom use:\\n -r: Dotfiles repository\\n -p: Dependencies and programs csv (local file or url)\\n -h: Show this message\\n" && exit ;; + r) dotfilesrepo=${OPTARG} && git ls-remote "$dotfilesrepo" || exit ;; p) packages=${OPTARG} ;; *) printf "Invalid option: -%s\\n" "$OPTARG" && exit ;; esac done +[ -z "$dotfilesrepo" ] && dotfilesrepo="https://github.com/davidtsadler/dotfiles.git" [ -z "$packages" ] && packages="https://raw.githubusercontent.com/davidtsadler/gohan/master/packages.csv" ### FUNCTIONS ### @@ -58,10 +60,22 @@ add_user() { dialog --infobox "Adding user \"$name\"..." 4 50 useradd -m -s /bin/bash "$name" >/dev/null 2>&1 || mkdir -p /home/"$name" && chown "$name":"$name" /home/"$name" [ ! -d "/home/$name/.local/src" ] && mkdir -p "/home/$name/.local/src" && chown -R "$name":"$name" /home/"$name/.local" + # Remove these files as they will be installed as part of the dotfiles. + [ -f "/home/$name/.bash_logout" ] && rm /home/$name/.bash_logout + [ -f "/home/$name/.bash_profile" ] && rm /home/$name/.bash_profile + [ -f "/home/$name/.bashrc" ] && rm /home/$name/.bashrc echo "$name:$pass1" | chpasswd unset pass1 pass2 } +install_dotfiles() { + dialog --infobox "Downloading and installing dotfiles..." 4 60 + [ ! -d "$2" ] && mkdir -p "$2" && chown -R "$name":"$name" "$2" + sudo -u "$name" git clone --bare --depth 1 "$1" "$2" >/dev/null 2>&1 + sudo -u "$name" git --git-dir="$2" --work-tree=$HOME checkout + sudo -u "$name" git --git-dir="$2" --work-tree=$HOME config --local status.showUntrackedFiles no +} + install_software() { ([ -f "$packages" ] && cp "$packages" /tmp/packages.csv) || curl -Ls "$packages" > /tmp/packages.csv total=$(wc -l < /tmp/packages.csv) @@ -104,6 +118,8 @@ preinstall_msg || error "User exited." add_user || error "Error adding username and/or password." +install_dotfiles $dotfilesrepos "/home/$name/.local/src" + install_software clear |
