#!/bin/bash DATE=$(date '+%F') # Date in this format e.g. 2024-01-21 TIME=$(date '+%I:%M %p') # Time in this format e.g. 3:40PM # By default all of these options are set to false. # Install ZSH and oy mh zsh INSTALL_ZSH=false # Install the .zshrc file INSTALL_ZSH_FILE=false # Install power level10k INSTALL_P10K=false # Install the zsh plugins INSTALL_ZSH_PLUGINS=false # Backup the ZSH file BACKUP_ZSH_FILE=false ZSH_FILE=https://gist.kelsoncraft.net/kelson8/b469849533e34e9683012e08e0099e74/raw/HEAD/.zshrc ZSH_USER_PATH="/home/$USER/.zshrc" # New options for root, this is for installing ZSH to the root user. ZSH_ROOT_PATH="/root/.zshrc" # If this is set to true, this will install zshrc and powerlevel10k # to the root user instaed of the current user. ZSH_ROOT_MODE=false # This needs git and curl installed on a base Debian 12 install. function install_zsh(){ # TODO Check if zsh is currently installed, untested # This seems to not attempt to reinstall zsh if it sees the file # but I don't know if it'll install it if it doesn't see it. if [ ! -f "/bin/zsh" ]; then # TODO Check if installing system is debian or arch if [ -f "/etc/arch-release" ]; then sudo pacman -S zsh -y fi # This part of the script is confirmed tested and working on Debian 12 # This seems to exist on both Ubuntu 24.04 and Debian 12 if [ -f "/etc/debian_version" ]; then sudo apt install zsh -y fi # fi if [ "$ZSH_ROOT_MODE" == "true" ]; then # Switch to root user folder. cd "/root" || exit # Setup oh my zsh sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" # Backup current .zshrc and replace it if the option is enabled if [ "$BACKUP_ZSH_FILE" == "true" ]; then cp "/root/.zshrc" "/root/.zshrc.bak" fi if [ "$INSTALL_ZSH_FILE" == "true" ]; then install_zsh_file fi # Print the date and time, and that it was installed. echo "$DATE @ $TIME Zsh installed for root user!" # Regular user install else cd "/home/$USER" || exit # Setup oh my zsh sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" # Backup current .zshrc and replace it if the option is enabled if [ "$BACKUP_ZSH_FILE" == "true" ]; then cp "/home/$USER/.zshrc" "/home/$USER/.zshrc.bak" fi if [ "$INSTALL_ZSH_FILE" == "true" ]; then install_zsh_file fi # This already asks the user to replace the current shell, disabled # sudo -u "$USER" chsh -s /bin/zsh # Print the date and time, and that it was installed. echo "$DATE @ $TIME Zsh installed for user $USER!" fi } # Put the zsh file from the git url into the path set above. # Changed this to work with root or regular user. function install_zsh_file() { if [ "$ZSH_ROOT_MODE" == "true" ]; then wget $ZSH_FILE -O "$ZSH_ROOT_PATH" else wget $ZSH_FILE -O "$ZSH_USER_PATH" fi } function install_p10k() { if [ "$ZSH_ROOT_MODE" == "true" ]; then # Root user install # Install powerlevel10k git clone https://github.com/romkatv/powerlevel10k.git "/root/.oh-my-zsh/custom/themes/powerlevel10k" # Regular user install else # Install powerlevel10k, I had to add $USERHOME since sudo was putting it in /themes/ git clone https://github.com/romkatv/powerlevel10k.git "/home/$USER/.oh-my-zsh/custom/themes/powerlevel10k" fi } function install_zsh_plugins() { if [ "$ZSH_ROOT_MODE" == "true" ]; then # Root user install # Syntax highlighting git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "/root/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" # Auto suggestions git clone https://github.com/zsh-users/zsh-autosuggestions "/root/.oh-my-zsh/custom/plugins/zsh-autosuggestions" # Oh my zsh auto update git clone https://github.com/Pilaton/OhMyZsh-full-autoupdate.git "/root/.oh-my-zsh/custom/plugins/ohmyzsh-full-autoupdate" # Regular user install else # Syntax highlighting git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "/home/$USER/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" # Auto suggestions git clone https://github.com/zsh-users/zsh-autosuggestions "/home/$USER/.oh-my-zsh/custom/plugins/zsh-autosuggestions" # Oh my zsh auto update git clone https://github.com/Pilaton/OhMyZsh-full-autoupdate.git "/home/$USER/.oh-my-zsh/custom/plugins/ohmyzsh-full-autoupdate" fi } function main() { # Make sure git is installed, if not exit if ! git --version >/dev/null 2>&1 then echo "Git is not installed! It is required for this to run." exit 1 fi # Install zsh if [ $INSTALL_ZSH == "true" ]; then install_zsh fi # Install power level 10k if [ $INSTALL_P10K == "true" ]; then install_p10k fi # Install my custom plugins if [ $INSTALL_ZSH_PLUGINS == "true" ]; then install_zsh_plugins fi # This already runs if install zsh is enabled, do nothing if it's enabled. if [ $INSTALL_ZSH == "false" ] && [ "$INSTALL_ZSH_FILE" == "true" ]; then install_zsh_file fi } main