-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathappimage-install
executable file
·175 lines (152 loc) · 4.04 KB
/
appimage-install
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
#!/usr/bin/env bash
#
# NAME
#
# appimage-install - install AppImages locally
#
# SYNOPSIS
#
# appimage-install [-n <name>] [-b <binary>] [-a <appdir>] <appimage>
#
# DESCRIPTION
#
# Although AppImages are very convenient, it is even better
# if they can be installed as usual applications. This script is
# a helper script that does exactly that. It extracts the AppImage to
# a sensible directory and creates an executable and a .desktop file
# that can be used to run the AppImage.
#
# OPTIONS
#
# -n <name> name of the AppImage (used in the "Name" field
# in the .desktop file to be created)
# -b <binary> path to the binary, e.g., /usr/local/bin/name
# -a <appdir> squashfs-root is extracted to this directory
#
# EXAMPLES
#
# o Install from a local AppImage
# appimage-install -n "Firefox Nightly" -b firefox-nightly -a /opt/Mozilla/Firefox firefox-nightly-x86_64.AppImage
#
# o Install from a URL
# appimage-install https://www.slsknet.org/SoulseekQt/Linux/SoulseekQt-2018-1-30-64bit-appimage.tgz
#
# DEPENDENCIES
#
# readlink, GNU coreutils
#
# SEE ALSO
#
# Zap, an AppImage package manager that is more feature rich
# <https://github.com/srevinsaju/zap>
#
set -e
set -o pipefail
while getopts ":hn:b:a:" opt
do
case "$opt" in
h) echo >&2 "usage: ${0##*/} [-n name] [-b binary] [-a appdir] <appimage>"
exit ;;
n) name="$OPTARG" ;;
b) bin="$OPTARG" ;;
a) appdir="$OPTARG" ;;
:) echo >&2 "${0##*/}: -$OPTARG requires an argument"
exit 1 ;;
\?) echo >&2 "${0##*/}: -$OPTARG is not a valid option"
exit 1 ;;
esac
done
shift $(( OPTIND - 1 ))
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir" >/dev/null 2>&1' EXIT
trap 'exit 2' HUP INT QUIT TERM
# --- Procure AppImage ---
if [[ "$1" =~ (^http|^www\.) ]]
then
cd "$tmpdir"
wget --no-config --progress=bar "$1"
# Extract archives if any.
tar=$(find -type f -name '*.tgz' -o -name '*.gz' -o -name '*.tar' | head -n 1)
zip=$(find -type f -name '*.zip' | head -n 1)
if [[ "$tar" ]]
then
# We need GNU tar for this.
if tar atvf "$tar" &>/dev/null
then
tar axvf "$tar"
fi
elif [[ "$zip" ]]
then
unzip "$zip"
fi
# Find the AppImage and set it as the only argument.
set -- "$(find -type f -name '*.AppImage' | head -n 1)"
elif [[ -f "$1" ]]
then
ln -s "$(readlink -e -n -- "$1")" "$tmpdir"
cd "$tmpdir"
else
echo >&2 "${0##*/}: '$1' is not a valid file or a URL"
exit 1
fi
# --- Metadata ---
stem="${1##*/}"
if [[ -z "$name" ]]
then
name="${stem%.AppImage}"
read -ep "Name [$name]: " -i "$name" name
fi
if [[ -z "$bin" ]]
then
bin="/usr/local/bin/$name"
read -ep "Binary [$bin]: " -i "$bin" bin
fi
if [[ -z "$appdir" ]]
then
appdir="/opt/$name"
read -ep "Directory [$appdir]: " -i "$appdir" appdir
fi
# --- AppRun to /usr/local/bin ---
chmod +x "$stem"
"./$stem" --appimage-extract
rm -rf "$appdir"
# We need to explicitly give read/executable permissions to
# all users, as, by default, the files are restricted to just
# root.
chmod -R a+rX squashfs-root
cp -r squashfs-root "$appdir"
cat >"$bin" <<EOF
#!/bin/sh
exec "$appdir/AppRun" "\$@"
EOF
chmod a+rx "$bin"
echo >&2 "${0##*/}: AppRun script at '$bin'"
# --- Icons ---
icon=$(find "$appdir" \
-maxdepth 1 \
-type f \
-name '*.svg' -o \
-name '*.png' -o \
-name '*.gif' | head -n 1)
if [[ "$icon" ]]
then
mkdir -p "/usr/local/share/icons"
cp -f "$icon" "/usr/local/share/icons/$name.${icon##*.}"
echo >&2 "${0##*/}: icon at '$icon'"
else
echo >&2 "${0##*/}: no icon file found"
fi
# --- .desktop file ---
mkdir -p "/usr/local/share/applications"
desktop="/usr/local/share/applications/${bin##*/}.desktop"
cat >"$desktop" <<EOF
[Desktop Entry]
Version=1.0
Type=Application
Name=$name
Icon=$name
Comment=$name
Exec=$bin %f
TryExec=$bin
EOF
echo >&2 "${0##*/}: .desktop file at '$desktop'"