refactor: cleanup of the fresh.sh script
This commit is contained in:
parent
a0952d0c32
commit
0126146f36
98
fresh.sh
98
fresh.sh
@ -1,17 +1,28 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Author: Philip Gaber <phga@posteo.de>
|
# Author: Philip Gaber <phga@posteo.de>
|
||||||
|
|
||||||
|
me=$(basename "$0")
|
||||||
scriptdir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
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
|
# Get params
|
||||||
while getopts "r:p:d:vush" opt;
|
while getopts "r:p:d:vush" opt;
|
||||||
do case $opt in
|
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 ;;
|
h) echo -e $help_msg && exit ;;
|
||||||
d) device=${OPTARG} ;;
|
d) dotfiles=${OPTARG} && git ls-remote "$repo" || exit ;;
|
||||||
r) repo=${OPTARG} && git ls-remote "$repo" || exit ;;
|
p) pack_csv=${OPTARG} ;;
|
||||||
p) prog=${OPTARG} ;;
|
|
||||||
a) aurhelper=${OPTARG} ;;
|
a) aurhelper=${OPTARG} ;;
|
||||||
v) logfile="$scriptdir/install.log" ;;
|
l) logfile="$scriptdir/install.log" ;;
|
||||||
u) todo="update" ;;
|
u) todo="update" ;;
|
||||||
s) todo="services" ;;
|
s) todo="services" ;;
|
||||||
\?) echo "-$OPTARG is not valid" >&2 && exit ;;
|
\?) echo "-$OPTARG is not valid" >&2 && exit ;;
|
||||||
@ -19,9 +30,8 @@ do case $opt in
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Default settings
|
# Default settings
|
||||||
device=${device:="480"}
|
dotfiles=${dotfiles:="https://phga@g.phga.de/phga/dotfiles"}
|
||||||
repo=${repo:="https://phga@g.phga.de/phga/dotfiles"}
|
pack_csv=${pack_csv:="$scriptdir/pack.csv"}
|
||||||
prog=${prog:="$scriptdir/pack.csv"}
|
|
||||||
aurhelper=${aurhelper:="yay"}
|
aurhelper=${aurhelper:="yay"}
|
||||||
logfile=${logfile:="/dev/null"}
|
logfile=${logfile:="/dev/null"}
|
||||||
todo=${todo:="install"}
|
todo=${todo:="install"}
|
||||||
@ -29,12 +39,15 @@ todo=${todo:="install"}
|
|||||||
|
|
||||||
startup_msg() {
|
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)
|
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
|
echo "Script started - Platform is: $curr_platform\n\n" >> $logfile
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_for_network() {
|
wait_for_network() {
|
||||||
dialog --infobox "Waiting for internet connection...\n\nDumdidum dum dumdiii dum" 0 0
|
dialog --infobox "Waiting for internet connection...\n\nDumdidum dum dumdiii dum" 0 0
|
||||||
dhcpcd >> $logfile
|
|
||||||
|
ping -c 1 -q "one.one.one.one" >> $logfile && return || dhcpcd >> $logfile
|
||||||
|
|
||||||
while [ ! $OK = 0 ]; do
|
while [ ! $OK = 0 ]; do
|
||||||
ping -c 1 -q "one.one.one.one" >> $logfile && OK=$?
|
ping -c 1 -q "one.one.one.one" >> $logfile && OK=$?
|
||||||
done
|
done
|
||||||
@ -42,7 +55,8 @@ wait_for_network() {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
wait_for_network
|
wait_for_network
|
||||||
pacman -S --noconfirm --needed dialog git make || { echo "Run as root user"; clear; exit; }
|
pacman -S --noconfirm --needed dialog git make > /dev/null 2>&1 ||
|
||||||
|
{ echo "Run as root user"; clear; exit; }
|
||||||
refresh_keyring
|
refresh_keyring
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,45 +123,50 @@ install_manual() {
|
|||||||
cd "/home/$uname" || exit
|
cd "/home/$uname" || exit
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: test with makepkg -si
|
|
||||||
install_aur_helper() {
|
install_aur_helper() {
|
||||||
dialog --title "Installing the AUR Helper" --infobox "Installing dependencies..." 0 0
|
dialog --title "Installing the AUR Helper" --infobox "Installing dependencies..." 0 0
|
||||||
pacman --noconfirm --needed -S go &>> $logfile
|
pacman --noconfirm --needed -S go &>> $logfile
|
||||||
dialog --title "Installing the AUR Helper" --infobox "Cloning repository..." 0 0
|
dialog --title "Installing the AUR Helper" --infobox "Cloning repository..." 0 0
|
||||||
cd $(sudo -u $uname mktemp -d)
|
cd $(sudo -u $uname mktemp -d)
|
||||||
git clone https://aur.archlinux.org/yay.git . &>> $logfile
|
git clone "https://aur.archlinux.org/$aurhelper.git" . &>> $logfile
|
||||||
sudo -u $uname makepkg --noconfirm -si &>> $logfile
|
sudo -u $uname makepkg --noconfirm -s &>> $logfile
|
||||||
# pacman -U --noconfirm *.zst
|
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() {
|
installation_loop() {
|
||||||
echo "Entered installationloop\n\n" >> $logfile
|
echo "Entered installationloop\n\n" >> $logfile
|
||||||
([ -f "$prog" ] && cp "$prog" /tmp/pack.csv) || curl -Ls "$prog" > /tmp/pack.csv
|
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
|
# count packages and sum results for all and curr platform
|
||||||
ps=$(($(grep -e "A,P," /tmp/pack.csv | wc -l) + $(grep -e "$curr_platform,P," /tmp/pack.csv | wc -l)))
|
ps=$(($(grep -e "A,P," "$csv" | wc -l) + $(grep -e "$curr_platform,P," "$csv" | wc -l)))
|
||||||
as=$(($(grep -e "A,A," /tmp/pack.csv | wc -l) + $(grep -e "$curr_platform,A," /tmp/pack.csv | wc -l)))
|
as=$(($(grep -e "A,A," "$csv" | wc -l) + $(grep -e "$curr_platform,A," "$csv" | wc -l)))
|
||||||
ms=$(($(grep -e "A,M," /tmp/pack.csv | wc -l) + $(grep -e "$curr_platform,M," /tmp/pack.csv | wc -l)))
|
ms=$(($(grep -e "A,M," "$csv" | wc -l) + $(grep -e "$curr_platform,M," "$csv" | wc -l)))
|
||||||
aur_already_installed=$(pacman -Qqm)
|
aur_already_installed=$(pacman -Qqm)
|
||||||
#IFS separator
|
# For all lines in pack.csv do
|
||||||
while IFS=, read -r platform prefix program info; do
|
while IFS=, read -r platform prefix program info; do
|
||||||
|
|
||||||
if [[ ${platform} != "A" ]] && [[ ${platform} != ${curr_platform} ]]; then
|
[[ ${platform} != "A" ]] && [[ ${platform} != ${curr_platform} ]] && continue
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
case $prefix in
|
case $prefix in
|
||||||
P) install_pacman "$program" "$info" ;;
|
P) install_pacman "$program" "$info" ;;
|
||||||
A) install_aur "$program" "$info" ;;
|
A) install_aur "$program" "$info" ;;
|
||||||
M) install_manual "$program" "$info" ;;
|
M) install_manual "$program" "$info" ;;
|
||||||
esac
|
esac
|
||||||
done < /tmp/pack.csv
|
done < "$csv"
|
||||||
}
|
}
|
||||||
|
|
||||||
enable_service() {
|
enable_service() {
|
||||||
for service in "$@"; do
|
for service in "$@"; do
|
||||||
dialog --infobox "Enabling: $service" 0 0
|
dialog --infobox "Enabling: $service" 0 0
|
||||||
if [[ $@ =~ "--user.*" ]]
|
if [[ $@ =~ "--user.*" ]]; then
|
||||||
then
|
|
||||||
sudo -u $uname systemctl enable "$service"
|
sudo -u $uname systemctl enable "$service"
|
||||||
sudo -u $uname systemctl start "$service"
|
sudo -u $uname systemctl start "$service"
|
||||||
else
|
else
|
||||||
@ -167,7 +186,7 @@ set_permissions() {
|
|||||||
download_dotfiles() {
|
download_dotfiles() {
|
||||||
cd /home/$uname
|
cd /home/$uname
|
||||||
sudo -u $uname mkdir -p .dotfiles && cd .dotfiles
|
sudo -u $uname mkdir -p .dotfiles && cd .dotfiles
|
||||||
sudo -u $uname git clone $repo .
|
sudo -u $uname git clone $dotfiles .
|
||||||
sudo -u $uname ./scripts/link.sh
|
sudo -u $uname ./scripts/link.sh
|
||||||
echo "Dotfiles downloaded and installed\n\n" >> $logfile
|
echo "Dotfiles downloaded and installed\n\n" >> $logfile
|
||||||
}
|
}
|
||||||
@ -179,22 +198,8 @@ no_beep() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ready_steady_go() {
|
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 ;
|
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 ;
|
||||||
|
|
||||||
uncom() {
|
|
||||||
sed -i '/'"$1"'/s/^#//g' $2
|
|
||||||
}
|
|
||||||
|
|
||||||
com() {
|
|
||||||
sed -i '/'"$1"'/s/^/#/g' $2
|
|
||||||
}
|
|
||||||
|
|
||||||
add_after() {
|
|
||||||
# Example:
|
|
||||||
# add_after "Color" "ILoveCandy" "$HOME/test/pacman.conf"
|
|
||||||
sed -i '/'"$2"'/d'
|
|
||||||
sed -i '/'"$1"'/a '"$2"'' $3
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_xorg_conf() {
|
add_xorg_conf() {
|
||||||
@ -213,9 +218,9 @@ add_pacman_hooks() {
|
|||||||
cp $scriptdir/etc/pacman.d/hooks/* /etc/pacman.d/hooks/ &>> $logfile
|
cp $scriptdir/etc/pacman.d/hooks/* /etc/pacman.d/hooks/ &>> $logfile
|
||||||
}
|
}
|
||||||
|
|
||||||
add_xorg_conf() {
|
add_systemd_conf() {
|
||||||
echo "Adding systemd configs\n\n" >> $logfile
|
echo "Adding systemd configs\n\n" >> $logfile
|
||||||
cp $scriptdir/etc/systemd/network/00-wired.network /etc/systemd/network/00-wired.network &>> $logfile
|
cp -r $scriptdir/etc/systemd/* /etc/systemd/ &>> $logfile
|
||||||
}
|
}
|
||||||
|
|
||||||
set_pacman_config() {
|
set_pacman_config() {
|
||||||
@ -244,6 +249,7 @@ set_system_stuff() {
|
|||||||
set_pacman_config
|
set_pacman_config
|
||||||
add_pacman_hooks
|
add_pacman_hooks
|
||||||
add_xorg_conf
|
add_xorg_conf
|
||||||
|
add_systemd_conf
|
||||||
set_git_config
|
set_git_config
|
||||||
#link syncthing config and move certs
|
#link syncthing config and move certs
|
||||||
# sudo -u $uname /home/$uname/.dotfiles/syncthing/link-confs.sh &>> $logfile
|
# sudo -u $uname /home/$uname/.dotfiles/syncthing/link-confs.sh &>> $logfile
|
||||||
@ -300,7 +306,7 @@ case $todo in
|
|||||||
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"
|
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
|
no_beep
|
||||||
set_system_stuff
|
set_system_stuff
|
||||||
enable_service "--user syncthing"
|
enable_service "--user syncthing" "--user pipewire-pulse"
|
||||||
if [[ ${curr_platform} == "L" ]]; then
|
if [[ ${curr_platform} == "L" ]]; then
|
||||||
enable_service "netctl-auto@wlp3s0"
|
enable_service "netctl-auto@wlp3s0"
|
||||||
else
|
else
|
||||||
@ -331,7 +337,7 @@ case $todo in
|
|||||||
else
|
else
|
||||||
enable_service "systemd-networkd"
|
enable_service "systemd-networkd"
|
||||||
fi
|
fi
|
||||||
enable_service "systemd-timesyncd" "atd"
|
enable_service "systemd-timesyncd" "atd" "--user syncthing" "--user pipewire-pulse"
|
||||||
ready_steady_go
|
ready_steady_go
|
||||||
clear
|
clear
|
||||||
;;
|
;;
|
||||||
|
38
pack.csv
38
pack.csv
@ -91,21 +91,31 @@ A,P,redshift,No more burning eyes at night <3
|
|||||||
A,P,alsa-plugins,Extra alsa plugins
|
A,P,alsa-plugins,Extra alsa plugins
|
||||||
A,P,alsa-utils,An alternative implementation of Linux sound support
|
A,P,alsa-utils,An alternative implementation of Linux sound support
|
||||||
|
|
||||||
# A,A,apulse,Compatibility layer for applications that rely on pulseaudio
|
|
||||||
A,P,pulseaudio,Sound server
|
|
||||||
A,P,pulseaudio-alsa,ALSA Configuration for PulseAudio
|
|
||||||
A,P,pavucontrol-qt,GUI to manage PulseAudio
|
|
||||||
|
|
||||||
D,P,pulseaudio-jack,Jack support for PulseAudio
|
|
||||||
D,P,jack2,C++ version of the JACK low-latency audio server for multi-processor machines
|
|
||||||
D,P,jack2-dbus,The JACK low-latency audio server (dbus integration)
|
|
||||||
D,P,a2jmidid,Dbus midi jack thingy
|
|
||||||
D,P,qjackctl,A Qt front-end for the JACK low-latency audio server
|
|
||||||
D,P,python-dbus,Python bindings for DBUS
|
|
||||||
D,P,realtime-privileges,Required for realtime applications
|
|
||||||
|
|
||||||
A,P,blueman,Bluetooth manager
|
A,P,blueman,Bluetooth manager
|
||||||
A,P,pulseaudio-bluetooth,Bluetooth support for PulseAudio
|
|
||||||
|
### PULSEAUDIO / JACK2
|
||||||
|
# A,A,apulse,Compatibility layer for applications that rely on pulseaudio
|
||||||
|
# A,P,pulseaudio,Sound server
|
||||||
|
# A,P,pulseaudio-alsa,ALSA Configuration for PulseAudio
|
||||||
|
# A,P,pavucontrol-qt,GUI to manage PulseAudio
|
||||||
|
|
||||||
|
# D,P,pulseaudio-jack,Jack support for PulseAudio
|
||||||
|
# D,P,jack2,C++ version of the JACK low-latency audio server for multi-processor machines
|
||||||
|
# D,P,jack2-dbus,The JACK low-latency audio server (dbus integration)
|
||||||
|
# D,P,a2jmidid,Dbus midi jack thingy
|
||||||
|
# D,P,qjackctl,A Qt front-end for the JACK low-latency audio server
|
||||||
|
# D,P,python-dbus,Python bindings for DBUS
|
||||||
|
# D,P,realtime-privileges,Required for realtime applications
|
||||||
|
|
||||||
|
# A,P,pulseaudio-bluetooth,Bluetooth support for PulseAudio
|
||||||
|
|
||||||
|
### PIPEWIRE
|
||||||
|
A,P,pipewire,Low-latency audio/video router and processor
|
||||||
|
A,P,pipewire-pulse,PulseAudio replacement
|
||||||
|
A,P,pipewire-alsa,ALSA configuration
|
||||||
|
A,P,pipewire-jack,JACK support
|
||||||
|
A,P,wireplumber,Session and policy manager implementation for PipeWire
|
||||||
|
A,P,qpwgraph,PipeWire Graph Qt GUI Interface
|
||||||
|
|
||||||
# Text editing
|
# Text editing
|
||||||
A,P,emacs,The extensible customizable self-documenting real-time display editor
|
A,P,emacs,The extensible customizable self-documenting real-time display editor
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user