-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall_repo.sh
More file actions
139 lines (118 loc) · 4 KB
/
install_repo.sh
File metadata and controls
139 lines (118 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
#
# install_repo.sh - part of the MiniArch project
# Copyright (C) 2024-2025, JustScott, development@justscott.me
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
STDOUT_LOG_PATH="/dev/null"
STDERR_LOG_PATH="/miniarcherrors.log"
SHARED_LIB_URL="https://raw.githubusercontent.com/JustScott/MiniArch/refs/heads/main/shared_lib"
REPO_URL="https://www.github.com/JustScott/MiniArch"
REPO_DIRECTORY="$(basename "$REPO_URL")"
PACMAN_UPDATED_FILE="/tmp/pacman_update"
printf "\n\e[36m%s\e[0m" "Download the shared_lib file..."
curl -LO $SHARED_LIB_URL >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH"
if [[ $? -ne 0 ]]
then
printf "\r\n\e[31m%s %s\e[0m\n" \
"[!] Failed to install the shared_lib file." \
"Are you connected to the internet?"
exit 1
fi
printf "\r\e[32m%s\e[0m %s\n" "[Success]" "Download the shared_lib file"
source ./shared_lib
wipe_pacman_keys()
{
{
umount /etc/pacman.d/gnupg
rm -rf /etc/pacman.d/gnupg
} >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Wipe the faulty keyring"
[[ $? -ne 0 ]] && return 1
return 0
}
configure_pacman()
{
pacman-key --init >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Ensure the keyring is properly initialized"
[[ $? -ne 0 ]] && return 1
pacman-key --populate archlinux >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Reload the default keys from the keyrings"
[[ $? -ne 0 ]] && return 1
pacman -Sy >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Update pacman's package database"
[[ $? -ne 0 ]] && return 1
touch $PACMAN_UPDATED_FILE
pacman -S --noconfirm archlinux-keyring \
>>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Update pacman's keyring"
[[ $? -ne 0 ]] && return 1
return 0
}
if ! configure_pacman
then
wipe_pacman_keys
if ! configure_pacman
then
printf "\e[31m%s\n%s\n%s\e[0m" \
"[!] Failed to configure pacman keys." \
" - Likely system time is off, or your network had issues." \
" - Check '$STDERR_LOG_PATH' for error logs."
exit 1
fi
fi
if ! pacman -Q git fzf &>/dev/null
then
pacman -S --noconfirm git fzf >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Install git"
[[ $? -ne 0 ]] && exit 1
fi
# Clear the old repo if it exists
if [[ -d "$REPO_DIRECTORY" ]]
then
rm -rf "$REPO_DIRECTORY" &>/dev/null
fi
# Clone the repo
git clone $REPO_URL \
>>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" "Clone the MiniArch repo"
[[ $? -ne 0 ]] && exit 1
if ! cd MiniArch &>/dev/null
then
printf "\n\e[31m%s%s\e[0m\n\n" \
"[!] Failed to cd into MiniArch... this shouldn't happen."
exit 1
fi
chosen_branch="$( \
git branch -a \
| grep "remotes" \
| grep -v "HEAD" \
| awk -F'/' '{print $3}' \
| fzf --prompt="Choose a branch: " --reverse)"
clear
if [[ -n "$chosen_branch" ]]
then
if ! git checkout "$chosen_branch" &>/dev/null
then
printf "\n\e[31m%s%s\e[0m\n\n" \
"[!] Failed to git checkout '$chosen_branch'... this shouldn't happen."
exit 1
fi
cd ../
bash MiniArch/start_install.sh
else
printf "\n\e[31m%s%s\e[0m\n\n" \
"[!] No branch chosen... Goodbye"
exit 1
fi