-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharchimage-cli
379 lines (305 loc) · 12.7 KB
/
archimage-cli
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#!/usr/bin/env bash
VERSION="4.3"
DIR="$( cd "$( dirname "$0" )" && pwd )"
ARCHIMAGE_REPO="https://raw.githubusercontent.com/ivan-hc/ArchImage/main"
DIVIDING_LINE="
-----------------------------------------------------------------------------
"
# Colors
Gold='\033[0;33m'
Green='\033[0;32m'
LightBlue='\033[1;34m'
# Common functions
_fit() {
fold -sw 77 | sed 's/^/ /g'
}
# Makes "less" optional
less() {
if ! command less "$@" 2>/dev/null; then
while read -r line; do echo "$line"; done
echo "Install 'less' if you want to scroll this list"
fi
}
# XDG Variables
SCRIPTDIR="${SCRIPTDIR:-$(xdg-user-dir DESKTOP 2>/dev/null)}"
if [ ! -d "$SCRIPTDIR" ]; then
echo "◆ No \"XDG DESKTOP\" directory found, scripts will be saved in \"$PWD\"" | _fit
SCRIPTDIR="$PWD"
fi
CACHEDIR="${XDG_CACHE_HOME:-$HOME/.cache}"
mkdir -p "$CACHEDIR"
DATADIR="${XDG_DATA_HOME:-$HOME/.local/share}"
mkdir -p "$DATADIR"
# DEVELOPER MODE
[ -d "$DATADIR/AM" ] && AMDATADIR="$DATADIR/AM"
if [ -f "$AMDATADIR"/archimage-betatester ]; then
ARCHIMAGE_REPO="https://raw.githubusercontent.com/ivan-hc/ArchImage/dev"
fi
_betatester_message_on() {
if [ -f "$AMDATADIR"/archimage-betatester ]; then
echo "$DIVIDING_LINE" | grep -- "-"; echo "\"Archimage CLI\" $AMVERSION: DEVELOPER MODE"; echo "$DIVIDING_LINE" | grep -- "-"
fi
}
################################################################################
# HELP
################################################################################
HELP_MESSAGE="
NAME: ${Green}ArchImage CLI\033[0m VERSION: ${Green}$VERSION\033[0m
SYNOPSIS: ${LightBlue}archimage-cli {OPTION}\033[0m
${LightBlue}archimage-cli {OPTION} {PROGRAM}\033[0m
DESCRIPTION: A command line interface to build AppImages based on JuNest, the lightweight Arch Linux based distro that runs, without root privileges, on top of any other Linux distro.
OPTIONS:
${Gold}-b,--build\033[0m\033[0m
${LightBlue}archimage-cli -b {program}\033[0m
Description: Create the script to build the AppImage.
${Gold}--devmode-disable\033[0m
${LightBlue}$AMCLI --devmode-disable\033[0m
Description: Undo \"--devmode-enable\" (see below).
${Gold}--devmode-enable\033[0m
${LightBlue}$AMCLI --devmode-enable\033[0m
Description: Use the development branch (at your own risk).
${Gold}-h,--help\033[0m
${LightBlue}archimage-cli -h\033[0m
Description: Shows this message.
${Gold}-s,--sync\033[0m
${LightBlue}archimage-cli -s\033[0m
Description: Update \"archimage-cli\" to the latest version.
${Gold}-v,--version\033[0m
${LightBlue}archimage-cli -v\033[0m
Description: Shows the version.
$DIVIDING_LINE
SITE:
https://github.com/ivan-hc/ArchImage
\"Archimage\" is powered by \"JuNest\":
https://github.com/fsquillace/JuNest
"
_help() {
printf "%b\n" "$HELP_MESSAGE" | _fit | sed "s/ --/--/g" | less -Ir
}
################################################################################
# BASH AND ZSH COMPLETION
################################################################################
completion_file="$DATADIR/bash-completion/completions/archimage-cli"
mkdir -p "$DATADIR/bash-completion/completions" || exit 1
if ! grep -o " archimage-cli$" "$completion_file" >/dev/null 2>&1 && [ -f "$AMDATADIR"/list ]; then
echo "complete -W \"\$(cat $AMDATADIR/list 2>/dev/null)\" archimage-cli" >> "$completion_file"
if [ -f "${ZDOTDIR:-$HOME}"/.zshrc ] && echo "$SHELL" | grep -q "zsh"; then
cat <<-HEREDOC >> "${ZDOTDIR:-$HOME}"/.zshrc
autoload bashcompinit
bashcompinit
source "$completion_file"
HEREDOC
fi
echo "Shell completion has been enabled!"
fi
################################################################################
# SYNC
################################################################################
_sync() {
cd "$DIR" || exit 1
echo -ne " ◆ Synchronizing Archimage CLI v$(./archimage-cli -v)...\r"; sleep 0.5
wget -q "$ARCHIMAGE_REPO/archimage-cli" -O "$CACHEDIR"/archimage-cli && chmod a+x "$CACHEDIR"/archimage-cli;
mv "$CACHEDIR"/archimage-cli ./archimage-cli; echo " ◆ ArchImage CLI is now updated to the version $(./archimage-cli -v) "
}
################################################################################
# BUILD
################################################################################
# First step
GETTING_STARTED_HEADER="-----------------------------------------------------------------------------
${LightBlue}ARCHIMAGE SCRIPT CREATING WIZARD\033[0m, v$VERSION
$DIVIDING_LINE"
GETTING_STARTED_MSG="After creating the script, make sure to run it in a dedicated directory.
Do not run the script in directories that are already occupied!
You can re-run the same script at the end of the process in case the AppImage creation failed and the program does not work as you wanted, as long as everything happens always in the same dedicated directory."
# Name the executable in /usr/bin if different from the appname
_usr_bin_executable_name() {
echo "$DIVIDING_LINE"
read -r -ep "◆ NAME THE MAIN EXECUTABLE IN \$PATH, OR LEAVE BLANK IF IT IS THE SAME: " response
[ -n "$response" ] && sed -i "s/^BIN=\"\$APP\"/BIN=\"$response\"/g" ./"$APP"-junest.sh
}
# Add optional dependencies
_add_dependencies() {
read -r -ep "◆ ADD (OPTIONAL) DEPENDENCIES OR LEAVE BLANK: " RESPONSE
[ -n "$RESPONSE" ] && sed -i "s/^DEPENDENCES=\"\"/DEPENDENCES=\"$RESPONSE\"/g" ./"$APP"-junest.sh
}
# Set the level of sub-dependencies extraction, the higher the number, the bigger the AppImage will be
_extraction_level() {
echo "◆ Set the level of sub-dependencies."
echo ""
echo "The variable \"\$extraction_count\" indicates the number of checks made on dependencies and dependencies of dependencies. The higher the number, the more packages will be included, the more successfully the app will work... the bigger the AppImage will be." | _fit | sed 's/^/ /g'
echo ""
read -r -ep " LEAVE BLANK TO SET THE DEFAULT VALUE TO 1 (RECOMMENDED): " extraction_number
[ -n "$extraction_number" ] && [[ "$extraction_number" =~ ^[0-9]+$ ]] && sed -i "s/extraction_count=1/extraction_count=$extraction_number/g" ./"$APP"-junest.sh
}
# Include all dependencies in the final AppImage
_include_all_dependencies() {
echo "◆ Automatic library checking should be more than enough. However..."
echo ""
read -r -ep " DO YOU WANT TO INCLUDE ALL DEPENDENCIES? THE PACKAGE MAY BE BLOATED (y,N) " yn
if echo "$yn" | grep -qi "^y"; then
sed -i 's/#rsync -av/rsync -av/g' ./"$APP"-junest.sh
fi
}
# Allow Nvidia check in the final AppImage
_enable_nvidia() {
read -r -ep "◆ DO YOU WANT TO ENABLE HARDWARE ACCELERATION FOR NVIDIA USERS? (y,N) " yn
if echo "$yn" | grep -qi "^y"; then
sed -i 's/NVIDIA_ON=0/NVIDIA_ON=1/g' ./"$APP"-junest.sh
fi
}
# Start configuration
STANDARD_CONFIGURATION_MSG="◆ Press \"y\" to finish using a standard configuration with the bare minimum for network and audio support, press \"N\" or leave blank instead to continue customization (RECOMMENDED).
"
_enable_chaoticaur() {
read -r -ep "◆ DO YOU WANT TO ENABLE CHAOTIC-AUR (y,N)? " yn
if echo "$yn" | grep -qi "^y"; then
sed -i 's/#_enable_chaoticaur/_enable_chaoticaur/g' ./"$APP"-junest.sh
fi
}
_enable_multilib() {
read -r -ep "◆ DO YOU WANT TO ENABLE MULTILIB WITH 32BIT LIBRARIES (y,N)? " yn
if echo "$yn" | grep -qi "^y"; then
sed -i 's/#_enable_multilib/_enable_multilib/g' ./"$APP"-junest.sh
fi
}
_enable_basicstuff() {
read -r -ep "◆ DO YOU WANT TO INCLUDE BINUTILS AND GZIP (y,N)? " yn
if echo "$yn" | grep -qi "^y"; then
sed -i 's/#BASICSTUFF/BASICSTUFF/g' ./"$APP"-junest.sh
fi
}
_enable_compilers(){
read -r -ep "◆ DO YOU WANT TO INCLUDE THE BASE-DEVEL PACKAGE AND COMPILE FROM AUR (y,N)? " yn
if echo "$yn" | grep -qi "^y"; then
sed -i 's/#COMPILERS/COMPILERS/g' ./"$APP"-junest.sh
sed -i '/-- gpg --keyserver/ s/^#*//' ./"$APP"-junest.sh
fi
}
_keywords_to_save_in_usr_bin() {
read -r -ep "◆ LIST BINARIES TO SAVE IN /usr/bin OR LEAVE BLANK $(echo -e '\n DO NOT ADD ASTERISKS, THEY ARE ALREADY PROVIDED IN THE SCRIPT\n:') " savebins
if [ -n "$savebins" ]; then
sed -i 's/#_savebins/_savebins/g' ./"$APP"-junest.sh
sed -i "s/SAVEBINSPLEASE/$savebins/g" ./"$APP"-junest.sh
fi
}
_keywords_to_save_in_usr_share() {
read -r -ep "◆ LIST DIRECTORIES TO SAVE IN /usr/share OR LEAVE BLANK $(echo -e '\n DO NOT ADD ASTERISKS, THEY ARE ALREADY PROVIDED IN THE SCRIPT\n:') " saveshare
if [ -n "$saveshare" ]; then
sed -i "s/SAVESHAREPLEASE/$saveshare/g" ./"$APP"-junest.sh
fi
}
_keywords_to_save_in_usr_lib() {
read -r -ep "◆ LIST LIBRARIES AND DIRECTORIES TO SAVE IN /usr/lib OR LEAVE BLANK $(echo -e '\n DO NOT ADD ASTERISKS, THEY ARE ALREADY PROVIDED IN THE SCRIPT\n:') " savelibs
if [ -n "$savelibs" ]; then
sed -i "s/SAVELIBSPLEASE/$savelibs/g" ./"$APP"-junest.sh
fi
}
_include_audio_keywords() {
read -r -ep "◆ DO YOU WISH TO ADD KEYWORDS IN /usr/lib TO ENABLE THE AUDIO (y,N)?" yn
if echo "$yn" | grep -qi "^y"; then
sed -i 's/^#lib_audio_keywords/lib_audio_keywords/g' ./"$APP"-junest.sh
fi
}
_include_internet_keywords() {
read -r -ep "◆ DO YOU WISH TO ADD KEYWORDS IN /use/lib TO USE NETWORK (y,N)? " yn
if echo "$yn" | grep -qi "^y"; then
sed -i 's/^#lib_browser_launcher/lib_browser_launcher/g' ./"$APP"-junest.sh
fi
}
_select_libraries() {
read -r -ep "◆ DO YOU WISH TO SELECT LIBRARIES TO SAVE (y,N)?" yn
if echo "$yn" | grep -qi "^y"; then
echo "$DIVIDING_LINE"
_keywords_to_save_in_usr_lib
echo "$DIVIDING_LINE"
_include_audio_keywords
echo "$DIVIDING_LINE"
_include_internet_keywords
fi
}
################################################################################
# USAGE
################################################################################
case "$1" in
'')
echo " ArchImage CLI requires an argument, run -h for more info.";;
'--help'|'-h')
if [ -t 1 ]; then _help; else _help | sed -e 's/\x1b\[[0-9;]*m//g'; fi
;;
'--build'|'-b')
while [ -n "$1" ]; do
cd "$SCRIPTDIR" || exit 1
if [ -z "$2" ]; then
echo " USAGE: archimage-cli -b [PROGRAM]"
exit 0
else
printf "%b" "$GETTING_STARTED_HEADER"
[ -f "$AMDATADIR"/archimage-betatester ] && printf "Developer Mode%b" "$DIVIDING_LINE" | _fit | sed -- 's/^ -/-/g'
echo "$GETTING_STARTED_MSG" | _fit
APP="$2"
wget -q "$ARCHIMAGE_REPO/NEW-junest.sh" -O "$APP"-junest.sh
sed -i "s#APP=SAMPLE#APP=$APP#g" "$APP"-junest.sh
_usr_bin_executable_name
echo "$DIVIDING_LINE"
_add_dependencies
echo "$DIVIDING_LINE"
_extraction_level
echo "$DIVIDING_LINE"
_include_all_dependencies
echo "$DIVIDING_LINE"
if curl --output /dev/null --silent --fail -r 0-0 https://aur.archlinux.org/packages/"$APP" 2> /dev/null; then
sed -i 's/#BASICSTUFF/BASICSTUFF/g' ./"$APP"-junest.sh # INSTALL BINUTILS AND GZIP
sed -i 's/#COMPILERS/COMPILERS/g' ./"$APP"-junest.sh # INSTALL BASE-DEVEL
sed -i '/-- gpg --keyserver/ s/^#*//' ./"$APP"-junest.sh # ENABLE AUR GPG VALIDATION
_enable_chaoticaur
echo "$DIVIDING_LINE"
fi
_enable_multilib
echo "$DIVIDING_LINE"
_enable_nvidia
echo "$DIVIDING_LINE"
echo "$STANDARD_CONFIGURATION_MSG" | _fit | sed "s/^/ /g; s/ ◆/◆/g"
read -r -ep " DO YOU WISH TO USE A STANDARD CONFIGURATION (y,N)? " yn
if echo "$yn" | grep -qi "^y"; then
sed -i 's/#lib_audio_keywords/lib_audio_keywords/g' ./"$APP"-junest.sh # SAVE KEYWORDS RELATED TO AUDIO
sed -i 's/^#lib_browser_launcher/lib_browser_launcher/g' ./"$APP"-junest.sh # ALLOW THE PROGRAM TO OPEN THE SYSTEM BROWSER
else
grep -q "^#BASICSTUFF" ./"$APP"-junest.sh && echo "$DIVIDING_LINE" && _enable_basicstuff
grep -q "^#COMPILERS" ./"$APP"-junest.sh && echo "$DIVIDING_LINE" && _enable_compilers
echo "$DIVIDING_LINE"
_keywords_to_save_in_usr_bin
echo "$DIVIDING_LINE"
_keywords_to_save_in_usr_share
echo "$DIVIDING_LINE"
_select_libraries
fi
fi
echo "$DIVIDING_LINE"
chmod a+x ./"$APP"-junest.sh
echo " THE SCRIPT IS READY, RUN IT TO CREATE AN APPIMAGE!"
echo ""
echo " SUGGESTIONS:"
echo ""
echo "◆ you can manually complete the function named \"_remove_more_bloatwares\" with a list of items to be deleted to avoid an excess in the size of the final AppImage" | _fit
echo "◆ in the footer of the script you can manually add TAG and REPO in case you want to host an updatable AppImage on github.com" | _fit
echo "◆ about the \"\$extraction_count\" variable, you can also set its value externally, for example, by running \"export extraction_count=2\"" | _fit
echo ""
exit 0
done
;;
'--devmode-disable')
mkdir -p "$AMDATADIR" && rm -f "$AMDATADIR"/archimage-betatester
;;
'--devmode-enable')
mkdir -p "$AMDATADIR" && touch "$AMDATADIR"/archimage-betatester && _betatester_message_on
;;
'--sync'|'-s')
_sync
;;
'--version'|'-v')
echo "$VERSION"
;;
*)
echo " Unknown option '$1', run -h for more info."
;;
esac