-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcachyos-repo.sh
executable file
·231 lines (193 loc) · 6.53 KB
/
cachyos-repo.sh
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
# Copyright (C) 2022-2024 CachyOS team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
set -e
if [[ $1 == "--help" ]]; then
cat<<EOF
Usage: cachyos-repo.sh [options]
Options:
--help Display this information.
--install Install repo.
--remove Remove repo.
EOF
exit 0
fi
if [ "$EUID" -ne 0 ]; then
echo "Please, run script with sudo"
exit 1
fi
if [ ! -f /etc/pacman.conf ]; then
echo "File [/etc/pacman.conf] not found!"
exit 1
fi
_install=true
_remove=false
for i in "$@"; do
case $i in
--install)
_install=true
_remove=false
shift # past argument=value
;;
--remove)
_install=false
_remove=true
shift # past argument=value
;;
*)
# unknown option
echo "Unknown argument: '$i'!"
exit 1
;;
esac
done
export LC_MESSAGES=C
export LANG=C
disable_colors() {
unset ALL_OFF BOLD BLUE GREEN RED YELLOW
}
enable_colors() {
# prefer terminal safe colored and bold text when tput is supported
if tput setaf 0 &>/dev/null; then
ALL_OFF="$(tput sgr0)"
BOLD="$(tput bold)"
RED="${BOLD}$(tput setaf 1)"
GREEN="${BOLD}$(tput setaf 2)"
YELLOW="${BOLD}$(tput setaf 3)"
BLUE="${BOLD}$(tput setaf 4)"
else
ALL_OFF="\e[0m"
BOLD="\e[1m"
RED="${BOLD}\e[31m"
GREEN="${BOLD}\e[32m"
YELLOW="${BOLD}\e[33m"
BLUE="${BOLD}\e[34m"
fi
readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
}
if [[ -t 2 ]]; then
enable_colors
else
disable_colors
fi
msg() {
local mesg=$1; shift
printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
info() {
local mesg=$1; shift
printf "${YELLOW} -->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
check_supported_isa_level() {
/lib/ld-linux-x86-64.so.2 --help | grep "$1 (supported, searched)" > /dev/null
echo $?
}
check_supported_znver45() {
gcc -march=native -Q --help=target 2>&1 | head -n 35 | grep -E '(znver4|znver5)' > /dev/null
echo $?
}
check_if_repo_was_added() {
cat /etc/pacman.conf | grep "(cachyos\|cachyos-v3\|cachyos-core-v3\|cachyos-extra-v3\|cachyos-testing-v3\|cachyos-v4\|cachyos-core-v4\|cachyos-extra-v4\|cachyos-znver4\|cachyos-core-znver4\|cachyos-extra-znver4)" > /dev/null
echo $?
}
check_if_repo_was_commented() {
cat /etc/pacman.conf | grep "cachyos\|cachyos-v3\|cachyos-core-v3\|cachyos-extra-v3\|cachyos-testing-v3\|cachyos-v4\|cachyos-core-v4\|cachyos-extra-v4\|cachyos-znver4\|cachyos-core-znver4\|cachyos-extra-znver4" | grep -v "#\[" | grep "\[" > /dev/null
echo $?
}
add_specific_repo() {
local isa_level="$1"
local gawk_script="$2"
local repo_name="$3"
local cmd_check="check_supported_isa_level ${isa_level}"
local pacman_conf="/etc/pacman.conf"
local pacman_conf_cachyos="./pacman.conf"
local pacman_conf_path_backup="/etc/pacman.conf.bak"
local is_isa_supported="$(eval ${cmd_check})"
if [ $is_isa_supported -eq 0 ]; then
info "${isa_level} is supported"
cp $pacman_conf $pacman_conf_cachyos
gawk -i inplace -f $gawk_script $pacman_conf_cachyos || true
info "Backup old config"
mv $pacman_conf $pacman_conf_path_backup
info "CachyOS ${repo_name} Repo changed"
mv $pacman_conf_cachyos $pacman_conf
else
info "${isa_level} is not supported"
fi
}
run_install() {
msg "Installing CachyOS repo.."
pacman-key --recv-keys F3B607488DB35A47 --keyserver keyserver.ubuntu.com
pacman-key --lsign-key F3B607488DB35A47
local mirror_url="https://mirror.cachyos.org/repo/x86_64/cachyos"
pacman -U "${mirror_url}/cachyos-keyring-20240331-1-any.pkg.tar.zst" \
"${mirror_url}/cachyos-mirrorlist-18-1-any.pkg.tar.zst" \
"${mirror_url}/cachyos-v3-mirrorlist-18-1-any.pkg.tar.zst" \
"${mirror_url}/cachyos-v4-mirrorlist-6-1-any.pkg.tar.zst" \
"${mirror_url}/pacman-7.0.0.r6.gc685ae6-3-x86_64.pkg.tar.zst"
local is_repo_added="$(check_if_repo_was_added)"
local is_repo_commented="$(check_if_repo_was_commented)"
local is_isa_v4_supported="$(check_supported_isa_level x86-64-v4)"
local is_znver_supported="$(check_supported_znver45)"
if [ $is_repo_added -ne 0 ] || [ $is_repo_commented -ne 0 ]; then
if [ $is_znver_supported -eq 0 ]; then
add_specific_repo x86-64-v4 ./install-znver4-repo.awk cachyos-znver4
elif [ $is_isa_v4_supported -eq 0 ]; then
add_specific_repo x86-64-v4 ./install-v4-repo.awk cachyos-v4
else
add_specific_repo x86-64-v3 ./install-repo.awk cachyos-v3
fi
else
info "Repo is already added!"
fi
msg "Done installing CachyOS repo."
}
run_remove() {
msg "Removing CachyOS repo.."
local pacman_conf="/etc/pacman.conf"
local pacman_conf_cachyos="./pacman.conf"
local pacman_conf_path_backup="/etc/pacman.conf.bak"
local is_repo_added="$(check_if_repo_was_added)"
local is_repo_commented="$(check_if_repo_was_commented)"
if [ $is_repo_added -eq 0 ] || [ $is_repo_commented -eq 0 ]; then
cp $pacman_conf $pacman_conf_cachyos
gawk -i inplace -f ./remove-repo.awk $pacman_conf_cachyos || true
info "Backup old config"
mv $pacman_conf $pacman_conf_path_backup
info "CachyOS repo removed"
mv $pacman_conf_cachyos $pacman_conf
pacman -Suuy
pacman -S core/pacman
pacman -Qqn | pacman -S -
pacman -R "cachyos-keyring" \
"cachyos-mirrorlist" \
"cachyos-v3-mirrorlist" \
"cachyos-v4-mirrorlist"
pacman-key --delete F3B607488DB35A47 || true
else
info "Repo is not added!"
fi
msg "Done removing CachyOS repo."
}
run() {
if $_install; then
run_install
elif $_remove; then
run_remove
fi
pacman -Syu
}
run