diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 19cb8d2..5f22488 100644 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -1,124 +1,74 @@ #!/bin/bash set -e -echo 'export SENTRY_DSN=https://4d089076433c4a7aa31bbb2741f053fe@sentry.aenow.com/3' + +# Sentry setup +echo 'export SENTRY_DSN=https://4d089076433c4a7aa31bbb2741f053fe@sentry.aenow.com/3' >> ~/.zshrc eval "$(sentry-cli bash-hook)" -## DigitalOcean's API for obtaining server metadata. -function digitalocean() { + +# Functions for provider-specific configurations +digitalocean() { export HOSTNAME=$(curl -s http://169.254.169.254/metadata/v1/hostname) - hostnamectl set-hostname $HOSTNAME - # echo $HOSTNAME > /etc/hostname - # hostname -F /etc/hostname - # hostname -f + hostnamectl set-hostname "$HOSTNAME" export PUBLIC_IPV4=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address) export PUBLIC_IPV6=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv6/address) } -## Add anything for OVH here. -function ovh() { - echo Nothing special for DigitalOcean at this stage. + +ovh() { + echo "Nothing special for OVH at this stage." } -## Choose which DC provider sepecifics need installed. + +# Provider setup case $1 in - digitalocean ) - digitalocean - ;; - ovh ) - ovh - ;; - none ) - echo Nothing special going to be done here. - ;; - * ) - echo bootstrap options are: - echo bootstrap ovh [gluster/nogluster] [salt/nosalt] - echo bootstrap digitalocean [gluster/nogluster] [salt/nosalt] - echo bootstrap none [gluster/nogluster] [salt/nosalt] - ;; + digitalocean) digitalocean ;; + ovh) ovh ;; + none) echo "Nothing special going to be done here." ;; + *) echo "bootstrap options are:" + echo "bootstrap ovh [salt/nosalt]" + echo "bootstrap digitalocean [salt/nosalt]" + echo "bootstrap none [salt/nosalt]" ;; esac -function install_salt() { - # ## Installing Salt for Ubuntu 20.04 - # curl -fsSL -o /usr/share/keyrings/salt-archive-keyring.gpg https://repo.saltproject.io/py3/ubuntu/20.04/amd64/latest/salt-archive-keyring.gpg - # echo "deb [signed-by=/usr/share/keyrings/salt-archive-keyring.gpg arch=amd64] https://repo.saltproject.io/py3/ubuntu/20.04/amd64/latest focal main" | sudo tee /etc/apt/sources.list.d/salt.list + +# Salt installation +install_salt() { sudo curl -fsSL -o /usr/share/keyrings/salt-archive-keyring.gpg https://repo.saltproject.io/salt/py3/ubuntu/22.04/amd64/latest/salt-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/salt-archive-keyring.gpg arch=amd64] https://repo.saltproject.io/salt/py3/ubuntu/22.04/amd64/latest jammy main" | sudo tee /etc/apt/sources.list.d/salt.list mkdir -p /etc/salt/minion.d/ - echo 'master: rios.aenow.fun' > /etc/salt/minion.d/99-master-address.conf + echo 'master: aerence.aenow.fun' > /etc/salt/minion.d/99-master-address.conf apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y salt-minion } -function install_gluster_pre() { - ## Installing Glusterfs-7 https://www.digitalocean.com/community/tutorials/how-to-create-a-redundant-storage-pool-using-glusterfs-on-ubuntu-20-04 - apt-get update && apt-get -y install software-properties-common dirmngr apt-transport-https lsb-release ca-certificates - echo |add-apt-repository ppa:gluster/glusterfs-7 -} -function install_gluster_post() { - DEBIAN_FRONTEND=noninteractive apt-get install -y glusterfs-server glusterfs-client -} -## Install Container Top ctop -echo "deb http://packages.azlux.fr/debian/ buster main" | sudo tee /etc/apt/sources.list.d/azlux.list -wget -qO - https://azlux.fr/repo.gpg.key | sudo apt-key add - -## Install Gluster Pre -echo Gluster Pre Function + +# Salt installation based on user selection case $2 in - gluster ) - install_gluster_pre - ;; - nogluster ) - echo not installing gluster. - ;; - * ) - echo no gluster instructions received. - echo options are: - echo bootstrap [hostingProvider] gluster [salt/nosalt] - echo bootstrap [hostingProvider] nogluster [salt/nosalt] - ;; + salt) install_salt ;; + nosalt) echo "Not installing salt." ;; + *) echo "No salt instructions received." + echo "Options are:" + echo "bootstrap [hostingProvider] salt" + echo "bootstrap [hostingProvider] nosalt" ;; esac -## Installing packages -echo Installing Apt Packages + +# Apt package installations +echo "Installing Apt Packages" apt-get update DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::='--force-confold' --force-yes -fuy dist-upgrade DEBIAN_FRONTEND=noninteractive apt-get install -y asciinema ca-certificates gnupg git glances htop iftop zsh apt-get update -## Install Gluster Post -echo Gluster Post Function -case $2 in - gluster ) - install_gluster_post - ;; - nogluster ) - echo not installing gluster. - ;; -esac -## Install salt -echo Installing Salt -case $3 in - salt ) - install_salt - - ;; - nosalt ) - echo Not installing salt. - ;; - * ) - echo no salt instructions received. - echo options are: - echo bootstrap [hostingProvider] [gluster/nogluster] salt - echo bootstrap [hostingProvider] [gluster/nogluster] nosalt - ;; -esac -## Install docker-compose and docker using convenience scripts -echo Install docker-compose and docker via convenience scripts +# Docker and docker-compose installation +echo "Install docker-compose and docker via convenience scripts" curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose curl -fsSL https://get.docker.com -o get-docker.sh sh get-docker.sh DEBIAN_FRONTEND=noninteractive apt-get install -y docker-compose-plugin -## Install CTOP Container Top https://github.com/bcicen/ctop + +# CTOP installation +echo "Installing CTOP" wget https://github.com/bcicen/ctop/releases/download/v0.7.7/ctop-0.7.7-linux-amd64 -O /usr/local/bin/ctop chmod +x /usr/local/bin/ctop -## This may no longer be required going forward, it'll be better to call it on first login instead with args. - ## Force install ohmyzsh on first login - curl -o /root/zsh-setup.sh https://bootstrap:sHEG3NTC6og8pCJDTF6EPYb8jLmbskx5Ns@git.nixc.us/colin/bootstrap-scripts/raw/branch/main/scripts/zsh-setup.sh - echo zsh-setup >> ~/.profile - source ~/.profile +# Setup Oh My Zsh on first login +curl -o /root/zsh-setup.sh https://bootstrap:sHEG3NTC6og8pCJDTF6EPYb8jLmbskx5Ns@git.nixc.us/colin/bootstrap-scripts/raw/branch/main/scripts/zsh-setup.sh +echo "zsh-setup" >> ~/.profile +source ~/.profile diff --git a/scripts/zsh-setup.sh b/scripts/zsh-setup.sh index 8a55a2c..9de8f02 100644 --- a/scripts/zsh-setup.sh +++ b/scripts/zsh-setup.sh @@ -1,100 +1,68 @@ #!/usr/bin/env bash -## Setup ZSH and ohmyzsh theme -# cd ~/ + USRDIR=$(echo ~) -sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended -# echo y|sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" -sed -i'' -e 's@ZSH_THEME="robbyrussell"@ZSH_THEME="pygmalion"@' $USRDIR/.zshrc -## Just install sentry DSN server info here. -function ae_sentry() { - # https://4d089076433c4a7aa31bbb2741f053fe@sentry.aenow.com/3 - echo 'export SENTRY_DSN=https://4d089076433c4a7aa31bbb2741f053fe@sentry.aenow.com/3' >> $USRDIR/.zshrc +# Simplify installation command +curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | sh -s -- --unattended + +# Update ZSH theme directly +sed -i'' -e 's@ZSH_THEME="robbyrussell"@ZSH_THEME="pygmalion"@' "$USRDIR/.zshrc" + +ae_sentry() { + echo 'export SENTRY_DSN=https://4d089076433c4a7aa31bbb2741f053fe@sentry.aenow.com/3' >> "$USRDIR/.zshrc" } -## DigitalOcean's API for obtaining server metadata. -function digitalocean() { - echo 'export PUBLIC_IPV4=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)' >> $USRDIR/.zshrc - echo 'export PUBLIC_IPV6=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv6/address)' >> $USRDIR/.zshrc +digitalocean() { + echo 'export PUBLIC_IPV4=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)' >> "$USRDIR/.zshrc" + echo 'export PUBLIC_IPV6=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv6/address)' >> "$USRDIR/.zshrc" } -## Add anything for OVH here. -function ovh() { - echo Nothing to see here at the moment. +ovh() { + echo "Nothing to see here at the moment." } -## Choose which DC provider sepecifics need installed. +configure_plugins() { + # Clone only if directory does not exist to prevent errors on rerun + [ ! -d "${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" ] && git clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" + [ ! -d "${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting" ] && git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting" + [ ! -d "${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/zsh-history-substring-search" ] && git clone https://github.com/zsh-users/zsh-history-substring-search "${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/zsh-history-substring-search" + [ ! -d "${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/command-time" ] && git clone https://github.com/popstas/zsh-command-time.git "${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/command-time" + + cat <> "$USRDIR/.zshrc" +ZSH_COMMAND_TIME_MIN_SECONDS=3 +ZSH_COMMAND_TIME_MSG="Execution time: %s" +ZSH_COMMAND_TIME_COLOR="cyan" +ZSH_COMMAND_TIME_EXCLUDE=(vim mcedit nano ctop ssh) +EOF + + sed -i'' -e 's@plugins=(git)@plugins=(git cp colored-man-pages docker docker-compose extract iterm2 python rsync safe-paste transfer ubuntu zsh-navigation-tools zsh-autosuggestions zsh-syntax-highlighting zsh-history-substring-search command-time universalarchive)@' "$USRDIR/.zshrc" +} + +# Process options case $1 in - digitalocean ) - digitalocean - ;; - ovh ) - ovh - ;; - none ) - echo Nothing special going to be done here. - ;; - * ) - echo zsh-setup.sh options are: - echo zsh-setup.sh ovh - echo zsh-setup.sh digitalocean - echo zsh-setup.sh none - ;; + digitalocean) digitalocean ;; + ovh) ovh ;; + *) echo "Usage: zsh-setup.sh [digitalocean|ovh|none]" ;; esac case $2 in - ae-sentry ) - ae_sentry - ;; - my-sentry ) - echo "buy a server for this you poor old sodd" - ;; - none ) - echo You have elected to not add a Sentry server. - ;; - * ) - echo No sentry option chosen however one must be chosen. The options are: - echo "zsh-setup.sh hosting-provider ae-sentry" - echo "zsh-setup.sh hosting-provider my-sentry" - echo "zsh-setup.sh hosting-provider none" - ;; + ae-sentry) ae_sentry ;; + none) echo "No Sentry server added." ;; + *) echo "Usage: zsh-setup.sh hosting-provider [ae-sentry|my-sentry|none]" ;; esac -## Docker build fast -echo "export DOCKER_BUILDKIT=1 # or configure in daemon.json" >> ~/.zshrc -echo "export COMPOSE_DOCKER_CLI_BUILD=1" >> ~/.zshrc +echo "export DOCKER_BUILDKIT=1" >> "$USRDIR/.zshrc" +echo "export COMPOSE_DOCKER_CLI_BUILD=1" >> "$USRDIR/.zshrc" -## Install Plugins - ## Auto Suggestions - git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/zsh-autosuggestions - ## Syntax Highlighting - git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting - ## History Substring search. - git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/zsh-history-substring-search - ## ZSH Command Execution Time - git clone https://github.com/popstas/zsh-command-time.git ${ZSH_CUSTOM:-$USRDIR/.oh-my-zsh/custom}/plugins/command-time - ## Configure plugins and envvars. - cat <> ~/.zshrc - # If command execution time above min. time, plugins will not output time. - ZSH_COMMAND_TIME_MIN_SECONDS=3 +configure_plugins - # Message to display (set to "" for disable). - ZSH_COMMAND_TIME_MSG="Execution time: %s" +sed -i'' -e "/bash \$USRDIR\/zsh-setup.sh/d" "$USRDIR/.profile" - # Message color. - ZSH_COMMAND_TIME_COLOR="cyan" +# Consider not removing the script automatically for debugging or rerun +# rm -f "$USRDIR/zsh-setup.sh" - # Exclude some commands - ZSH_COMMAND_TIME_EXCLUDE=(vim mcedit nano ctop ssh) -EOF - -## Enable plugins -sed -i'' -e 's@plugins=(git)@plugins=(git cp colored-man-pages docker docker-compose extract iterm2 python rsync safe-paste transfer ubuntu zsh-navigation-tools zsh-autosuggestions zsh-syntax-highlighting zsh-history-substring-search command-time universalarchive)@' $USRDIR/.zshrc - -## Cleanup -sed -i'' -e 's@bash $USRDIR/zsh-setup.sh@@' $USRDIR/.profile -#rm -f $USRDIR/zsh-setup.sh echo "Relog into terminal finished bootstrapping server" -chsh -s $(which zsh) + +chsh -s "$(which zsh)" zsh -source $USRDIR/.zshrc +source "$USRDIR/.zshrc" diff --git a/strap.sh b/strap.sh index cd6e605..73a519b 100644 --- a/strap.sh +++ b/strap.sh @@ -1,52 +1,27 @@ #!/usr/bin/env bash set -e -## Basic deps -DEBIAN_FRONTEND=noninteractive apt-get install -y curl wget +# Basic dependencies installation +DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y curl wget -## source <(curl -s https://git.nixc.us/colin/bootstrap-scripts/raw/branch/main/strap.sh) defaults-bootstrap -# curl -sL https://sentry.io/get-cli/ | bash -# echo 'export SENTRY_DSN=https://4d089076433c4a7aa31bbb2741f053fe@sentry.aenow.com/3' -# eval "$(sentry-cli bash-hook)" +# Downloading bootstrap scripts curl -o /usr/local/sbin/zsh-setup https://git.nixc.us/colin/bootstrap-scripts/raw/branch/main/scripts/zsh-setup.sh && chmod +x /usr/local/sbin/zsh-setup curl -o /usr/local/sbin/bootstrap https://git.nixc.us/colin/bootstrap-scripts/raw/branch/main/scripts/bootstrap.sh && chmod +x /usr/local/sbin/bootstrap -echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLT6xx+pXQl6UfiVe0VTZkC45E/2YE/zfNrWb7mLMtI computer@dewitt.improvingmipractices.com" > /root/.ssh/authorized_keys -## Run bootstrap +# Update Dewitt SSH key +echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICxoakgL0Tq4mAv+UMnFc3PZptPCXz8ObCsyVmBtiB2P defaultkey_key" > /root/.ssh/authorized_keys + +# Ensure .ssh directory exists and proper permissions are set +mkdir -p /root/.ssh +chmod 700 /root/.ssh +chmod 600 /root/.ssh/authorized_keys + +# Run bootstrap based on input parameters or default action case $1 in - bootstrap ) - /usr/local/sbin/bootstrap $2 $3 $4 - ;; - defaults-bootstrap ) + bootstrap) + /usr/local/sbin/bootstrap "$2" "$3" "$4" + ;; + defaults-bootstrap|*) /usr/local/sbin/bootstrap none nogluster nosalt - ;; - * ) - /usr/local/sbin/bootstrap none nogluster nosalt - ;; -esac -#!/usr/bin/env bash -set -e - -## Basic deps -DEBIAN_FRONTEND=noninteractive apt-get install -y curl wget - -## source <(curl -s https://git.nixc.us/colin/bootstrap-scripts/raw/branch/main/strap.sh) defaults-bootstrap -# curl -sL https://sentry.io/get-cli/ | bash -# echo 'export SENTRY_DSN=https://4d089076433c4a7aa31bbb2741f053fe@sentry.aenow.com/3' -# eval "$(sentry-cli bash-hook)" -curl -o /usr/local/sbin/zsh-setup https://git.nixc.us/colin/bootstrap-scripts/raw/branch/main/scripts/zsh-setup.sh && chmod +x /usr/local/sbin/zsh-setup -curl -o /usr/local/sbin/bootstrap https://git.nixc.us/colin/bootstrap-scripts/raw/branch/main/scripts/bootstrap.sh && chmod +x /usr/local/sbin/bootstrap -echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLT6xx+pXQl6UfiVe0VTZkC45E/2YE/zfNrWb7mLMtI computer@dewitt.improvingmipractices.com" > /root/.ssh/authorized_keys - -## Run bootstrap -case $1 in - bootstrap ) - /usr/local/sbin/bootstrap $2 $3 $4 - ;; - defaults-bootstrap ) - /usr/local/sbin/bootstrap none nogluster nosalt - ;; - * ) - /usr/local/sbin/bootstrap none nogluster nosalt - ;; + ;; esac