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.
345 lines
12 KiB
345 lines
12 KiB
#!/bin/bash
|
|
# Author: Philip Gaber <phga@posteo.de>
|
|
|
|
me=$(basename "$0")
|
|
scriptdir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
|
|
help_msg="\nUsage: $me [OPTIONS]\n\n
|
|
Examples:\n\n $ $me -l -u\n\n
|
|
Options:\n
|
|
-d GIT_DOTFILES_REPO_URL (e.g. https://user@gitmebabyonemoretime.com/user/dotfiles)\n
|
|
-p PACKAGE_CSV_FILE (e.g. ./pack.csv)\n
|
|
-a AURHELPER (e.g. yay)\n
|
|
-l LOGFILE (default: $HOME/install.log)\n
|
|
-u Update the current system\n
|
|
-s Enable necessary services on the current system\n
|
|
|
|
"
|
|
# Get params
|
|
while getopts "r:p:d:vush" opt;
|
|
do case $opt in
|
|
h) echo -e $help_msg && exit ;;
|
|
d) dotfiles=${OPTARG} && git ls-remote "$repo" || exit ;;
|
|
p) pack_csv=${OPTARG} ;;
|
|
a) aurhelper=${OPTARG} ;;
|
|
l) logfile="$scriptdir/install.log" ;;
|
|
u) todo="update" ;;
|
|
s) todo="services" ;;
|
|
\?) echo "-$OPTARG is not valid" >&2 && exit ;;
|
|
esac
|
|
done
|
|
|
|
# Default settings
|
|
dotfiles=${dotfiles:="https://phga@g.phga.de/phga/dotfiles"}
|
|
pack_csv=${pack_csv:="$scriptdir/pack.csv"}
|
|
aurhelper=${aurhelper:="yay"}
|
|
logfile=${logfile:="/dev/null"}
|
|
todo=${todo:="install"}
|
|
|
|
|
|
startup_msg() {
|
|
curr_platform=$(dialog --clear --title "Welcome to the Freshcript <3" --menu "Choose your current platform:" 0 0 3 "L" "Laptop" "D" "Desktop" "S" "Server" 2>&1>/dev/tty)
|
|
[ -z "$curr_platform" ] && { clear; exit; }
|
|
echo "Script started - Platform is: $curr_platform\n\n" >> $logfile
|
|
}
|
|
|
|
wait_for_network() {
|
|
dialog --infobox "Waiting for internet connection...\n\nDumdidum dum dumdiii dum" 0 0
|
|
|
|
ping -c 1 -q "one.one.one.one" >> $logfile && return || dhcpcd >> $logfile
|
|
|
|
while [ ! $OK = 0 ]; do
|
|
ping -c 1 -q "one.one.one.one" >> $logfile && OK=$?
|
|
done
|
|
}
|
|
|
|
init() {
|
|
wait_for_network
|
|
pacman -S --noconfirm --needed dialog git make > /dev/null 2>&1 ||
|
|
{ echo "Run as root user"; clear; exit; }
|
|
refresh_keyring
|
|
}
|
|
|
|
refresh_keyring() {
|
|
pacman --noconfirm -Sy archlinux-keyring &>> $logfile
|
|
dialog --infobox "Refresh of the Keyring" 0 0
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
pre_update() {
|
|
uname=$(logname)
|
|
dialog --title "Start the Update" --yes-label "Okey Dokey Artischokey" --no-label "NOPE Byeee" --yesno "\nUpdateriniho as user > $uname <" 0 0 || { clear; exit; }
|
|
echo "Automatic update started as user:$uname\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))
|
|
echo "Entered installationloop\n\n" >> $logfile
|
|
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 && make install && make clean &>> $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
|
|
cd $(sudo -u $uname mktemp -d)
|
|
git clone "https://aur.archlinux.org/$aurhelper.git" . &>> $logfile
|
|
sudo -u $uname makepkg --noconfirm -s &>> $logfile
|
|
pacman -U --noconfirm *.zst
|
|
# Check if aurhelper installation was successful
|
|
if ! hash $aurhelper > /dev/null 2>&1; then
|
|
dialog --title "Installing the AUR Helper" --infobox \
|
|
"Installation of $aurhelper failed" 0 0
|
|
sleep 10
|
|
clear
|
|
exit
|
|
fi
|
|
}
|
|
|
|
installation_loop() {
|
|
echo "Entered installationloop\n\n" >> $logfile
|
|
csv="/tmp/pack.csv"
|
|
([ -f "$pack_csv" ] && cp "$pack_csv" "$csv") || curl -Ls "$pack_csv" > "$csv"
|
|
# count packages and sum results for all and curr platform
|
|
ps=$(($(grep -e "A,P," "$csv" | wc -l) + $(grep -e "$curr_platform,P," "$csv" | wc -l)))
|
|
as=$(($(grep -e "A,A," "$csv" | wc -l) + $(grep -e "$curr_platform,A," "$csv" | wc -l)))
|
|
ms=$(($(grep -e "A,M," "$csv" | wc -l) + $(grep -e "$curr_platform,M," "$csv" | wc -l)))
|
|
aur_already_installed=$(pacman -Qqm)
|
|
# For all lines in pack.csv do
|
|
while IFS=, read -r platform prefix program info; do
|
|
|
|
[[ ${platform} != "A" ]] && [[ ${platform} != ${curr_platform} ]] && continue
|
|
|
|
case $prefix in
|
|
P) install_pacman "$program" "$info" ;;
|
|
A) install_aur "$program" "$info" ;;
|
|
M) install_manual "$program" "$info" ;;
|
|
esac
|
|
done < "$csv"
|
|
}
|
|
|
|
enable_service() {
|
|
for service in "$@"; do
|
|
dialog --infobox "Enabling: $service" 0 0
|
|
if [[ $@ =~ "--user.*" ]]; then
|
|
sudo -u $uname systemctl enable "$service"
|
|
sudo -u $uname systemctl start "$service"
|
|
else
|
|
systemctl enable "$service"
|
|
systemctl start "$service"
|
|
fi
|
|
echo "Services $service started\n\n" >> $logfile
|
|
done
|
|
}
|
|
|
|
set_permissions() {
|
|
sed -i '/.*#phga/d' /etc/sudoers
|
|
echo -e "$@ #phga" >> /etc/sudoers
|
|
echo "Permissions set\n\n" >> $logfile
|
|
}
|
|
|
|
download_dotfiles() {
|
|
cd /home/$uname
|
|
sudo -u $uname mkdir -p .dotfiles && cd .dotfiles
|
|
sudo -u $uname git clone $dotfiles .
|
|
sudo -u $uname ./scripts/link.sh
|
|
echo "Dotfiles downloaded and installed\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" --msgbox "The installation is complete\n\n#fingerscrossed
|
|
everything worked :D\n\nTODOs\n\n- Move syncthing keys into .config\n" 0 0 ;
|
|
}
|
|
|
|
add_xorg_conf() {
|
|
echo "Adding xorg conf\n\n" >> $logfile
|
|
cp $scriptdir/etc/X11/xorg.conf.d/* /etc/X11/xorg.conf.d/ &>> $logfile
|
|
}
|
|
|
|
add_udev_rules() {
|
|
echo "Adding udev rules from $scriptdir into udev folder\n\n" >> $logfile
|
|
cp $scriptdir/etc/udev/rules.d/* /etc/udev/rules.d/ &>> $logfile
|
|
}
|
|
|
|
add_pacman_hooks() {
|
|
echo "Adding pacman hooks\n\n" >> $logfile
|
|
mkdir -p /etc/pacman.d/hooks >> $logfile
|
|
cp $scriptdir/etc/pacman.d/hooks/* /etc/pacman.d/hooks/ &>> $logfile
|
|
}
|
|
|
|
add_systemd_conf() {
|
|
echo "Adding systemd configs\n\n" >> $logfile
|
|
cp -r $scriptdir/etc/systemd/* /etc/systemd/ &>> $logfile
|
|
}
|
|
|
|
set_pacman_config() {
|
|
echo "Setting pacman conf\n\n" >> $logfile
|
|
cp $scriptdir/etc/pacman.conf /etc/pacman.conf &>> $logfile
|
|
}
|
|
|
|
set_git_config() {
|
|
sudo -u $uname git config --global user.email "phga@posteo.de"
|
|
sudo -u $uname git config --global user.name "qhga"
|
|
sudo -u $uname git config --global credential.useHttpPath true
|
|
# gpg --list-keys --keyid-format=long
|
|
sudo -u $uname git config --global user.signingkey 5249548AA705F019
|
|
sudo -u $uname git config --global commit.gpgsign true
|
|
|
|
# sudo -u $uname git config --global credential.helper /usr/bin/pass-git-helper
|
|
}
|
|
|
|
set_system_stuff() {
|
|
# locale gen
|
|
echo "Enter system stuff\n\n" >> $logfile
|
|
dialog --title "Setting up the system" --infobox "Final adjustments" 0 0
|
|
localectl --no-convert set-x11-keymap us ,altgr-intl &>> $logfile
|
|
setxkbmap us -variant altgr-intl &>> $logfile
|
|
add_udev_rules
|
|
set_pacman_config
|
|
add_pacman_hooks
|
|
add_xorg_conf
|
|
add_systemd_conf
|
|
set_git_config
|
|
#link syncthing config and move certs
|
|
# sudo -u $uname /home/$uname/.dotfiles/syncthing/link-confs.sh &>> $logfile
|
|
echo "Leave system stuff\n\n" >> $logfile
|
|
}
|
|
|
|
add_user_to_groups() {
|
|
dialog --infobox "Adding $uname to necessary groups" 0 0
|
|
ugroups="audio video realtime docker"
|
|
usermod -a -G "$ugroups" "$uname"
|
|
echo "Added user $uname to groups: $ugroups\n\n" >> $logfile
|
|
}
|
|
|
|
set_root_bashrc() {
|
|
echo ". /root/.bashrc" > /root/.bash_profile
|
|
cat <<EOF > /root/.bashrc
|
|
# Fix for tramp connections
|
|
[ $TERM = "dumb" ] && return
|
|
|
|
set -o vi
|
|
|
|
# append to the history file, don't overwrite it
|
|
shopt -s histappend
|
|
|
|
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
|
|
HISTCONTROL=ignoreboth:erasedups HISTSIZE=100000 HISTFILESIZE=200000
|
|
PROMPT_COMMAND='history -a'
|
|
|
|
# check the window size after each command and, if necessary,
|
|
# update the values of LINES and COLUMNS.
|
|
shopt -s checkwinsize
|
|
|
|
alias ls='ls --color=auto --group-directories-first'
|
|
alias grep='grep --color=auto'
|
|
alias ll='ls -alSFhv'
|
|
[ -f /etc/bash_completion ] && ! shopt -oq posix && . /etc/bash_completion
|
|
|
|
# PS1 config
|
|
export PS1="\[$(tput bold)\]\[\033[38;5;1m\]ROOT\[$(tput sgr0)\]@\w\n->\[$(tput sgr0)\] "
|
|
EOF
|
|
}
|
|
# ACTUAL ROUTINE
|
|
|
|
case $todo in
|
|
install)
|
|
init
|
|
startup_msg
|
|
get_credentials
|
|
pre_install
|
|
create_user
|
|
install_aur_helper
|
|
installation_loop
|
|
download_dotfiles
|
|
set_permissions "Defaults timestamp_timeout=45\n%wheel ALL=(ALL) ALL\n%wheel ALL=(ALL) NOPASSWD: /usr/bin/shutdown,/usr/bin/reboot,/usr/bin/systemctl suspend"
|
|
no_beep
|
|
set_system_stuff
|
|
enable_service "--user syncthing" "--user pipewire-pulse"
|
|
if [[ ${curr_platform} == "L" ]]; then
|
|
enable_service "netctl-auto@wlp3s0" "bluetooth"
|
|
else
|
|
enable_service "systemd-networkd"
|
|
fi
|
|
enable_service "systemd-timesyncd" "atd" "ly"
|
|
set_root_bashrc
|
|
add_user_to_groups
|
|
ready_steady_go
|
|
clear
|
|
;;
|
|
update)
|
|
init
|
|
startup_msg
|
|
refresh_keyring
|
|
pre_update
|
|
installation_loop
|
|
set_system_stuff
|
|
ready_steady_go
|
|
clear
|
|
;;
|
|
services)
|
|
init
|
|
startup_msg
|
|
pre_update
|
|
if [[ ${curr_platform} == "L" ]]; then
|
|
enable_service "netctl-auto@wlp3s0" "bluetooth"
|
|
else
|
|
enable_service "systemd-networkd"
|
|
fi
|
|
enable_service "systemd-timesyncd" "atd" "ly" "--user syncthing" "--user pipewire-pulse"
|
|
ready_steady_go
|
|
clear
|
|
;;
|
|
esac
|