-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathamsitlab-repo
executable file
·136 lines (102 loc) · 2.24 KB
/
amsitlab-repo
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
#!/data/data/com.termux/files/usr/bin/bash
## for enabling https://amaitlab.guthub.io/ repository
## Author : amsit <[email protected]>
##
set -e
## Ensure PREFIX
test -z $PREFIX && \
PREFIX=/data/data/com.termux/files/usr
## Ensure TMPDIR
test -z $TMPDIR && \
TMPDIR="${PREFIX}/tmp"
## gnupg public key file
PUBKEY="${TMPDIR}/pubkey.gpg"
## user device architecture
ARCHITECTURE=$(uname -m)
## location of sources.list
SOURCES_LIST="${PREFIX}/etc/apt/sources.list.d/amsitlab.list"
## main program
main(){
## Displaying help message when args count is 0
if [ $# -eq 0 ]; then
__help
exit
fi
## Filtering allowed arg 1
## Display help message when arg 1 is invalid.
case $1 in
"enable"|"disable")
$@
apt update
;;
"-h"|"help"|*)
__help
;;
esac
}
## help message
__help(){
echo "Usage: "
echo
echo " amsitlab-repo enable"
echo " enabling repo https://amsitlab.github.io"
echo
echo " amsitlab-repo disable"
echo " disabling repo https://amsitlab.github.io"
echo
echo " amsitlab-repo help"
echo " show this message and exit"
echo
echo
echo "# 2018 (C) amsitlab"
}
## help message
help(){
## redirect
__help
}
__missing () {
if [ "x`which ${PREFIX}/bin/${2}`" == "x" ]; then
apt install -y $1
fi
}
## enabling repository
enable(){
apt update
apt upgrade -y
echo "Enabaling"
#apt install gnupg wget
__missing "curl" "curl"
## Download gnupg public key
curl -# -L "https://amsitlab.github.io/pubkey.gpg" -o "$PUBKEY"
apt-key add "$PUBKEY"
rm -fr "$PUBKEY"
## Prevent duplicate entries in sources.list
disable
## Ensure user device architecture
## set as "aarch64" when architecture unknown
if [ -z "$ARCHITECTURE" ]; then
echo "Unknown architecture"
echo "Note:"
echo " Architecture will be set as \"aarch64\""
echo " If this wrong, Please edit file"
echo " ${SOURCES_LIST/$HOME/\~}"
ARCHITECTURE=aarch64
fi
## do not ask me , you known it
case "$ARCHITECTURE" in
armv7*)
ARCHITECTURE=arm
;;
esac
[ ! -r "$SOURCES_LIST" ] && {
echo "deb [trusted=true,arch=all,${ARCHITECTURE}] https://amsitlab.github.io/ termux amsitlab" > "$SOURCES_LIST"
}
}
## Disabling repo
disable(){
#sed -i '/https:\/\/amsitlab.github.io\//d' "$SOURCES_LIST"
rm -f $SOURCES_LIST
}
main $@
unset SOURCES_LIST ARCHITECTURE PUBKEY