rmm-scripts/izebra-linux-oneshot.sh

109 lines
4.2 KiB
Bash

#!/bin/bash
#Zebra
#Linux Onboarding Oneshot script for izebra networks.
#Installs fish, starship, and sets up some shell tweaks that are nice to have.
#Check script is running as root
if [ "$EUID" -ne 0 ]
then echo "Please run as Root"
exit 1
fi
#define variables
fishconfig="https://git.izebra.net/izebra_projects/rmm-scripts/raw/branch/main/config-files/config.fish"
starshipconfig="https://git.izebra.net/izebra_projects/rmm-scripts/raw/branch/main/config-files/starship.toml"
#Add fish shell repo and install
echo Installing fish...
sudo apt-add-repository --yes ppa:fish-shell/release-3
sudo apt update
sudo apt install fish -y
#install other tools required
sudo apt install unzip
#install Meslo Nerd Font
echo Downloading and installing meslo font...
mkdir /tmp/meslo
wget -O /tmp/meslo/meslo.zip https://objects.githubusercontent.com/github-production-release-asset-2e65be/27574418/5c372df6-5404-410a-bd48-5172d2d5048d?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20240726%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240726T020324Z&X-Amz-Expires=300&X-Amz-Signature=89a39bc8f1b1320e5e0aaf43c76987fd7b93bab7f1bfcdbaeef2885c5060fa38&X-Amz-SignedHeaders=host&actor_id=22875272&key_id=0&repo_id=27574418&response-content-disposition=attachment%3B%20filename%3DMeslo.zip&response-content-type=application%2Foctet-stream
unzip /tmp/meslo/meslo.zip
sudo cp Meslo* /usr/share/fonts/
#Copy fish config file to root and all users under /home/
echo Downloading Fish Config File. Storing in $HOME/.config/fish/config.fish
wget -O "$HOME/.config/fish/config.fish" $fishconfig
# Iterate over each user's home directory, including /root
for homedir in /root /home/*; do
if [ -d "$homedir" ]; then
# Ensure .config directory exists
echo Creating dir structure for $homedir
mkdir -p "$homedir/.config"
mkdir -p "$homedir/.config/fish"
# Copy starship.toml to the user's .config directory
echo copying fish config to $homedir/.config/fish/config.fish
cp -f "$HOME/.config/fish/config.fish" "$homedir/.config/fish/config.fish"
# Set ownership to the user of the home directory
echo Taking ownership of file under UID $homedir
chown -R $(basename "$homedir"):"$(id -gn $(basename "$homedir"))" "$homedir/.config/"
# Optional: Set permissions to 0644 (readable by owner and group, readable by others)
echo setting file perms
chmod 0644 "$homedir/.config/fish/config.fish"
fi
done
#install pyenv
curl https://pyenv.run | bash
#Download starship and copy config file to root and all users under /home/
echo Downloading starship installer to $HOME/starship.sh
wget -O $HOME/starship.sh https://starship.rs/install.sh
chmod +x $HOME/starship.sh
sh $HOME/starship.sh --force
rm $HOME/starship.sh
wget -O "$HOME/.config/starship.toml" $starshipconfig
# Iterate over each user's home directory, including /root
for homedir in /root /home/*; do
if [ -d "$homedir" ]; then
# Ensure .config directory exists
echo Creating directories for $homedir
mkdir -p "$homedir/.config"
# Copy starship.toml to the user's .config directory
echo Copying config file to $homedir/.config/starship.toml
cp -f "$HOME/.config/starship.toml" "$homedir/.config/starship.toml"
# Set ownership to the user of the home directory
echo Setting ownership for $homedir
chown -R $(basename "$homedir"):"$(id -gn $(basename "$homedir"))" "$homedir/.config"
# Optional: Set permissions to 0644 (readable by owner and group, readable by others)
chmod 0644 "$homedir/.config/starship.toml"
fi
done
#Change default shell to fish
echo Changing default shell to fish
# Minimum UID for regular user accounts (adjust as necessary)
MIN_UID=1000
# Loop through all users in /etc/passwd
while IFS=: read -r username _ uid _ _ homedir _; do
# Skip system accounts and users without a home directory
if [[ $uid -ge $MIN_UID && -d $homedir ]]; then
echo "Changing shell for user: $username"
sudo chsh -s /usr/bin/fish "$username"
if [ $? -ne 0 ]; then
echo "Failed to change shell for user: $username"
fi
else
echo "Skipping system account or user without home directory: $username"
fi
done < /etc/passwd
chsh -s /usr/bin/fish