Skip to content

Commit d4e7b03

Browse files
committed
Fix stinky code part 3 (final refactor)
- Unify install_package function and override with specific distros - Move install_package functions to src/lib/install-package.sh - BEGONE REPETITIVE CODE! - Fix some typos - Import install_package.sh where necessary - Use more CONSTANTS in git-gpg-ssh-setup.sh - Use #!/bin/bash as the default header - Use rm -rf some/path on base-script.sh instead of rm -r some/path - Add install_my_flatpak_packages function to base-script.sh - Allowing to install all of them in every system with ease - New flatpak packages: ca.parallel_launcher.ParallelLauncher (will test and remove) com.github.Rosalie241.RMG (will test and remove) net.rpcs3.RPCS3 net.pcsx2.PCSX2 org.DolphinEmu.dolphin-emu org.ppsspp.PPSSPP org.duckstation.DuckStation net.kuribo64.melonDS app.xemu.xemu org.libretro.RetroArch org.ryujinx.Ryujinx
1 parent 00ff007 commit d4e7b03

13 files changed

+173
-160
lines changed

linux-script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

33
source ./src/lib/base-script.sh
44

src/lib/arch-base-script.sh

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,9 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

33
source ./src/lib/base-script.sh
4+
source ./src/lib/install-package.sh
45
source ./src/lib/title-templates.sh
56

