-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtekel.sh
executable file
·214 lines (202 loc) · 4.54 KB
/
tekel.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
#!/bin/bash
APPDIR="/data/app/$USER"
umask 022
if [ ! -d /data/app/ ] ; then
APPDIR=$HOME/.tekelapps
mkdir -p $APPDIR 2>/dev/null || true
fi
set -e
if [ ! -d $APPDIR ] ; then
su -c "mkdir -p $APPDIR ; chmod 755 $APPDIR ; chown $USER -R $APPDIR" || exit 1
fi
[ "$REPO" == "" ] && export REPO="https://gitlab.com/sulinos/repositories/tekel-repo/-/raw/master/index.txt"
if [ $UID -eq 0 ] ; then
APPDIR=/data/app/system
if [ ! -d /data/app/ ] ; then
APPDIR=/opt/
fi
fi
if [ ! -d $APPDIR ] ; then
su -c "mkdir -p $APPDIR ; chown $USER $APPDIR ; chmod 755 $APPDIR" 2>/dev/null || true
fi
touch $HOME/.tekel
generate_line(){
while read line
do
name=$(basename $line | sed "s/\.sh$//g")
echo "$name::$(cat repo_url)/$line"
done
}
index(){
find | grep ".sh$" | generate_line | sed "s|/\./|/|g" > index.txt
}
install_common(){
cd $APPDIR/$1
. "$1.tekel"
[ "$SOURCE" == "" ] || wget -c $SOURCE
set -x
_setup
set +x
cd $APPDIR/$1
set -x
_build
set +x
cd $APPDIR/$1
set -x
_install
set +x
if ! [ "$desktop_files" == "" ] ; then
return 0
fi
if [ $UID -eq 0 ] ; then
export dfile="/usr/share/applications/$NAME.tekel.desktop"
else
mkdir -p "$HOME/.local/share/applications/" 2>/dev/null
export dfile="$HOME/.local/share/applications/$NAME.desktop"
fi
mkdir -p "$(dirname $dfile)" 2>/dev/null || true
touch $dfile
chmod +x $dfile
echo "[Desktop Entry]" > $dfile
echo "Version=1.0" >> $dfile
echo "Name=$NAME" >> $dfile
echo "Comment=$COMMENT" >> $dfile
echo "Categories=$CATEGORY" >> $dfile
echo "Icon=$ICON" >> $dfile
echo "Exec=$EXEC" >> $dfile
echo "Type=Application" >> $dfile
echo "MimeType=$MIMETYPE" >> $dfile
echo "X-GNOME-UsesNotifications=true" >> $dfile
}
install_remote(){
if [ -f "$APPDIR/$1/$1.tekel" ] ; then
echo "Package $1 already installed."
echo "You can remove $APPDIR/$1."
exit 1
fi
link=$(cat $HOME/.tekel | grep $1 | head -n 1 | sed "s/^.*:://g")
curl $link > "/tmp/$1.tekel"
if [ -f "/tmp/$1.tekel" ] ; then
mkdir -p $APPDIR/$1
mv "/tmp/$1.tekel" "$APPDIR/$1/$1.tekel"
install_common $1
else
echo "Cannot get tekel file"
exit 1
fi
}
install_local(){
if [ -f "$APPDIR/$1/$1.tekel" ] ; then
echo "Package $1 already installed."
echo "You can remove $APPDIR/$1."
exit 1
fi
if [ -f "$1" ] ; then
name=$(sh -c "source $(realpath $1) ; echo -n \$NAME" | sed "s/ /_/g")
mkdir -p $APPDIR/$name
cp "$1" "$APPDIR/$name/$name.tekel"
install_common $name
else
echo "Tekel file not found"
exit 1
fi
}
remove(){
if [ -f "$APPDIR/$1/$1.tekel" ] ; then
. "$APPDIR/$1/$1.tekel"
if [ "$desktop_files" == "" ] ; then
if [ $UID -eq 0 ] ; then
rm -f "/usr/share/applications/$NAME.desktop"
else
rm -f "$HOME/.local/share/applications/$NAME.desktop"
fi
else
for file in ${desktop_files[@]} ; do
if [ $UID -eq 0 ] ; then
rm -f "/usr/share/applications/$file.desktop"
else
rm -f "$HOME/.local/share/applications/$file.desktop"
fi
done
fi
rm -rf "$APPDIR/$1"
fi
}
update(){
curl $REPO > $HOME/.tekel
}
list(){
cd $APPDIR
ls | while read line
do
[ -f "$APPDIR/$line/$line.tekel" ] && echo $line
done | sort
}
look(){
cat $HOME/.tekel | sed "s/::.*$//g" | sort | grep "$1"
}
selfupdate(){
su -c "curl https://gitlab.com/sulinos/devel/tekel/-/raw/master/tekel.sh > /usr/bin/tekel"
}
print_help(){
echo "tekel - Userspace package installer for SulinOS"
if [ "$1" != "" ]; then
echo
echo "$@"
fi
echo
echo "i/install <package-name> - install package"
echo "il/install-local <package-name> - install package from local"
echo "s/show - list installable packages"
echo "l/list - list installed packages"
echo "u/update - update installable package list"
echo "r/remove <package-name> - remove package"
echo "n/index - index repo"
}
case "$1" in
i|install)
if [ "$3" != "" ]; then
print_help $1: requires only one argument
elif [ "$2" != "" ]; then
install_remote $2
else
print_help $1: requires an extra argument
fi
;;
il|install-local)
if [ "$3" != "" ]; then
print_help $1: requires only one argument
elif [ "$2" != "" ]; then
install_local $2
else
print_help $1: requires an extra argument
fi
;;
s|show)
look $2
;;
l|list)
list
;;
r|remove)
if [ "$3" != "" ]; then
print_help $1: requires only one argument
elif [ "$2" != "" ]; then
remove $2
else
print_help $1: requires an extra argument
fi
;;
u|update)
update
;;
n|index)
index
;;
+|selfupdate)
selfupdate
;;
*)
print_help
;;
esac