#!/bin/bash
scriptdir = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
logfile = "/dev/null"
# Get params
while getopts "r:p:d:vh" opt;
do case $opt in
h) echo -e " -r: https://link-to-repo\n-p: /link/to/prog/file\n-d: devicename for special dotfiles\n-v: verbose, please supply logfile path (default is $HOME /install.log) " && exit ; ;
d) device = ${ OPTARG } ; ;
r) repo = ${ OPTARG } && git ls-remote " $repo " || exit ; ;
p) prog = ${ OPTARG } ; ;
a) aurhelper = ${ OPTARG } ; ;
v) logfile = " $scriptdir /install.log " ; ;
\? ) echo " - $OPTARG is not valid " >& 2 && exit ; ;
esac
done
device = ${ device : = "480" }
repo = ${ repo : = "https://toerd@bitbucket.org/toerd/dotfiles" }
prog = ${ prog : = " $scriptdir /pack.list " }
aurhelper = ${ aurhelper : = "yay" }
startup_msg( ) {
curr_platform = $( dialog --clear --title "Welcome to the installer <3" --menu "Choose your current platform:" 0 0 2 "L" "Laptop" "D" "Desktop" 2>& 1>/dev/tty)
echo " Installation started - Platform is: $curr_platform \n\n " >> $logfile
}
init( ) {
pacman -S --noconfirm --needed dialog git make || { echo "Run as root user" ; exit; }
dialog --infobox "Refresh of the Keyring" 0 0
pacman --noconfirm -Sy archlinux-keyring & >> $logfile
}
pre_install( ) {
dialog --title "Start the installation" --yes-label "Okey Dokey Artischokey" --no-label "NOPE Byeee" --yesno "\nIf you decide to start the installation, grab a beer and watch some youtube vids (On another device ofc)\n\nIf not... then you should just DIY ._." 0 0 || { clear; exit; }
echo "Automatic part started\n\n" >> $logfile
}
get_credentials( ) {
uname = $( dialog --inputbox "Enter an username" 0 0 2>& 1 1>/dev/tty)
echo $uname
while ! [ [ $uname = ~ ^[ _a-z] [ _a-z0-9] { 0,30} $ ] ] ; do
uname = $( dialog --no-cancel --inputbox " $uname Please enter a - valid - username " 0 0 2>& 1 1>/dev/tty)
done
# Grab the password and check if it matches
passw = $( dialog --no-cancel --passwordbox "Enter a password" 0 0 2>& 1 1>/dev/tty)
passr = $( dialog --no-cancel --passwordbox "Confirm password" 0 0 2>& 1 1>/dev/tty)
while [ [ ${ passw } != ${ passr } || ${# passw } -lt 8 ] ] ; do
passw = $( dialog --no-cancel --passwordbox " ${# passw } Passwords did not match or length < 8\nEnter a password " 0 0 2>& 1 1>/dev/tty)
passr = $( dialog --no-cancel --passwordbox "Confirm password" 0 0 2>& 1 1>/dev/tty)
done
echo "Username and password successfully supplied\n\n" >> $logfile
}
create_user( ) {
dialog --infobox " Creating user - $uname " 0 0
useradd -m -g wheel -s /bin/bash " $uname " & >> $logfile || usermod -a -G wheel " $uname " && mkdir -p /home/" $uname " && chown " $uname " :wheel /home/" $uname "
echo " $uname : $passw " | chpasswd
unset passw passr ;
echo "User successfully created\n\n" >> $logfile
}
install_pacman( ) {
psd = $(( psd+1))
dialog --title "Pacman packages" --infobox " Package $psd / $ps \n\nInstalling: $1 \n\n> $2 < " 0 0
pacman --noconfirm --needed -S " $1 " & >> $logfile
}
install_aur( ) {
asd = $(( asd+1))
dialog --title "AUR packages" --infobox " AUR Package $asd / $as \n\nInstalling: $1 \n\n> $2 < " 0 0
# is package already installed?
grep " ^ $1 $" <<< " $aur_already_installed " && return
sudo -u $uname $aurhelper -S --noconfirm " $1 " $>> $logfile
}
install_manual( ) {
msd = $(( msd+1))
dialog --title "Manual packages" --infobox " Manual Package $msd / $ms \n\nInstalling: $1 \n\n> $2 < " 0 0
cd " $scriptdir /packages/ $1 " || exit
make clean && make && sudo -u $uname make install & >> $logfile ;
cd " /home/ $uname " || exit
}
install_aur_helper( ) {
dialog --title "Installing the AUR Helper" --infobox "Installing dependencies..." 0 0
pacman --noconfirm --needed -S go & >> $logfile
dialog --title "Installing the AUR Helper" --infobox "Cloning repository..." 0 0
d = $( sudo -u '$uname' mktemp -d) || exit
git clone https://aur.archlinux.org/yay.git $d & >> $logfile
cd $d
sudo -u " $uname " makepkg --noconfirm -si & >> $logfile
}
installation_loop( ) {
echo "Entered installationloop\n\n" >> $logfile
( [ -f " $prog " ] && cp " $prog " /tmp/pack.list) || curl -Ls " $prog " > /tmp/pack.list
ps = $( grep -e ",P," /tmp/pack.list | wc -l)
as = $( grep -e ",A," /tmp/pack.list | wc -l)
ms = $( grep -e ",M," /tmp/pack.list | wc -l)
aur_already_installed = $( pacman -Qqm)
#IFS separator
while IFS = , read -r platform prefix program info; do
if [ [ ${ platform } != "A" ] ] && [ [ ${ platform } != ${ curr_platform } ] ] ; then
continue
fi
case $prefix in
P) install_pacman " $program " " $info " ; ;
A) install_aur " $program " " $info " ; ;
M) install_manual " $program " " $info " ; ;
esac
done < /tmp/pack.list
}
enable_service( ) {
for service in " $@ " ; do
dialog --infobox " Enabling: $service " 0 0
systemctl enable " $service "
systemctl start " $service "
echo " Services $service started\n\n " >> $logfile
done
}
set_permissions( ) {
sed -i '.*/#toerd/d' /etc/sudoers
echo -e " $@ #toerd " >> /etc/sudoers
echo "Permissions set\n\n" >> $logfile
}
download_dotfiles( ) {
cd /home/$uname
mkdir -p .dotfiles && cd .dotfiles
git clone $repo .
echo "Dotfiles downloaded\n\n" >> $logfile
}
no_beep( ) {
rmmod pcspkr
echo "blacklist pcspkr" > /etc/modprobe.d/nobeep.conf
echo "Beep killed\n\n" >> $logfile
}
ready_steady_go( ) {
dialog --title "WE ARE DONE" --infobox "The installation is complete\n\n#fingerscrossed everything worked :D" 0 0 ;
}
init
startup_msg
get_credentials
pre_install
create_user
set_permissions "%wheel ALL=(ALL) NOPASSWD: ALL"
install_aur_helper
installation_loop
download_dotfiles
set_permissions "%wheel ALL=(ALL) ALL\\n%wheel ALL=(ALL) NOPASSWD: /usr/bin/shutdown,/usr/bin/reboot,/usr/bin/systemctl suspend,/usr/bin/wifi-menu,/usr/bin/mount,/usr/bin/umount,/usr/bin/pacman -Syu,/usr/bin/pacman -Syyu,/usr/bin/packer -Syu,/usr/bin/packer -Syyu,/usr/bin/systemctl restart NetworkManager,/usr/bin/rc-service NetworkManager restart,/usr/bin/pacman -Syyu --noconfirm,/usr/bin/loadkeys,/usr/bin/yay"
no_beep
sed -i "s/#Color^/Color/g" /etc/pacman.conf
ready_steady_go
clear