-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfpkg
More file actions
executable file
·302 lines (263 loc) · 6.98 KB
/
fpkg
File metadata and controls
executable file
·302 lines (263 loc) · 6.98 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/usr/bin/env bash
fast="nae"
package_print_format="%-25s%-12s%-40s\n" #printf format
############################
## DUMMY VALUES / NO LOGIC #
############################
repo="FRUE-Games"
repoURL="https://raw.githubusercontent.com/FRUE-Project/FRUE-Games/main/"
ver="0.1-r1"
fpkg_ver="0.1-r2"
#Takes error message as first parameter; used as: command || exit_with_error <MSG>
function exit_with_error() {
echo " !! Error !! $1"
echo " !! Abort !! "
exit 1
}
function warn() {
echo " !! Warn !! $1"
}
function sleepy() {
if [ "$fast" = "nae" ]; then
sleep "$1"
fi
}
#Creates countdowns; used as: countdown <START> 'Countdown msg'
function countdown() {
((s = $1))
for i in $(seq $s -1 1); do
printf ' %s %s...\n' "$2" "$i" && ((i--))
sleep 1
done
}
function remover() {
# shellcheck disable=SC2034
countdown 3 ' !! Removing in'
if [[ -d /usr/bin/"${package}" ]]; then
rm -r /usr/bin/"${package:?}" || exit_with_error "Couldn't remove package."
elif [[ -f /usr/bin/"${package}" ]]; then
rm /usr/bin/"${package}" || exit_with_error "Couldn't remove package."
else
echo "How 'bout yue install that package first?"
exit 1
fi
echo "!! Packages removed!!1 :)"
sleepy 1
}
function pkginfo() {
echo "======PKG=================VERSION=====================REPO================="
# shellcheck disable=SC2059
printf "$package_print_format" "${package}" "$ver" "$repo"
echo "==========================================================================="
}
function Help() {
echo "FRUE Package Kit Getter"
echo "============================="
sleepy 0.5
echo "Version $fpkg_ver"
echo "============================="
sleepy 1
echo "Usage: fpkg [options]"
echo "============================="
sleepy 1
echo " "
echo "Options:"
echo " -i - installs a package"
echo " -r - removes a package"
echo " -h - displays this help dialog and exits"
echo " -f - sets 'fast mode' (waits are skipped)"
echo " -v - display version"
echo " -d - only download the package and save it in /etc/fpkg"
sleepy 1
exit 0
}
function cleanup() {
rm -rf /tmp/fpkg-cache/"${package}"
}
function Install() {
if [ "$remove" = true ]; then
echo ""
echo "Already removed sumthin', ain't gonna install that"
exit 0
else
echo " :: Searchin' for package ..."
if wget -q --method=HEAD ${repoURL}${package}; then
echo " !! Package finded."
else
echo " !! Package ${package} not found."
echo " !! Abort !!"
return 1
fi
sleepy 0.5
echo " These packages gon be INSTALLED: "
pkginfo
#Check if we are installing this package automatically (i.e. it's a dependency) (used by passing "auto" as 2nd parameter to function)
if [ "$2" != "auto" ]; then
read -rp "Cop packages n' install? [Y/n]: " reply
else
reply="y"
fi
case "$reply" in
[nN])
echo " !! Didn't do jack shit..."
;;
[yY])
echo " :: Downloadin' package $package..."
if [[ ! -d /tmp/fpkg-cache ]]; then
mkdir /tmp/fpkg-cache || exit_with_error "Could not create '/tmp/fpkg-cache/'"
chmod 755 -R /tmp/fpkg-cache
fi
mkdir /tmp/fpkg-cache/"${package}"
cd /tmp/fpkg-cache/"${package}" || exit_with_error "Could not cd to '/tmp/fpkg-cache/${package}'"
wget "${repoURL}${package}" >/dev/null 2>&1 || warn "Could not fetch package ${package}. Skippin'."
return 2
if [ "$downloadonly" = true ]; then
echo " !! Package donwloaden'!!1 In '/tmp/fpkg-cache/'"
return
fi
echo " :: Unpackin' package..."
mkdir /etc/fpkg/packages/"$package" ||
#Handle .sh scripts and .fpkg files differently
case $(file --mime-type -b "${package}") in
*shellscript*)
mv "/tmp/fpkg-cache/${package}" /usr/bin || exit_with_error "Could not unpack executables. My bad."
sleepy 2
chmod +x "/usr/bin/${package}"
;;
application/gzip)
mkdir -p /tmp/fpkg-cache/"${package}-cache"
tar -xzvf /tmp/fpkg-cache/"${package}" -O /tmp/fpkg-cache/"${package}-cache" || exit_with_error "Could not unpack executables. My bad."
find . -print0 | while IFS= read -r -d'' f; do
file -ib "$f" | grep shellscr && mv "$f" /usr/bin
chmod +x "/usr/bin/$f"
done
;;
*) ;;
esac
echo " :: Fixin' executables..."
sleepy 1
echo " :: Cleanin' up..."
cleanup
echo " !! Done!!1 :)"
sleepy 1
;;
esac
fi
}
function Remove() {
if [ "$install" = true ]; then
echo ""
echo "Already installed sumthin', ain't gon remove that"
exit 0
else
echo " :: Lookin' in /usr/bin ..."
sleepy 1
echo " !! Packages finded!"
sleepy 0.5
echo "These packages gon be DELETED:"
pkginfo
read -rp "Are you sure you wanna get rid of these packages? [y/n]: " reply
case "$reply" in
[nN])
echo " !! Didn't do jack shit..."
;;
[yY])
remover
;;
esac
fi
}
function ConfClean() {
# shellcheck disable=SC2140
if [[ -d "$HOME"/.config/"${package}*" ]]; then
rm -r "$HOME"/.config/"${package}*" || exit_with_error "Couldn't remove config."
elif [[ -f "$HOME"/.config/"${package}*" ]]; then
rm "$HOME"/.config/"${package}*" || exit_with_error "Couldn't remove config."
else
echo "Sum'n went wrong while removin' that config, my bad."
exit 1
fi
}
function Version() {
echo "$fpkg_ver"
echo "© 2021 - 2022, FRUE Project"
echo "No rights reserved."
exit 0
}
function Purge {
echo " :: Lookin' for packages ..."
sleepy 1
echo " !! Packages finded!"
sleepy 0.5
echo "These packages gon be PURGED:"
pkginfo
read -rp "Are you sure you wanna get rid of these packages? [y/n]: " reply
case "$reply" in
[nN])
echo " !! Didn't do jack shit..."
;;
[yY])
remover
ConfClean
echo "!! Packages pugeded!!1 :)"
sleepy 1
;;
esac
}
#MAIN
#Check for root privileges
if ! [ $(id -u) = 0 ]; then
exit_with_error "Yue gon need root for this dumbass."
exit 1
fi
[[ -d /etc/fpkg/ ]] || mkdir /etc/fpkg/ || exit_with_error "Could not create '/etc/fpkg/'"
chmod 755 /etc/fpkg/ || exit_with_error "Could not chmod '/etc/fpkg/'"
[[ -d /etc/fpkg/packages/ ]] || mkdir /etc/fpkg/packages/ || exit_with_error "Could not create '/etc/fpkg/packages/'"
chmod 755 /etc/fpkg/packages/ || exit_with_error "Could not chmod '/etc/fpkg/packages/'"
[[ -d /etc/fpkg/repositories/ ]] || mkdir /etc/fpkg/repositories/ || exit_with_error "Could not create '/etc/fpkg/repositories/'"
chmod 755 /etc/fpkg/repositories/ || exit_with_error "Could not chmod '/etc/fpkg/repositories/'"
optlist=':hfi:r:vdp:c:' #add new opts here
####################
# PRIORITY OPTIONS #
####################
while getopts "$optlist" option; do
case $option in
f) fast="ye" ;;
d) downloadonly=true ;;
esac
done
OPTIND=1
#####################
# SECONDARY OPTIONS #
#####################
while getopts "$optlist" option; do
case $option in
h) Help ;;
i)
install=true
package=$OPTARG #should not treat it as an array
Install "$package"
exit
;;
r)
remove=true
package=$OPTARG
Remove "$package"
exit
;;
c)
package=$OPTARG
ConfClean "$package"
exit
;;
p)
package=$OPTARG
Purge "$package"
exit
;;
v) Version ;;
\?) Help ;;
esac
done
# shellcheck disable=SC2004
shift $(($OPTIND - 1))