6-
function install_package() {
7-
local apps=("$1")
8-
if [[ $# -eq 1 ]]; then
9-
local install_block="sudo pacman -S --needed --noconfirm"
10-
else
11-
local install_block="$2"
12-
fi
13-
14-
echo_caption "Runnning: $install_block"
15-
echo_caption "For each package: ${apps[*]}"
16-
17-
# Using IFS (Internal Field Separator) to manage arrays
18-
local counter=0
19-
while IFS=" " read -ra array; do
20-
for app in "${array[@]}"; do
21-
echo_section "($((counter += 1))/${#array[@]}) - ${app}"
22-
eval "$install_block" "${app}"
23-
done
24-
done <<<"${apps[@]}"
25-
}
26-
277
function install_package_managers() {
288
echo_title "Installing Package Managers (Yay, Snap)"
299

@@ -44,9 +24,9 @@ function install_package_managers() {
4424
echo "Snap will work only after loggin' out and in"
4525

4626
echo_caption "Enabling Flatpak"
47-
install_package "flatpak"
27+
install_package_arch "flatpak"
4828

49-
echo_error "To finish the installation, this PC will reboot after confirmation!!!"
29+
echo_error "To finish the installation, this PC will reboot after confirming!!!"
5030
wait_prompt
5131
reboot
5232
}
@@ -64,11 +44,11 @@ function pre_arch_setup() {
6444
echo_section "Initializing and Updating Repositories (Core, Extra, Community and Multilib)"
6545
sudo pacman-key --init
6646
sudo pacman-key --populate
67-
install_package "archlinux-keyring" "sudo pacman -Syy --needed --noconfirm"
47+
install_package_arch "archlinux-keyring" "sudo pacman -Syy --needed --noconfirm"
6848

6949
echo_caption "Installing required packages for every script"
7050
# 2 Terminal Download Manager | 1 Git (If doesn't have) | 2 Compress/Extract zip files | 1 Tool to change Shell | 1 Z-Shell (ZSH)
71-
install_package "curl wget git unzip zip which zsh"
51+
install_package_arch "curl wget git unzip zip which zsh"
7252

7353
fix_time_zone
7454
}
@@ -86,8 +66,8 @@ function pre_arch_setup() {
8666
# 7 sbctl -s /efi/EFI/systemd/systemd-bootx64.efi
8767
# 8 sbctl sign -s /efi/EFI/systemd/systemd-bootx64.efi
8868
# 9 bootctl install
89-
# 13 sbctl sign -s /efi/1f0883d502ec49c5a55e9acdd375bc4a/6.9.6-arch1-1/linux # GENERATED KERNEL DIR
90-
# 14 sbctl verify
91-
# 15 reboot
92-
# 16 sbctl status
93-
# 17 bootctl status
69+
# 10 sbctl sign -s /efi/1f0883d502ec49c5a55e9acdd375bc4a/6.9.6-arch1-1/linux # GENERATED KERNEL DIR
70+
# 11 sbctl verify
71+
# 12 reboot
72+
# 13 sbctl status
73+
# 14 bootctl status

src/lib/base-script.sh

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

3+
source ./src/lib/install-package.sh
34
source ./src/lib/title-templates.sh
45

56
SYSTEM_BASED_ON=$(grep -i "ID_LIKE=" /etc/*-release | sed -e "s/^.*ID_LIKE=//" | head -n1)
@@ -87,7 +88,7 @@ function install_fonts() {
8788
unzip JetBrainsMono.zip "fonts/ttf/*.ttf"
8889
echo_section "Moving JetBrains Mono font"
8990
mv --force --verbose fonts/ttf/*.ttf ./
90-
rm -r fonts
91+
rm -rf fonts/
9192
rm JetBrainsMono.zip
9293
popd || exit
9394

@@ -105,12 +106,35 @@ function install_fonts() {
105106
fc-cache -v -f
106107

107108
echo_caption "Removing fonts/ folder from $(pwd)"
108-
rm -r fonts/
109+
rm -rf fonts/
109110

110111
echo_section "Create Downloads folder"
111112
mkdir --parents ~/Downloads
112113
}
113114

115+
function install_my_flatpak_packages() {
116+
local flatpak_apps=(
117+
"dev.vencord.Vesktop" # | Vesktop (better Discord alternative for linux)
118+
"org.onlyoffice.desktopeditors" # | ONLYOFFICE Desktop Editors
119+
# Emulators
120+
"ca.parallel_launcher.ParallelLauncher" # ✅ | Nintendo 64
121+
"com.github.Rosalie241.RMG" # ✅ | Nintendo 64
122+
"net.rpcs3.RPCS3" # ❌ | PS3
123+
"net.pcsx2.PCSX2" # ✅ | PS2
124+
"org.DolphinEmu.dolphin-emu" # ❌ | Nintendo GameCube / Wii
125+
"org.ppsspp.PPSSPP" # ✅ | PSP
126+
"org.duckstation.DuckStation" # ✅ | PS1
127+
"net.kuribo64.melonDS" # ✅ | Nintendo DS
128+
"app.xemu.xemu" # ❌ | Xbox
129+
"org.libretro.RetroArch" # ✅ | Most Retro
130+
"org.ryujinx.Ryujinx" # ✅ | Nintendo Switch
131+
)
132+
133+
echo_section "Installing via flatpak"
134+
echo "${flatpak_apps[*]}"
135+
install_package_flatpak "${flatpak_apps[*]}"
136+
}
137+
114138
function install_zsh() {
115139
echo_title "Z-Shell install"
116140
echo_caption "Zsh should already be installed, this just to finish it's install"
@@ -131,7 +155,7 @@ function install_oh_my_zsh() {
131155

132156
if [[ -d "$HOME/.oh-my-zsh" ]]; then
133157
echo_error "ATTENTION - Removing ~/.oh-my-zsh file to reinstall from 0."
134-
sudo rm --recursive ~/.oh-my-zsh
158+
sudo rm -rf ~/.oh-my-zsh
135159
fi
136160

137161
echo_caption "Installing Oh My Zsh..."

src/lib/fedora-base-script.sh

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,17 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

33
source ./src/lib/base-script.sh
4+
source ./src/lib/install-package.sh
45
source ./src/lib/title-templates.sh
56

6-
function install_package() {
7-
local apps=("$1")
8-
if [[ $# -eq 1 ]]; then
9-
local install_block="sudo dnf install -y"
10-
else
11-
local install_block="$2"
12-
fi
13-
14-
echo_caption "Runnning: $install_block"
15-
echo_caption "For each package: ${apps[*]}"
16-
17-
# Using IFS (Internal Field Separator) to manage arrays
18-
local counter=0
19-
while IFS=" " read -ra array; do
20-
for app in "${array[@]}"; do
21-
echo_section "($((counter += 1))/${#array[@]}) - ${app}"
22-
eval "$install_block" "${app}"
23-
done
24-
done <<<"${apps[@]}"
25-
}
26-
277
function pre_fedora_setup() {
288
# 2 Terminal Download Manager | 1 Git (If doesn't have) | 2 Compress/Extract zip files | 1 Tool to change Shell | 1 Z-Shell (ZSH) | 1 Install chsh commands + others
29-
install_package "curl wget git unzip zip which zsh util-linux-user"
9+
install_package_fedora "curl wget git unzip zip which zsh util-linux-user"
3010

3111
fix_time_zone
3212
}
3313

3414
function upgrade_all_fedora() {
3515
sudo dnf upgrade
36-
install_package "dnf-plugin-system-upgrade"
16+
install_package_fedora "dnf-plugin-system-upgrade"
3717
}

src/lib/install-package.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
source ./src/lib/title-templates.sh
4+
5+
# TODO: detect the OS package manager and do it automatically
6+
# TODO 2: Allow to use flags such as:
7+
# - Per Distro: --apt --dnf --aur (with yay) --pacman
8+
# - Globally: --snap --flatpak (--nix?)
9+
# - More options: --single-install (default) --multiple-install --add-apt-repo
10+
function install_package() {
11+
local apps=("$1")
12+
if [[ $# -eq 1 ]]; then
13+
echo_error "Package install command missing!!! Quitting..." || exit
14+
else
15+
local install_block="$2"
16+
fi
17+
18+
echo_caption "Runnning: $install_block"
19+
echo_caption "For each package: ${apps[*]}"
20+
21+
# Using IFS (Internal Field Separator) to manage arrays
22+
local counter=0
23+
while IFS=" " read -ra apps; do
24+
for app in "${apps[@]}"; do
25+
echo_section "($((counter += 1))/${#apps[@]}) - ${app}"
26+
eval "$install_block" "${app}"
27+
done
28+
done <<<"${apps[@]}"
29+
}
30+
31+
function install_package_flatpak() {
32+
if [[ $# -eq 1 ]]; then
33+
install_package "$1" "flatpak install flathub --system -y"
34+
elif [[ $# -eq 2 ]]; then
35+
install_package "$1" "$2"
36+
fi
37+
}
38+
39+
function install_package_arch() {
40+
if [[ $# -eq 1 ]]; then
41+
install_package "$1" "sudo pacman -S --needed --noconfirm"
42+
elif [[ $# -eq 2 ]]; then
43+
install_package "$1" "$2"
44+
fi
45+
}
46+
47+
function install_package_fedora() {
48+
if [[ $# -eq 1 ]]; then
49+
install_package "$1" "sudo dnf install -y"
50+
elif [[ $# -eq 2 ]]; then
51+
install_package "$1" "$2"
52+
fi
53+
}
54+
55+
function install_package_ubuntu() {
56+
if [[ $# -eq 1 ]]; then
57+
install_package "$1" "sudo apt install -y"
58+
elif [[ $# -eq 2 ]]; then
59+
install_package "$1" "$2"
60+
fi
61+
}

src/lib/title-templates.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

33
function echo_title() {
44
local text="$1"

src/lib/ubuntu-base-script.sh

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,9 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

33
source ./src/lib/base-script.sh
4+
source ./src/lib/install-package.sh
45
source ./src/lib/title-templates.sh
56

6-
function install_package() {
7-
local apps=("$1")
8-
if [[ $# -eq 1 ]]; then
9-
local install_block="sudo apt install -y"
10-
else
11-
local install_block="$2"
12-
fi
13-
14-
echo_caption "Runnning: $install_block"
15-
echo_caption "For each package: ${apps[*]}"
16-
17-
# Using IFS (Internal Field Separator) to manage arrays
18-
local counter=0
19-
while IFS=" " read -ra array; do
20-
for app in "${array[@]}"; do
21-
echo_section "($((counter += 1))/${#array[@]}) - ${app}"
22-
eval "$install_block" "${app}"
23-
done
24-
done <<<"${apps[@]}"
25-
}
26-
277
function pre_ubuntu_setup() {
288
echo_title "Pre Ubuntu Setup"
299
echo_section "Fix/Update currently installed Packages"
@@ -40,7 +20,7 @@ function pre_ubuntu_setup() {
4020

4121
echo_caption "Installing required packages for every script..."
4222
# 2 Terminal Download Manager | 1 Git (If doesn't have) | 2 Compress/Extract zip files | 1 Tool to change Shell | 1 Z-Shell (ZSH)
43-
install_package "curl wget git unzip zip zsh"
23+
install_package_ubuntu "curl wget git unzip zip zsh"
4424

4525
fix_time_zone
4626
}

0 commit comments

Comments
 (0)