2024-07-24 19:09:09 +00:00
|
|
|
#!/bin/bash
|
2024-07-25 00:05:44 +00:00
|
|
|
#Zebra
|
2024-07-24 19:09:09 +00:00
|
|
|
#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
|
2024-07-24 19:13:47 +00:00
|
|
|
if [ "$EUID" -ne 0 ]
|
2024-07-24 19:09:09 +00:00
|
|
|
then echo "Please run as Root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#define variables
|
2024-07-24 19:15:44 +00:00
|
|
|
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"
|
2024-07-24 19:09:09 +00:00
|
|
|
|
2024-07-25 00:03:42 +00:00
|
|
|
#Add fish shell repo and install
|
|
|
|
echo Installing fish...
|
2024-07-25 04:55:15 +00:00
|
|
|
sudo apt-add-repository --yes ppa:fish-shell/release-3
|
2024-07-24 19:09:09 +00:00
|
|
|
sudo apt update
|
2024-07-25 04:55:15 +00:00
|
|
|
sudo apt install fish -y
|
2024-07-25 00:03:42 +00:00
|
|
|
|
2024-07-26 02:07:25 +00:00
|
|
|
#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/
|
2024-07-25 00:03:42 +00:00
|
|
|
|
2024-07-26 02:11:01 +00:00
|
|
|
sudo fc-cache
|
2024-07-25 00:03:42 +00:00
|
|
|
#Copy fish config file to root and all users under /home/
|
2024-07-24 22:44:11 +00:00
|
|
|
|
|
|
|
echo Downloading Fish Config File. Storing in $HOME/.config/fish/config.fish
|
2024-07-24 19:41:29 +00:00
|
|
|
wget -O "$HOME/.config/fish/config.fish" $fishconfig
|
|
|
|
# Iterate over each user's home directory, including /root
|
2024-07-24 20:34:47 +00:00
|
|
|
for homedir in /root /home/*; do
|
2024-07-24 19:41:29 +00:00
|
|
|
if [ -d "$homedir" ]; then
|
|
|
|
# Ensure .config directory exists
|
2024-07-24 22:44:11 +00:00
|
|
|
echo Creating dir structure for $homedir
|
2024-07-24 19:41:29 +00:00
|
|
|
mkdir -p "$homedir/.config"
|
|
|
|
mkdir -p "$homedir/.config/fish"
|
|
|
|
|
|
|
|
# Copy starship.toml to the user's .config directory
|
2024-07-24 22:44:11 +00:00
|
|
|
echo copying fish config to $homedir/.config/fish/config.fish
|
2024-07-24 22:31:18 +00:00
|
|
|
cp -f "$HOME/.config/fish/config.fish" "$homedir/.config/fish/config.fish"
|
2024-07-24 19:41:29 +00:00
|
|
|
|
|
|
|
# Set ownership to the user of the home directory
|
2024-07-24 22:44:11 +00:00
|
|
|
echo Taking ownership of file under UID $homedir
|
2024-07-24 22:48:24 +00:00
|
|
|
chown -R $(basename "$homedir"):"$(id -gn $(basename "$homedir"))" "$homedir/.config/"
|
2024-07-24 19:41:29 +00:00
|
|
|
|
|
|
|
# Optional: Set permissions to 0644 (readable by owner and group, readable by others)
|
2024-07-24 22:44:11 +00:00
|
|
|
echo setting file perms
|
2024-07-24 19:41:29 +00:00
|
|
|
chmod 0644 "$homedir/.config/fish/config.fish"
|
|
|
|
fi
|
2024-07-24 19:09:09 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
#install pyenv
|
|
|
|
curl https://pyenv.run | bash
|
|
|
|
|
|
|
|
#Download starship and copy config file to root and all users under /home/
|
2024-07-24 22:44:11 +00:00
|
|
|
echo Downloading starship installer to $HOME/starship.sh
|
2024-07-24 21:47:59 +00:00
|
|
|
wget -O $HOME/starship.sh https://starship.rs/install.sh
|
|
|
|
chmod +x $HOME/starship.sh
|
2024-07-24 22:30:03 +00:00
|
|
|
sh $HOME/starship.sh --force
|
|
|
|
rm $HOME/starship.sh
|
2024-07-24 21:24:53 +00:00
|
|
|
|
2024-07-24 19:41:29 +00:00
|
|
|
wget -O "$HOME/.config/starship.toml" $starshipconfig
|
|
|
|
# Iterate over each user's home directory, including /root
|
2024-07-24 20:34:47 +00:00
|
|
|
for homedir in /root /home/*; do
|
2024-07-24 19:41:29 +00:00
|
|
|
if [ -d "$homedir" ]; then
|
|
|
|
# Ensure .config directory exists
|
2024-07-24 22:44:11 +00:00
|
|
|
echo Creating directories for $homedir
|
2024-07-24 19:41:29 +00:00
|
|
|
mkdir -p "$homedir/.config"
|
2024-07-24 19:20:50 +00:00
|
|
|
|
2024-07-24 19:41:29 +00:00
|
|
|
# Copy starship.toml to the user's .config directory
|
2024-07-24 22:44:11 +00:00
|
|
|
echo Copying config file to $homedir/.config/starship.toml
|
2024-07-24 22:31:18 +00:00
|
|
|
cp -f "$HOME/.config/starship.toml" "$homedir/.config/starship.toml"
|
2024-07-24 19:41:29 +00:00
|
|
|
|
|
|
|
# Set ownership to the user of the home directory
|
2024-07-24 22:44:11 +00:00
|
|
|
echo Setting ownership for $homedir
|
2024-07-24 22:48:24 +00:00
|
|
|
chown -R $(basename "$homedir"):"$(id -gn $(basename "$homedir"))" "$homedir/.config"
|
2024-07-24 19:41:29 +00:00
|
|
|
|
|
|
|
# Optional: Set permissions to 0644 (readable by owner and group, readable by others)
|
|
|
|
chmod 0644 "$homedir/.config/starship.toml"
|
|
|
|
fi
|
2024-07-24 19:09:09 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
#Change default shell to fish
|
2024-07-24 22:44:11 +00:00
|
|
|
echo Changing default shell to fish
|
2024-07-24 22:57:57 +00:00
|
|
|
# Minimum UID for regular user accounts (adjust as necessary)
|
|
|
|
MIN_UID=1000
|
|
|
|
|
2024-07-24 22:52:48 +00:00
|
|
|
# Loop through all users in /etc/passwd
|
2024-07-24 22:57:57 +00:00
|
|
|
while IFS=: read -r username _ uid _ _ homedir _; do
|
2024-07-24 22:52:48 +00:00
|
|
|
# Skip system accounts and users without a home directory
|
2024-07-24 22:57:57 +00:00
|
|
|
if [[ $uid -ge $MIN_UID && -d $homedir ]]; then
|
2024-07-24 22:52:48 +00:00
|
|
|
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
|
2024-07-24 22:57:57 +00:00
|
|
|
else
|
|
|
|
echo "Skipping system account or user without home directory: $username"
|
2024-07-24 22:52:48 +00:00
|
|
|
fi
|
|
|
|
done < /etc/passwd
|
2024-07-24 22:57:57 +00:00
|
|
|
chsh -s /usr/bin/fish
|