forked from CachyOS/CachyOS-Live-ISO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.sh
executable file
·104 lines (89 loc) · 3.11 KB
/
util.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
#!/bin/bash
# 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; version 2 of the License.
#
# 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.
get_timer(){
echo $(date +%s)
}
# $1: start timer
elapsed_time(){
echo $(echo $1 $(get_timer) | awk '{ printf "%0.2f",($2-$1)/60 }')
}
show_elapsed_time(){
info "Time %s: %s minutes" "$1" "$(elapsed_time $2)"
}
check_root(){
(( EUID == 0 )) && return
if type -P sudo >/dev/null; then
exec sudo -- "$@"
else
exec su root -c "$(printf ' %q' "$@")"
fi
}
check_requirements(){
local package="archiso"
#checking if application is already installed or else install with aur helpers
if ! pacman -Qi $package &> /dev/null; then
# checking which helper is installed
if pacman -Qi yay &> /dev/null; then
echo "################################################################"
echo "######### Installing with yay"
echo "################################################################"
yay -S --noconfirm $package
elif pacman -Qi trizen &> /dev/null; then
echo "################################################################"
echo "######### Installing with trizen"
echo "################################################################"
trizen -S --noconfirm --needed --noedit $package
fi
# Just checking if installation was successful
if pacman -Qi $package &> /dev/null; then
echo "################################################################"
echo "######### "$package" has been installed"
echo "################################################################"
else
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!!!!!!!! "$package" has NOT been installed"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit 1
fi
fi
}
prepare_dir(){
if [[ ! -d $1 ]]; then
mkdir -p $1
fi
}
load_vars() {
[[ -f $1 ]] || return 1
local var
for var in {SRC,SRCPKG,PKG,LOG}DEST MAKEFLAGS PACKAGER CARCH GPGKEY; do
[[ -z ${!var} ]] && eval $(grep -a "^${var}=" "$1")
done
return 0
}
create_chksums() {
msg2 "creating checksums for [$1]"
sha1sum $1 > $1.sha1
sha256sum $1 > $1.sha256
}
sign_with_key() {
load_vars "$HOME/.makepkg.conf"
load_vars /etc/makepkg.conf
if [ ! -e "$1" ]; then
error "%s does not exist!" "$1"
exit 1
fi
msg2 "signing [%s] with key %s" "${1##*/}" "${GPGKEY}"
[[ -e "$1".sig ]] && rm "$1".sig
local SIGNWITHKEY=()
if [[ -n $GPGKEY ]]; then
SIGNWITHKEY=(-u "${GPGKEY}")
fi
gpg --detach-sign --use-agent "${SIGNWITHKEY[@]}" "$1"
}