rmm-scripts/izebra-linux-oneshot.sh

98 lines
3.5 KiB
Bash
Raw Normal View History

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
#Add fish shell repo and install
echo Installing fish...
sudo apt-add-repository ppa:fish-shell/release-3
2024-07-24 19:09:09 +00:00
sudo apt update
sudo apt install fish
#Copy fish config file to root and all users under /home/
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
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
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
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)
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/
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
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
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
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
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
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