Skip to content

Commit 3447cc6

Browse files
authored
Merge pull request #779 from ivan-hc/dev
Create AppImages on the fly!
2 parents 74344e7 + c557e15 commit 3447cc6

File tree

7 files changed

+199
-250
lines changed

7 files changed

+199
-250
lines changed

APP-MANAGER

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
AMVERSION="7"
3+
AMVERSION="7.1"
44

55
# Determine main repository and branch
66
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,15 +1100,9 @@ https://github.com/ivan-hc/AM/assets/88724353/b6513e8a-17ab-4671-baf7-d86183d57c
11001100
#### Option One: "build AppImages on-the-fly"
11011101
This was one of the very first approaches used to create this project. Before I started building AppImage packages myself, they were first compiled just like using any AUR-helper.
11021102

1103-
The syntax seems simple, but you have to know what you're building.
1103+
From version 7.1, the installation script for the AppImages is used, with the only difference that it points only to the version, while a second script will be downloaded, published separately, at [github.com/ivan-hc/AM/tree/main/appimage-bulder-scripts](https://github.com/ivan-hc/AM/tree/main/appimage-bulder-scripts), which will have the task of assembling the AppImage in the directory on the fly "tmp", during the installation process. When the second script has created the .AppImage file, the first script will continue the installation treating the created AppImage as a ready-made one downloaded from the internet.
11041104

1105-
You'll need to decide what kind of AppImage you want to build on the fly, whether to include a custom AppRun, "libunionpreload", and detect system libraries.
1106-
1107-
It will be used as the Debian base, but you can manually modify the script to suit your needs.
1108-
1109-
In this example I'll create the script for Abiword with "AM" and I'll install it using AppMan:
1110-
1111-
https://github.com/ivan-hc/AM/assets/88724353/6ae38787-e0e5-4b63-b020-c89c1e975ddd
1105+
Fun fact, up until version 7, this option included a unique template that installed and assembled the AppImage on the fly (see [this video](https://github.com/ivan-hc/AM/assets/88724353/6ae38787-e0e5-4b63-b020-c89c1e975ddd)). This method has been replaced as it is too pretentious for a process, assembly, which may instead require many more steps, too many to be included in both an installation script and an update script (AM-updater).
11121106

11131107
#### Option Two: "Archives and other programs"
11141108
Option two is very similar to option zero. What changes is the number of questions, which allow you to customize both the application's .desktop file and the way a program should be extracted.

appimage-bulder-scripts/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
This directory will contain scripts for building AppImage packages on the fly, where required.
2+
3+
Each script must have the name of the corresponding installation script, but with the ".sh" extension. For example:
4+
```
5+
/appimage-bulder-scripts/x86_64/calibre.sh
6+
```
7+
is used by
8+
```
9+
/programs/x86_64/calibre
10+
```
11+
It is assumed that all of the work for these scripts will be done during the installation process, in the "tmp" directory, so the scripts posted here will need to be able to compile and drop the AppImage into the same "tmp" directory. The rest of the installation process will handle the created AppImage as if it had been normally downloaded from the internet ready-made.
12+
13+
If you are a user of my tools, consider using [AppImaGen](https://github.com/ivan-hc/AppImaGen).
14+
15+
Try not to use [Archimage](https://github.com/ivan-hc/ArchImage), as build times are longer and more resource intensive.
16+
17+
If your AppImage creation script requires specific dependencies, please let me know with a PR.
18+
19+
TIP, creating AppImage on the fly can take time and resources, depending on the complexity of the program being compiled. It is highly suggested to publish the AppImages to a repository, using Github Actions, [as I do](https://github.com/ivan-hc#my-appimage-packages).
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
3+
APP=calibre
4+
5+
# DOWNLOADING THE DEPENDENCES
6+
if test -f ./appimagetool; then
7+
echo " appimagetool already exists" 1> /dev/null
8+
else
9+
echo " Downloading appimagetool..."
10+
wget -q "$(wget -q https://api.github.com/repos/probonopd/go-appimage/releases -O - | sed 's/"/ /g; s/ /\n/g' | grep -o 'https.*continuous.*tool.*86_64.*mage$')" -O appimagetool
11+
fi
12+
chmod a+x ./appimagetool
13+
14+
#CREATE THE APPDIR
15+
mkdir -p "$APP".AppDir/
16+
17+
# DOWNLOAD THE ARCHIVE
18+
DOWNLOAD_URL=$(curl -Ls https://api.github.com/repos/kovidgoyal/calibre/releases | sed 's/[()",{} ]/\n/g' | grep -v "i386\|i686\|aarch64\|arm64\|armv7l" | grep -i "http.*x86_64.txz$" | head -1)
19+
if wget --version | head -1 | grep -q ' 1.'; then
20+
wget -q --no-verbose --show-progress --progress=bar "$DOWNLOAD_URL"
21+
else
22+
wget "$DOWNLOAD_URL"
23+
fi
24+
25+
# EXTRACT THE ARCHIVE
26+
tar fx ./*txz* -C ./"$APP".AppDir/
27+
28+
# CREATE THE LAUNCHER
29+
cat >> ./"$APP".AppDir/"$APP".desktop << 'EOF'
30+
[Desktop Entry]
31+
Categories=Office;
32+
Comment[en_US]=E-book library management: Convert, view, share, catalogue all your e-books
33+
Comment=E-book library management: Convert, view, share, catalogue all your e-books
34+
Exec=AppRun
35+
GenericName[en_US]=E-book library management
36+
GenericName=E-book library management
37+
Icon=calibre
38+
MimeType=application/vnd.openxmlformats-officedocument.wordprocessingml.document;image/vnd.djvu;application/x-mobi8-ebook;application/x-cbr;text/fb2+xml;application/pdf;application/x-cbc;application/vnd.ms-word.document.macroenabled.12;text/rtf;application/epub+zip;application/x-cbz;text/plain;application/x-sony-bbeb;application/oebps-package+xml;application/x-cb7;application/x-mobipocket-ebook;application/ereader;text/html;text/x-markdown;application/xhtml+xml;application/vnd.oasis.opendocument.text;application/x-mobipocket-subscription;x-scheme-handler/calibre;
39+
Name=calibre
40+
Type=Application
41+
X-DBUS-ServiceName=
42+
X-DBUS-StartupType=
43+
X-KDE-SubstituteUID=false
44+
X-KDE-Username=
45+
EOF
46+
47+
# ADD THE ICON AT THE ROOT OF THA APPDIR
48+
cp ./"$APP".AppDir/resources/content-server/calibre.png ./"$APP".AppDir/calibre.png
49+
50+
# CREATE THE APPRUN
51+
cat >> ./"$APP".AppDir/AppRun << 'EOF'
52+
#!/bin/sh
53+
HERE="$(dirname "$(readlink -f "${0}")")"
54+
exec "${HERE}"/calibre "$@"
55+
EOF
56+
chmod a+x ./"$APP".AppDir/AppRun
57+
58+
# CONVERT THE APPDIR TO AN APPIMAGE
59+
echo "\nConverting the AppDir to an AppImage...\n"
60+
ARCH=x86_64 VERSION=$(./appimagetool -v | grep -o '[[:digit:]]*') ./appimagetool -s ./"$APP".AppDir 2>&1 | grep "Architecture\|Creating\|====\|Exportable"

modules/install.am

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,40 +132,51 @@ function _install_arg() {
132132
# Check if the installation script contain a keyword related to a missing dependence
133133
if grep -q 'ar.*x .*\.deb' ./"$arg"; then
134134
if ! command -v ar 1>/dev/null; then
135-
echo ' 💀 ERROR: YOU CANNOT INSTALL '"$(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]')"' WITHOUT INSTALLING "BINUTILS"!'; return 0
135+
echo " 💀 ERROR: you cannot install \"$arg\" without installing \"binutils\""; return 0
136136
fi
137-
fi
138-
if grep -q 'ffwa-' ./"$arg"; then
137+
elif grep -q 'ffwa-' ./"$arg"; then
139138
ffbrowser=$(find ${PATH//:/ } -maxdepth 1 -name "firefox*" | sort | head -1)
140139
if [[ -z "$ffbrowser" ]]; then
141-
echo ' 💀 ERROR: YOU CANNOT INSTALL '"$(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]')"' WITHOUT INSTALLING "FIREFOX"!'; return 0
140+
echo " 💀 ERROR: you cannot install \"$arg\" without installing \"firefox\""; return 0
142141
else
143142
sed -i 's#firefox --class#'"$(echo "$ffbrowser" | xargs -L 1 basename)"' --class#g' ./"$arg"
144143
fi
145-
fi
146-
if grep -q 'http.*\.tar' ./"$arg"; then
144+
elif grep -q 'http.*\.tar' ./"$arg"; then
147145
if ! command -v tar 1>/dev/null; then
148-
echo ' 💀 ERROR: YOU CANNOT INSTALL '"$(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]')"' WITHOUT INSTALLING "TAR"!'; return 0
146+
echo " 💀 ERROR: you cannot install \"$arg\" without installing \"tar\""; return 0
149147
fi
150-
fi
151-
if grep -q 'http.*\.zip' ./"$arg"; then
148+
elif grep -q 'http.*\.zip' ./"$arg"; then
152149
if ! command -v unzip 1>/dev/null; then
153-
echo ' 💀 ERROR: YOU CANNOT INSTALL '"$(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]')"' WITHOUT INSTALLING "UNZIP"!'; return 0
150+
echo " 💀 ERROR: you cannot install \"$arg\" without installing \"unzip\""; return 0
154151
fi
155-
fi
156-
if grep -q '^wget "$version.zsync"' ./"$arg"; then
152+
elif grep -q '^wget "$version.zsync"' ./"$arg"; then
157153
if ! command -v zsync 1>/dev/null; then
158154
optzsync=$(grep -F 'if test -f /opt/$APP/*.zsync' ./"$arg" | wc -l)
159155
if [ "$optzsync" == 0 ]; then
160-
echo ' 💀 ERROR: YOU CANNOT INSTALL '"$(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]')"' WITHOUT INSTALLING "ZSYNC"!'; return 0
156+
echo " 💀 ERROR: you cannot install \"$arg\" without installing \"zsync\""; return 0
161157
else
162-
echo -e ' ⚠️ WARNING: '"$(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]')"' MAY NOT BE UPDATABLE WITHOUT "ZSYNC".\n\n THE APP WILL STILL BE INSTALLED, BUT INSTALLING "ZSYNC" IS RECOMMENDED!\n'
158+
echo -e " ⚠️ WARNING: \"$arg\" may not be updatable without \"zsync\".\n\n The app will still be installed, but installing \"zsync\" is recommended! \n"
163159
fi
164160
fi
161+
elif grep -q 'appimage-bulder-scripts' ./"$arg"; then
162+
appimage_build_deps="ar convert glib-compile-schemas tar unzip"
163+
for name in $appimage_build_deps; do
164+
if ! command -v "$name" &>/dev/null; then
165+
if [ "$name" == "ar" ]; then
166+
echo " 💀 ERROR: cannot create \"$arg\" without \"binutils\""; return 0
167+
elif [ "$name" == "convert" ]; then
168+
echo " 💀 ERROR: cannot create \"$arg\" without \"$name\" (from \"imagemagick\")"; return 0
169+
else
170+
echo " 💀 ERROR: cannot create \"$arg\" without \"$name\""; return 0
171+
fi
172+
fi
173+
done
165174
fi
166175
# Check if you are installing an app or a library
167-
echo -e "$(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]'): starting installation script" &&
168-
if grep -q "/usr/local/lib" ./"$arg"; then
176+
echo -e "$(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]'): starting installation script"
177+
if grep -q 'appimage-bulder-scripts' ./"$arg"; then
178+
echo -e "\n This script will create an AppImage on the fly, please wait..."
179+
elif grep -q "/usr/local/lib" ./"$arg"; then
169180
echo -e '\n ⚠️ This script installs a system library in /usr/local/lib, cancel it if:\n'
170181
echo ' - it is already installed in the system;'
171182
echo -e ' - its already present in your repositories (so install it from there).\n'

modules/template.am

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,21 @@ while [ -n "$1" ]; do
333333
case $arg in
334334
*)
335335
cd "$SCRIPTDIR" || return
336-
echo "##############################################################"; echo ""
337-
echo -e " Create a template for \"$arg\"\n " | tr '[:lower:]' '[:upper:]'
338-
echo "--------------------------------------------------------------"; echo ""
339-
echo -e " EACH MODEL IS BASED ON A DIFFERENT METHOD OF BUILDING/UPDATING THE PROGRAM.\n"
340-
echo -e " PLEASE, SELECT A TEMPLATE FOR \"$(echo "$arg" | tr '[:lower:]' '[:upper:]')\": \n"
336+
echo "##############################################################"
337+
echo ""
338+
echo " Create a template for \"$arg\"" | tr '[:lower:]' '[:upper:]'
339+
echo ""
340+
echo "--------------------------------------------------------------"
341+
echo ""
342+
echo " EACH MODEL IS BASED ON A DIFFERENT METHOD OF BUILDING/UPDATING THE PROGRAM."
343+
echo ""
344+
echo " PLEASE, SELECT A TEMPLATE FOR \"$(echo "$arg" | tr '[:lower:]' '[:upper:]')\":"
345+
echo ""
341346
echo " 0) APPIMAGE, FROM ANY WEBSITE (BETTER IF FROM GITHUB.COM)"
342-
echo " 1) APPIMAGE, BUILD YOUR OWN WITH PKG2APPIMAGE"
347+
echo " 1) APPIMAGE ON-THE-FLY, USING A DEDICATED SCRIPT"
343348
echo " 2) ANY ARCHIVE/BINARY/SCRIPT FROM ANY WEBSITE"
344-
echo -e ' 3) WEBAPP BASED ON A FIREFOX PROFILE (REQUIRES "FIREFOX" IN $PATH)"\n'
349+
echo ' 3) WEBAPP BASED ON A FIREFOX PROFILE (REQUIRES "FIREFOX" IN $PATH)'
350+
echo ""
345351
read -r -p " WHAT KIND OF PROGRAM DO YOU WANT TO WRITE A SCRIPT FOR? : " templatetype
346352
case "$templatetype" in
347353

@@ -370,62 +376,22 @@ while [ -n "$1" ]; do
370376

371377
1) # CREATE AN APPIMAGE ON-THE-FLY
372378
mkdir -p ./am-scripts ./am-scripts/"$arch" ./am-scripts/portable-linux-apps.github.io/apps ./am-scripts/portable-linux-apps.github.io/icons
373-
# CUSTOMEZE THE APPRUN, THE CORE SCRIPT OF THE APPIMAGE
374-
read -r -p ' Do you wish to use a custom AppRun script (y,N)?' yn
375-
case $yn in
376-
'Y'|'y')
377-
# DOWNLOAD THE TEMPLATE AND CONVERT THE ARGUMENT INTO A COMMAND
378-
wget -q "$AMREPO"/templates/AM-SAMPLE-pkg2appimage-custom -O ./am-scripts/"$arch"/"$arg" &&
379-
sed -i "s/SAMPLE/$arg/g" ./am-scripts/"$arch"/"$arg" &&
380-
# LIBUNIONPRELOAD
381-
read -r -p ' Do you wish to add libunionpreload (y,N)?' yn
382-
case $yn in
383-
'Y'|'y')
384-
sed -i 's/#export LD_PRELOAD/export LD_PRELOAD/g' ./am-scripts/"$arch"/"$arg"
385-
sed -i 's/#chmod/chmod/g' ./am-scripts/"$arch"/"$arg"
386-
sed -i 's/#mv ./mv ./g' ./am-scripts/"$arch"/"$arg"
387-
sed -i 's/#wget/wget/g' ./am-scripts/"$arch"/"$arg"
388-
;;
389-
'N'|'n'|*)
390-
;;
391-
esac
392-
# SYSTEM LIBRARIES
393-
read -r -p ' Do you wish to include system libraries (Y,n)?' yn
394-
case $yn in
395-
'N'|'n')
396-
sed -i 's/##export LD_LIBRARY_PATH/export LD_LIBRARY_PATH/g' ./am-scripts/"$arch"/"$arg"
397-
;;
398-
'Y'|'y'|*)
399-
sed -i 's/#export LD_LIBRARY_PATH/export LD_LIBRARY_PATH/g' ./am-scripts/"$arch"/"$arg"
400-
;;
401-
esac
402-
# BINARY PATH
403-
read -r -p ' Do you wish to specify the binary`s path manually (y,N)?' yn
404-
case $yn in
405-
'Y'|'y')
406-
read -r -ep " ◆ ADD THE PATH (EXAMPLE \"/usr/lib.../$arg\") $(echo -e '\n: ')" RESPONSE
407-
case "$RESPONSE" in
408-
*)
409-
sed -i "s/#exec/exec/g" ./am-scripts/"$arch"/"$arg"
410-
sed -i "s#CUSTOMPATH#$RESPONSE#g" ./am-scripts/"$arch"/"$arg"
411-
esac
412-
;;
413-
'N'|'n'|*)
414-
sed -i "s/##exec/exec/g" ./am-scripts/"$arch"/"$arg"
415-
;;
416-
esac
417-
;;
418-
'N'|'n'|*)
419-
# DOWNLOAD THE TEMPLATE AND CONVERT THE ARGUMENT INTO A COMMAND
420-
wget -q "$AMREPO"/templates/AM-SAMPLE-pkg2appimage -O ./am-scripts/"$arch"/"$arg" &&
421-
sed -i "s/SAMPLE/$arg/g" ./am-scripts/"$arch"/"$arg"
422-
;;
379+
# DOWNLOAD THE TEMPLATE AND CONVERT THE ARGUMENT INTO A COMMAND
380+
wget -q "$AMREPO"/templates/AM-SAMPLE-AppImage -O ./am-scripts/"$arch"/"$arg"
381+
sed -i "s/SAMPLE/$arg/g" ./am-scripts/"$arch"/"$arg"
382+
383+
_template_if_hosted_elsewhere
384+
385+
# ADD A LINEAR DOWNLOAD URL
386+
read -r -ep " ◆ ADD A LINEAR DOWNLOAD URL FOR THE SCRIPT OR LEAVE BLANK $(echo -e '\n : ')" dlurl
387+
case "$dlurl" in
388+
'')
389+
sed -i 's#wget "$version"#wget "'"$AMREPO"'/appimage-bulder-scripts/'"$arch"'/$APP.sh" \&\& chmod a+x "$APP".sh \&\& ./"$APP".sh#g' ./am-scripts/"$arch"/"$arg"
390+
;;
391+
*)
392+
sed -i 's#wget "$version"#wget "'"$dlurl"'" -O '"$arg"'.sh && chmod '"$arg"'.sh && ./'"$arg"'.sh#g' ./am-scripts/"$arch"/"$arg"
393+
;;
423394
esac
424-
# CREATE A WEBPAGE FOR https://portable-linux-apps.github.io CONTAINING ALL THE INFO ABOUT THIS APP
425-
echo "# $(echo "$arg" | tr '[:lower:]' '[:upper:]')" >> ./am-scripts/portable-linux-apps.github.io/apps/"$arg".md
426-
echo -e "\n $COMMENT\n\n SITE: \n\n | [Applications](https://portable-linux-apps.github.io/apps.html) | [Home](https://portable-linux-apps.github.io)\n | --- | --- |" >> ./am-scripts/portable-linux-apps.github.io/apps/"$arg".md &&
427-
# CREATE A NEW LINE FOR THE APPLICATION'S LIST
428-
echo "$arg : $COMMENT" >> ./am-scripts/list; echo ""
429395
# END OF THIS FUNCTION
430396
echo -e "\n All files are saved in $SCRIPTDIR/am-scripts\n"
431397
;;

0 commit comments

Comments
 (0)