Skip to content

Commit f80bb21

Browse files
committed
Add script to create an AppImage
1 parent 79de0cb commit f80bb21

File tree

2 files changed

+191
-0
lines changed

2 files changed

+191
-0
lines changed

orchestra/support/mkappimage.sh

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
4+
5+
BOLD="\e[1m"
6+
RED="\e[31m"
7+
RESET="\e[0m"
8+
9+
function cleanup() {
10+
TEMPDIR="${APPDIR:-}"
11+
if [[ -n "$TEMPDIR" ]] && [[ -d "$TEMPDIR" ]]; then
12+
rm -Rf "$TEMPDIR"
13+
fi
14+
}
15+
trap cleanup ERR EXIT
16+
17+
function log() {
18+
echo -en "${BOLD}" >/dev/stderr
19+
echo -n '[+]' "$1" >/dev/stderr
20+
echo -e "${RESET}" >/dev/stderr
21+
}
22+
23+
function log_err() {
24+
echo -en "${BOLD}${RED}" >/dev/stderr
25+
echo -n '[!]' "$1" >/dev/stderr
26+
echo -e "${RESET}" >/dev/stderr
27+
}
28+
29+
function log2() {
30+
echo -en "${BOLD}" >/dev/stderr
31+
echo -n '[+]' "${1}" >/dev/stderr
32+
echo -en "${RESET} " >/dev/stderr
33+
echo "${2}"
34+
}
35+
36+
ORCHESTRA_DOTDIR=""
37+
APPIMAGETOOL="./appimagetool-x86_64.AppImage"
38+
APPIMAGE_NAME="orc_toolbox"
39+
APPIMAGE_TITLE="Orchestra Toolbox"
40+
APPIMAGE_DESC="A collection of tools from orchestra"
41+
OUTPUT="$APPIMAGE_NAME.AppImage"
42+
ICON="$SCRIPT_DIR/revng_logo.png"
43+
COMPRESS=0
44+
45+
function usage() {
46+
echo "Usage: $0 [-a path/to/appimagetool-x86_64.AppImage] [-o path/to/output.AppImage] [-d ORCHESTRA_DOTDIR] [-n 'AppImage name'] [-t 'AppImage title'] [-D 'AppImage description'] [-i path/to/icon.png] [-c]"
47+
echo "Packs an orchestra root directory into an AppImage."
48+
exit 1
49+
}
50+
51+
while getopts "a:o:d:n:t:D:i:ch" arg; do
52+
case "$arg" in
53+
a)
54+
APPIMAGETOOL="$OPTARG"
55+
;;
56+
c)
57+
COMPRESS=1
58+
;;
59+
d)
60+
ORCHESTRA_DOTDIR="$OPTARG"
61+
;;
62+
o)
63+
OUTPUT="$OPTARG"
64+
;;
65+
n)
66+
APPIMAGE_NAME="$OPTARG"
67+
;;
68+
t)
69+
APPIMAGE_TITLE="$OPTARG"
70+
;;
71+
D)
72+
APPIMAGE_DESC="$OPTARG"
73+
;;
74+
i)
75+
ICON="$OPTARG"
76+
;;
77+
*)
78+
usage
79+
;;
80+
esac
81+
done
82+
83+
if [[ ! -x "$APPIMAGETOOL" ]]; then
84+
log_err "appimagetool '$APPIMAGETOOL' does not exist or is not executable"
85+
log2 "Note:" "You can download appimagetool-x86_64.AppImage from https://github.com/AppImage/AppImageKit/releases"
86+
usage
87+
fi
88+
if [[ ! -f "$ICON" ]]; then
89+
log_err "Icon does not exist: '$ICON'"
90+
usage
91+
fi
92+
93+
log2 "Using appimagetool:" "$APPIMAGETOOL"
94+
95+
if [[ -z "$ORCHESTRA_DOTDIR" ]]; then
96+
ORC=("orc")
97+
else
98+
ORC=("orc" "--orchestra-dotdir" "$ORCHESTRA_DOTDIR")
99+
fi
100+
101+
ORC_ENV="$("${ORC[@]}" environment)"
102+
ORCHESTRA_ROOT=""
103+
eval "$(echo "$ORC_ENV" | grep '^export ORCHESTRA_ROOT=')"
104+
105+
log2 "Found orchestra root:" "$ORCHESTRA_ROOT"
106+
107+
log "Creating AppDir..."
108+
APPDIR="$(mktemp -d -p "$PWD" --suffix=".AppDir")"
109+
rmdir "$APPDIR"
110+
cp -a --reflink=auto "$ORCHESTRA_ROOT" "$APPDIR"
111+
112+
ICON_EXT="${ICON##*.}"
113+
cp "$ICON" "$APPDIR/$APPIMAGE_NAME.$ICON_EXT"
114+
115+
cat >"$APPDIR/$APPIMAGE_NAME.desktop" <<EOF
116+
[Desktop Entry]
117+
Version=1.0
118+
Type=Application
119+
Name=$APPIMAGE_TITLE
120+
Icon=$APPIMAGE_NAME
121+
Exec=AppRun
122+
Categories=Development
123+
EOF
124+
125+
mkdir -p "$APPDIR/usr/share/applications"
126+
cp "$APPDIR/$APPIMAGE_NAME.desktop" "$APPDIR/usr/share/applications/$APPIMAGE_NAME.desktop"
127+
128+
APPRUN="$APPDIR/AppRun"
129+
130+
{
131+
cat <<'EOF'
132+
#!/bin/bash
133+
set -euo pipefail
134+
135+
export ORCHESTRA_ROOT="$APPDIR"
136+
EOF
137+
138+
echo "$ORC_ENV" | grep -v '^export ORCHESTRA_ROOT=\|^export GIT_ASKPASS=\|^export SOURCE_ARCHIVES=\|^export BINARY_ARCHIVES=\|^export SOURCES_DIR=\|^export BUILDS_DIR=\|^export TMP_ROOTS='
139+
140+
cat <<'EOF'
141+
142+
ARG0_FNAME="$(basename "$ARGV0")"
143+
APPIMAGE_FNAME="$(basename "$APPIMAGE")"
144+
145+
if [[ "$ARG0_FNAME" != "$APPIMAGE_FNAME" ]]; then
146+
# User symlinked the AppImage to something else - behave like busybox
147+
CMD_ARG0="$ARG0_FNAME"
148+
CMD_ARGS=("$ARG0_FNAME" "$@")
149+
else
150+
# User is running ./foo.AppImage command
151+
if [[ "$#" == 0 ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
152+
EOF
153+
cat <<EOF
154+
echo "$APPIMAGE_TITLE - $APPIMAGE_DESC"
155+
EOF
156+
cat <<'EOF'
157+
echo "Usage: $ARGV0 [toolname] [args...]" >&2
158+
cho "You may also symlink the AppImage to a tool name to create a shortcut."
159+
exit 1
160+
fi
161+
CMD_ARG0="$1"
162+
CMD_ARGS=("$@")
163+
fi
164+
165+
if [[ -z "$CMD_ARG0" ]]; then
166+
echo "Invalid ARGV0" >&2
167+
exit 1
168+
fi
169+
170+
CMD_PATH="$(which "$CMD_ARG0" 2>/dev/null)"
171+
if [[ -z "$FORCE_RUN_OUTSIDE_APPIMAGE" ]] && { [[ -z "$CMD_PATH" ]] || [[ "$CMD_PATH" != "$APPDIR"* ]] }; then
172+
echo "Error: Could not find '$CMD_ARG0' inside AppImage! (found candidate: '$CMD_PATH')" >&2
173+
exit 2
174+
fi
175+
176+
exec -a "$CMD_ARG0" "${CMD_ARGS[@]}"
177+
178+
EOF
179+
} >"$APPRUN"
180+
181+
chmod +x "$APPRUN"
182+
183+
log "Packing AppImage"
184+
COMP_ARGS=()
185+
if [[ "$COMPRESS" != 0 ]]; then
186+
COMP_ARGS=(--comp xz)
187+
fi
188+
ARCH=x86_64 "$APPIMAGETOOL" -n "${COMP_ARGS[@]}" "$APPDIR" "$OUTPUT"
189+
190+
echo
191+
log2 "AppImage is ready at:" "$OUTPUT"

orchestra/support/revng_logo.png

37.9 KB
Loading

0 commit comments

Comments
 (0)