You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
5.9 KiB
166 lines
5.9 KiB
6 years ago
|
#!/bin/bash
|
||
|
# userinput and resume after reboot
|
||
|
# mkfs.fat -F 32 -n EFIBOOT /dev/
|
||
|
|
||
|
# Get params
|
||
|
while getopts "r:p:d:v:h" 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=${OPTARG} ;;
|
||
|
\?) echo "-$OPTARG is not valid" >&2 && exit ;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
device=${device:="480"}
|
||
|
repo=${repo:="https://toerd@bitbucket.org/toerd/dotfiles"}
|
||
|
prog=${prog:="$HOME/install/pack.list"}
|
||
|
aurhelper=${aurhelper:="yay"}
|
||
|
logfile=${logfile:="$HOME/install/install.log"}
|
||
|
|
||
|
if [ -z ${v+x} ]; then logfile="/dev/null"
|
||
|
fi
|
||
|
|
||
|
startup_msg() {
|
||
|
dialog --infobox "Welcome to the installer." 0 0 || { clear; exit; }
|
||
|
echo "Installation started\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() {
|
||
|
dialog --title "Pacman packages" --infobox "Package $n/$ps\n\nInstalling: $1\n\n> $2 <" 0 0
|
||
|
pacman --noconfirm --needed -S "$1" &>$logfile
|
||
|
}
|
||
|
|
||
|
install_aur() {
|
||
|
dialog --title "AUR packages" --infobox "AUR Package $n/$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_from_source() {
|
||
|
dialog --title "Manual packages" --infobox "Manual Package $n/$ms\n\nInstalling: $1\n\n> $2 <" 0 0
|
||
|
cd "$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
|
||
|
dir=$(mktemp -d)
|
||
|
git clone https://aur.archlinux.org/yay.git "$dir" &>$logfile
|
||
|
cd "$dir" || exit
|
||
|
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
|
||
|
n=$((n+1))
|
||
|
|
||
|
if [[ ${platform} != "A" ]] && [[ ${platform} != ${curr_plattform} ]]; then
|
||
|
continue
|
||
|
fi
|
||
|
|
||
|
case $prefix in
|
||
|
P) install_pacman "$program" "$info" ;;
|
||
|
A) install_aur "$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
|