kelson8 revised this gist 4 months ago. Go to revision
1 file changed, 162 insertions
install-zsh.sh(file created)
| @@ -0,0 +1,162 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | ||
| 3 | + | DATE=$(date '+%F') # Date in this format e.g. 2024-01-21 | |
| 4 | + | TIME=$(date '+%I:%M %p') # Time in this format e.g. 3:40PM | |
| 5 | + | ||
| 6 | + | # By default all of these options are set to false. | |
| 7 | + | ||
| 8 | + | # Install ZSH and oy mh zsh | |
| 9 | + | INSTALL_ZSH=false | |
| 10 | + | # Install the .zshrc file | |
| 11 | + | INSTALL_ZSH_FILE=false | |
| 12 | + | # Install power level10k | |
| 13 | + | INSTALL_P10K=false | |
| 14 | + | # Install the zsh plugins | |
| 15 | + | INSTALL_ZSH_PLUGINS=false | |
| 16 | + | # Backup the ZSH file | |
| 17 | + | BACKUP_ZSH_FILE=false | |
| 18 | + | ZSH_FILE=https://gist.kelsoncraft.net/kelson8/b469849533e34e9683012e08e0099e74/raw/HEAD/.zshrc | |
| 19 | + | ZSH_USER_PATH="/home/$USER/.zshrc" | |
| 20 | + | ||
| 21 | + | # New options for root, this is for installing ZSH to the root user. | |
| 22 | + | ZSH_ROOT_PATH="/root/.zshrc" | |
| 23 | + | # If this is set to true, this will install zshrc and powerlevel10k | |
| 24 | + | # to the root user instaed of the current user. | |
| 25 | + | ZSH_ROOT_MODE=false | |
| 26 | + | ||
| 27 | + | # This needs git and curl installed on a base Debian 12 install. | |
| 28 | + | ||
| 29 | + | function install_zsh(){ | |
| 30 | + | # TODO Check if zsh is currently installed, untested | |
| 31 | + | # This seems to not attempt to reinstall zsh if it sees the file | |
| 32 | + | # but I don't know if it'll install it if it doesn't see it. | |
| 33 | + | if [ ! -f "/bin/zsh" ]; then | |
| 34 | + | ||
| 35 | + | # TODO Check if installing system is debian or arch | |
| 36 | + | if [ -f "/etc/arch-release" ]; then | |
| 37 | + | sudo pacman -S zsh -y | |
| 38 | + | fi | |
| 39 | + | ||
| 40 | + | # This part of the script is confirmed tested and working on Debian 12 | |
| 41 | + | # This seems to exist on both Ubuntu 24.04 and Debian 12 | |
| 42 | + | if [ -f "/etc/debian_version" ]; then | |
| 43 | + | sudo apt install zsh -y | |
| 44 | + | fi | |
| 45 | + | # | |
| 46 | + | fi | |
| 47 | + | ||
| 48 | + | if [ "$ZSH_ROOT_MODE" == "true" ]; then | |
| 49 | + | # Switch to root user folder. | |
| 50 | + | cd "/root" || exit | |
| 51 | + | # Setup oh my zsh | |
| 52 | + | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
| 53 | + | ||
| 54 | + | # Backup current .zshrc and replace it if the option is enabled | |
| 55 | + | if [ "$BACKUP_ZSH_FILE" == "true" ]; then | |
| 56 | + | cp "/root/.zshrc" "/root/.zshrc.bak" | |
| 57 | + | fi | |
| 58 | + | ||
| 59 | + | if [ "$INSTALL_ZSH_FILE" == "true" ]; then | |
| 60 | + | install_zsh_file | |
| 61 | + | fi | |
| 62 | + | ||
| 63 | + | # Print the date and time, and that it was installed. | |
| 64 | + | echo "$DATE @ $TIME Zsh installed for root user!" | |
| 65 | + | # Regular user install | |
| 66 | + | else | |
| 67 | + | cd "/home/$USER" || exit | |
| 68 | + | # Setup oh my zsh | |
| 69 | + | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
| 70 | + | ||
| 71 | + | ||
| 72 | + | # Backup current .zshrc and replace it if the option is enabled | |
| 73 | + | if [ "$BACKUP_ZSH_FILE" == "true" ]; then | |
| 74 | + | cp "/home/$USER/.zshrc" "/home/$USER/.zshrc.bak" | |
| 75 | + | fi | |
| 76 | + | ||
| 77 | + | if [ "$INSTALL_ZSH_FILE" == "true" ]; then | |
| 78 | + | install_zsh_file | |
| 79 | + | fi | |
| 80 | + | ||
| 81 | + | # This already asks the user to replace the current shell, disabled | |
| 82 | + | # sudo -u "$USER" chsh -s /bin/zsh | |
| 83 | + | ||
| 84 | + | # Print the date and time, and that it was installed. | |
| 85 | + | echo "$DATE @ $TIME Zsh installed for user $USER!" | |
| 86 | + | ||
| 87 | + | fi | |
| 88 | + | } | |
| 89 | + | ||
| 90 | + | # Put the zsh file from the git url into the path set above. | |
| 91 | + | # Changed this to work with root or regular user. | |
| 92 | + | function install_zsh_file() { | |
| 93 | + | if [ "$ZSH_ROOT_MODE" == "true" ]; then | |
| 94 | + | wget $ZSH_FILE -O "$ZSH_ROOT_PATH" | |
| 95 | + | else | |
| 96 | + | wget $ZSH_FILE -O "$ZSH_USER_PATH" | |
| 97 | + | fi | |
| 98 | + | } | |
| 99 | + | ||
| 100 | + | function install_p10k() { | |
| 101 | + | if [ "$ZSH_ROOT_MODE" == "true" ]; then | |
| 102 | + | # Root user install | |
| 103 | + | # Install powerlevel10k | |
| 104 | + | git clone https://github.com/romkatv/powerlevel10k.git "/root/.oh-my-zsh/custom/themes/powerlevel10k" | |
| 105 | + | # Regular user install | |
| 106 | + | else | |
| 107 | + | # Install powerlevel10k, I had to add $USERHOME since sudo was putting it in /themes/ | |
| 108 | + | git clone https://github.com/romkatv/powerlevel10k.git "/home/$USER/.oh-my-zsh/custom/themes/powerlevel10k" | |
| 109 | + | fi | |
| 110 | + | } | |
| 111 | + | ||
| 112 | + | function install_zsh_plugins() { | |
| 113 | + | if [ "$ZSH_ROOT_MODE" == "true" ]; then | |
| 114 | + | # Root user install | |
| 115 | + | # Syntax highlighting | |
| 116 | + | git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "/root/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" | |
| 117 | + | # Auto suggestions | |
| 118 | + | git clone https://github.com/zsh-users/zsh-autosuggestions "/root/.oh-my-zsh/custom/plugins/zsh-autosuggestions" | |
| 119 | + | # Oh my zsh auto update | |
| 120 | + | git clone https://github.com/Pilaton/OhMyZsh-full-autoupdate.git "/root/.oh-my-zsh/custom/plugins/ohmyzsh-full-autoupdate" | |
| 121 | + | ||
| 122 | + | # Regular user install | |
| 123 | + | else | |
| 124 | + | # Syntax highlighting | |
| 125 | + | git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "/home/$USER/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" | |
| 126 | + | # Auto suggestions | |
| 127 | + | git clone https://github.com/zsh-users/zsh-autosuggestions "/home/$USER/.oh-my-zsh/custom/plugins/zsh-autosuggestions" | |
| 128 | + | # Oh my zsh auto update | |
| 129 | + | git clone https://github.com/Pilaton/OhMyZsh-full-autoupdate.git "/home/$USER/.oh-my-zsh/custom/plugins/ohmyzsh-full-autoupdate" | |
| 130 | + | fi | |
| 131 | + | } | |
| 132 | + | ||
| 133 | + | function main() { | |
| 134 | + | # Make sure git is installed, if not exit | |
| 135 | + | if ! git --version >/dev/null 2>&1 | |
| 136 | + | then | |
| 137 | + | echo "Git is not installed! It is required for this to run." | |
| 138 | + | exit 1 | |
| 139 | + | fi | |
| 140 | + | ||
| 141 | + | # Install zsh | |
| 142 | + | if [ $INSTALL_ZSH == "true" ]; then | |
| 143 | + | install_zsh | |
| 144 | + | fi | |
| 145 | + | ||
| 146 | + | # Install power level 10k | |
| 147 | + | if [ $INSTALL_P10K == "true" ]; then | |
| 148 | + | install_p10k | |
| 149 | + | fi | |
| 150 | + | ||
| 151 | + | # Install my custom plugins | |
| 152 | + | if [ $INSTALL_ZSH_PLUGINS == "true" ]; then | |
| 153 | + | install_zsh_plugins | |
| 154 | + | fi | |
| 155 | + | ||
| 156 | + | # This already runs if install zsh is enabled, do nothing if it's enabled. | |
| 157 | + | if [ $INSTALL_ZSH == "false" ] && [ "$INSTALL_ZSH_FILE" == "true" ]; then | |
| 158 | + | install_zsh_file | |
| 159 | + | fi | |
| 160 | + | } | |
| 161 | + | ||
| 162 | + | main | |
Newer
Older