-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patharchimage-cli
More file actions
320 lines (255 loc) · 10.4 KB
/
archimage-cli
File metadata and controls
320 lines (255 loc) · 10.4 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/usr/bin/env bash
VERSION="5.0"
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"
# Shell completion in zsh requires editing the main configuration file
if [ -f "${ZDOTDIR:-$HOME}"/.zshrc ] && echo "$SHELL" | grep -q "zsh"; then
if ! grep -q "$completion_file" "${ZDOTDIR:-$HOME}"/.zshrc && [ ! -f "$AMDATADIR"/zsh-completion-off ]; then
printf $"Zsh completion requires editing the main configuration file, but it may cause problems.\nSee https://github.com/ivan-hc/AM/issues/1843\n" | _fit
read -r -p $"Want to proceed anyway? (y,N)" response
if echo "$response" | grep -qi "^y"; then
cat <<-HEREDOC >> "${ZDOTDIR:-$HOME}"/.zshrc
autoload bashcompinit
bashcompinit
source "$completion_file"
HEREDOC
else
touch "$AMDATADIR"/zsh-completion-off
fi
fi
fi
if [ ! -f "$AMDATADIR"/zsh-completion-off ]; then
echo $"Shell completion has been enabled!"
fi
# Shell completion in fish
if [ -d "$DATADIR"/fish/completions ] || [ -d /etc/fish/completions ] || [ -d /usr/share/fish/completions ]; then
command -v fish 1>/dev/null && [ ! -f "$CONFIGDIR"/fish/completions/archimage-cli.fish ] && mkdir -p "$CONFIGDIR"/fish/completions && echo "complete -c archimage-cli -f -a \"(cat $DATADIR/AM/list 2>/dev/null)\"" > "$CONFIGDIR"/fish/completions/archimage-cli.fish
fi
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."
# Choose between a JuNest-based Archimage or an Anylinux ShaRun-based AppImage
_choose_archimage_or_sharun() {
echo "$DIVIDING_LINE"
echo "Since version 5, you can choose between two types of AppImages:" | _fit
echo ""
printf "1. ${Green}Archimage\033[0m (default), a JuNest-based AppImage, contains an Arch Linux container that, using BubbleWrap and Proot (depending on restrictions), allows you to run the latest programs on older distributions, thanks to its isolation from the host system, with which it shares few resources." | _fit
echo ""
echo "Archimage is the method that gives this project its name." | _fit
echo "https://github.com/ivan-hc/ArchImage" | _fit
echo ""
printf "2. ${Gold}Anylinux\033[0m, a SHARUN-based AppImage. JuNest is used only to provide a base Arch Linux system from which all files and directories will be extracted to obtain an AppImage capable of running on 2010 distributions. It also supports DWARFS for compression, allowing it to contain a huge amount of files in a very small space." | _fit
echo ""
echo "Visit the Anylinux repository to learn more." | _fit
echo "https://github.com/pkgforge-dev/Anylinux-AppImages" | _fit
echo ""
echo "Press 2 for Anylinux, 1 or blank for Archimage, or any other key to abort." | _fit
echo ""
read -r -ep "◆ WHAT KIND OF APPIMAGE YOU WANT TO BUILD? " choose
case $choose in
''|"1")
wget -q "$ARCHIMAGE_REPO/NEW-junest.sh" -O "$APP"-junest.sh
SCRIPT="$APP-junest.sh"
;;
"2")
wget -q "$ARCHIMAGE_REPO/NEW-anylinux.sh" -O "$APP"-anylinux.sh
SCRIPT="$APP-anylinux.sh"
;;
*)
echo "$DIVIDING_LINE"
echo " UNKNOWN OPTION: PROCESS ABORTED!"
echo "$DIVIDING_LINE"
exit 0
;;
esac
}
# 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" ./"$SCRIPT"
}
# Add optional dependencies
_add_dependencies() {
echo "$DIVIDING_LINE"
read -r -ep "◆ ADD (OPTIONAL) DEPENDENCIES OR LEAVE BLANK: " RESPONSE
[ -n "$RESPONSE" ] && sed -i "s/^DEPENDENCES=\"\"/DEPENDENCES=\"$RESPONSE\"/g" ./"$SCRIPT"
}
_enable_chaoticaur() {
echo "$DIVIDING_LINE"
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' ./"$SCRIPT"
fi
}
_enable_multilib() {
echo "$DIVIDING_LINE"
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' ./"$SCRIPT"
fi
}
# Allow Nvidia check in the final AppImage
_enable_nvidia() {
echo "$DIVIDING_LINE"
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' ./"$SCRIPT"
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"
_choose_archimage_or_sharun
sed -i "s#APP=SAMPLE#APP=$APP#g" "$SCRIPT"
_usr_bin_executable_name
_add_dependencies
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' ./"$SCRIPT" # INSTALL BINUTILS AND GZIP
sed -i 's/#COMPILERS/COMPILERS/g' ./"$SCRIPT" # INSTALL BASE-DEVEL
sed -i '/-- gpg --keyserver/ s/^#*//' ./"$SCRIPT" # ENABLE AUR GPG VALIDATION
_enable_chaoticaur
fi
_enable_multilib
if grep -q "NVIDIA_ON" ./"$SCRIPT"; then
_enable_nvidia
fi
fi
echo "$DIVIDING_LINE"
chmod a+x ./"$SCRIPT"
echo " THE SCRIPT IS READY, RUN IT INTO AN EMPTY DIRECTORY TO CREATE AN APPIMAGE!"
echo "$DIVIDING_LINE"
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