template_setup/template_setup.sh
deathbybandaid 4513080352 test
2022-03-08 08:15:13 -05:00

103 lines
3.5 KiB
Bash

#!/bin/bash
echo "Setting up template environment"
## Script Location
SCRIPTDIR=$(dirname $0)
echo "Checking Dependencies"
## Start File Loop
## For .dependency files In The dependencies Directory
DEPENDENCIESALL="$SCRIPTDIR/dependencies/*.dep"
for f in $DEPENDENCIESALL
do
## Name Of Package
DEPENDENCYNAME=$(echo "`basename $f | cut -f 1 -d '.'`")
## Actual Package
DEPENDENCYPACKAGE=`cat $f`
echo "Checking For $DEPENDENCYNAME with package name $DEPENDENCYPACKAGE"
if which $DEPENDENCYNAME >/dev/null;
then
echo "$DEPENDENCYNAME Is Already Installed."
else
echo "Installing $DEPENDENCYNAME"
apt-get install -y $DEPENDENCYPACKAGE
fi
if which $DEPENDENCYNAME >/dev/null;
then
:
else
echo "Error Installing $DEPENDENCYNAME"
fi
## End Of loop
done
topgrade_install_directory="/opt/topgrade"
if [ ! -d "$topgrade_install_directory" ]; then
echo "creating topgrade installation directory"
mkdir $topgrade_install_directory
fi
topgrade_binary="/opt/topgrade/topgrade"
topgrade_git_user="r-darwish"
topgrade_git_repo="topgrade"
if [ ! -f "$topgrade_binary" ]; then
echo "topgrade binary missing, installing now"
curl -s -L "https://github.com/$topgrade_git_user/$topgrade_git_repo/releases/latest" | egrep -o '/$topgrade_git_user/$topgrade_git_repo/releases/download/[0-9]*/[0-9]*-x86_64-unknown-linux-gnu.tar.gz' | wget --base=http://github.com/ -i - -O "$topgrade_binary.tar.gz"
fi
neofetch_motd="/etc/update-motd.d/01-neofetch"
if [ ! -f "$neofetch_motd" ]; then
echo "Installing Neofetch MOTD"
echo "#!/bin/bash" | tee --append $neofetch_motd &>/dev/null
echo "/usr/bin/neofetch" | tee --append $neofetch_motd &>/dev/null
fi
custom_bash_aliases_path="/etc/bash_aliases"
custom_bash_aliases_git="https://git.deathbybandaid.net/deathbybandaid/bash_aliases"
if [ ! -d "$custom_bash_aliases_path" ]; then
echo "Installing Bash Aliases"
git clone --quiet $custom_bash_aliases_git $custom_bash_aliases_path
fi
source $HOME/.bashrc
custom_topgrade_confs_path="/etc/topgrade"
custom_topgrade_confs_git="https://git.deathbybandaid.net/deathbybandaid/topgrade"
if [ ! -d "$custom_topgrade_confs_path" ]; then
echo "Installing topgrade configs"
git clone --quiet $custom_topgrade_confs_git $custom_topgrade_confs_path
fi
## Update
echo "Running topgrade"
/opt/topgrade/topgrade
## FreeIPA Realm Join
if (whiptail --title "FreeIPA Relam Join" --yes-button "yes" --no-button "no" --yesno "Do You want to join a FreeIPA Realm?" 10 80)
then
echo "Checking if system already contains Membership to FreeIPA Realm"
realm_join=0
if [[ ! -f /var/lib/ipa-client/sysrestore/sysrestore.state ]]
then
echo "$HOSTNAME appears to not be joined to FreeIPA Server Realm"
realm_join=1
else
echo "$HOSTNAME appears to already be joined to FreeIPA Server Realm"
fi
if [[ $HOSTNAME == *template* ]]; then
echo "Hostname $HOSTNAME contains the word 'template', skipping realm joining"
realm_join=0
fi
if [ "$realm_join" == 1 ]; then
echo "Setting up ipa-client to join FreeIPA Server Realm"
freeipa_admin=$(whiptail --passwordbox "Please enter the user authorized to join FreeIPA realm: $freeipa_admin" 8 78 --title "FreeIPA Admin User Prompt" 3>&1 1>&2 2>&3)
freeipa_password=$(whiptail --passwordbox "Please enter the password for the FreeIPA admin user: $freeipa_admin" 8 78 --title "FreeIPA Password Prompt" 3>&1 1>&2 2>&3)
ipa-client-install --mkhomedir --no-ntp --principal="$freeipa_admin" --password="$freeipa_password" --enable-dns-updates --unattended
fi
else
echo "Skipping realm joining"
fi