loop while not connected to network, choice for upgrading configs, improved reload handling

This commit is contained in:
natemaia 2017-10-29 07:20:48 -07:00
parent d2244066d5
commit 5d05846b04

View File

@ -16,41 +16,52 @@ KEYS=('AEFB411B072836CD48FF0381AE252C284B5DBA5D'
'35F52A02854DCCAEC9DD5CC410443C7F54B00041') '35F52A02854DCCAEC9DD5CC410443C7F54B00041')
DIR="$HOME/.config" DIR="$HOME/.config"
SCRIPT_PATH=$(pwd) SCRIPT_PATH=$(pwd)
yes="y"
no="n"
cur_wm=$(wmctrl -m | grep Name | cut -d " " -f2)
# Loop until network connection is solid
while ! [[ $net >/dev/null ]]; do
net=$(ping -c1 8.8.8.8 2>&1)
echo -e "Please Connect to a Network Before Continuing"
clear; sleep 1
done
setupKeyring() { setupKeyring() {
# import each key and populate the keyring clear; echo "############################################################################################
unset POPULATED
while ! [ $POPULATED ]; do
clear; echo "############################################################################################
######## Setting up keyring & Adding repo to pacman.conf ######### ######## Setting up keyring & Adding repo to pacman.conf #########
############################################################################################" ############################################################################################"
sudo pacman-key --init sleep 2
sudo pacman-key --populate archlinux
for key in ${KEYS[@]}; do # import each key and populate the keyring
if ! sudo pacman-key --list-keys | grep $key; then sudo pacman-key --init
gpg --receive-keys $key sudo pacman-key --populate archlinux
sudo pacman-key -r $key for key in "${KEYS[@]}"; do
fi if ! sudo pacman-key --list-keys | grep $key; then
done gpg --receive-keys $key
sudo pacman-key -r $key
fi
done
# add $REPO to pacman.conf
if ! grep "archlabs_repo" /etc/pacman.conf; then
echo "${REPO}" | sudo tee -a /etc/pacman.conf
else ## if entries exist just remove them
sudo sed -i '/archlabs_repo/d' /etc/pacman.conf
echo "${REPO}" | sudo tee -a /etc/pacman.conf
fi
# finish # add $REPO to pacman.conf
sudo pacman-key --populate archlabs if ! grep "archlabs_repo" /etc/pacman.conf; then
POPULATED="Done" echo "$REPO" | sudo tee -a /etc/pacman.conf
done else
sudo sed -i '/archlabs_repo/d' /etc/pacman.conf
echo "$REPO" | sudo tee -a /etc/pacman.conf
fi
# finish populating the keyrings
sudo pacman-key --populate archlabs
} }
@ -58,22 +69,18 @@ setupKeyring() {
backupConfigs() { backupConfigs() {
# Backup configs to $HOME/Downloads/ clear
unset BACKEDUP echo "############################################################################################
while ! [ $BACKEDUP ]; do
clear; echo "############################################################################################
######## Backing up configs to /home/$USER/Downloads/$USER-config-backup.tar.gz ######### ######## Backing up configs to /home/$USER/Downloads/$USER-config-backup.tar.gz #########
############################################################################################" ############################################################################################"
# Do the archive # Backup configs to $HOME/Downloads/ if backup doesn't exist already
if ! [ -e "$HOME/Downloads/$USER-config-backup.tar.gz" ]; then if ! [ -e "$HOME/Downloads/$USER-config-backup.tar.gz" ]; then
tar czvf $HOME/Downloads/$USER-config-backup.tar.gz $HOME/.{config,Xresources,zshrc,bashrc,icons,xsession,xsessionrc,xinitrc} > /dev/null 2>&1 tar czvf "$HOME/Downloads/$USER-config-backup.tar.gz" "$HOME"/.{config,Xresources,zshrc,bashrc,icons,xsession,xsessionrc,xinitrc} > /dev/null 2>&1
fi else
# set BACKEDUP for setupConfigs check echo "[WARNING] Backup already exists... Not overwriting"
BACKEDUP="Done" sleep 2
fi
done
} }
@ -82,34 +89,67 @@ backupConfigs() {
setupConfigs() { setupConfigs() {
# get rid of old leftover configs/scripts clear
rm -rf $HOME/.config/{bspwm,dunst,i3,obmenu-generator,qt5ct,Thunar,conky,geany,neofetch,polybar,termite,xfce4,openbox} echo "############################################################################################
sudo rm -rf /etc/skel/*
clear; echo "############################################################################################
######## Setting up new configs ######### ######## Setting up new configs #########
############################################################################################" ############################################################################################"
# Copy configs to /etc/skel/ & $HOME sleep 2
cp -rf "$PWD/home/"{bin,.config,.themes,.gorice,.Xresources,.Xresources.template,.mozilla,.zshrc,.bashrc,.icons,.local,.xsession,.xsessionrc,.xinitrc} "$HOME/"
sudo cp -rf "$PWD/home/"{bin,.config,.themes,.gorice,.Xresources,.Xresources.template,.mozilla,.zshrc,.bashrc,.icons,.local,.xsession,.xsessionrc,.xinitrc} /etc/skel/ # get rid of old leftover configs/scripts
sudo cp -rf "$PWD/etc" / rm -rf "$HOME"/.config/{bspwm,dunst,i3,obmenu-generator,qt5ct,Thunar,conky,geany,neofetch,polybar,termite,xfce4,openbox}
sudo rm -rf /etc/skel/*
# Copy configs to /etc/skel/ & $HOME
sudo cp -rf "$PWD"/home/{bin,.config,.themes,.gorice,.Xresources,.Xresources.template,.mozilla,.zshrc,.bashrc,.icons,.local,.xsession,.xsessionrc,.xinitrc} /etc/skel/
sudo cp -rf "$PWD"/etc /
cp -rf /etc/skel/{bin,.config,.themes,.gorice,.Xresources,.Xresources.template,.mozilla,.zshrc,.bashrc,.icons,.local,.xsession,.xsessionrc,.xinitrc} "$HOME"/
} }
# first setupKeyring # first setupKeyring
setupKeyring setupKeyring
# call backupConfigs before we continue # ask to setup configs
backupConfigs clear
printf "\nThis step will get the latest configs for polybar, tint2, openbox, i3, etc.
\n\nYour existing configs will be backed up to an archive located at:
\n\t$HOME/Downloads/$USER-config-backup.tar.gz\n\n\n\nDo you want to continue? [y/N]:"
read -r answer
# then setupConfigs if [ "${answer,,}" = "${yes,,}" ]; then
setupConfigs
# finish up by setting and reloading everything # backup configs before continuing
$HOME/.config/setup backupConfigs
$HOME/.config/polybar/scripts/launch-polybar --reload > /dev/null 2>&1
clear; echo "############################################################################################ # setupConfigs only if a backup was made
if [ -e "$HOME/Downloads/$USER-config-backup.tar.gz" ]; then
setupConfigs
fi
# finish up by running setup then reloading everything
$HOME/.config/setup
if [[ $cur_wm == i3 ]]; then
i3-msg restart
else
$HOME/.config/polybar/scripts/launch-polybar --reload > /dev/null 2>&1
fi
else
sudo rm -rf /etc/skel/*
sudo cp -rf "$PWD"/home/{bin,.config,.themes,.gorice,.Xresources,.Xresources.template,.mozilla,.zshrc,.bashrc,.icons,.local,.xsession,.xsessionrc,.xinitrc} /etc/skel/
sudo cp -rf "$PWD"/etc /
fi
clear
echo "############################################################################################
######## Setup Successfully Completed ######### ######## Setup Successfully Completed #########
############################################################################################" ############################################################################################"