-
Notifications
You must be signed in to change notification settings - Fork 10
/
appimage-desktop-entry.sh
executable file
·60 lines (46 loc) · 1.15 KB
/
appimage-desktop-entry.sh
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
#!/bin/bash
APPIMAGE_PATH=$1
if [ -z "$APPIMAGE_PATH" ]; then
echo "Missing argument: appimage"
exit 1
fi
if [ ! -f "$APPIMAGE_PATH" ]; then
echo "File not found:" $APPIMAGE_PATH
exit 1
fi
APPIMAGE_FULLPATH=$(readlink -e "$APPIMAGE_PATH")
APPIMAGE_FILENAME=$(basename "$APPIMAGE_PATH")
APP_NAME="${APPIMAGE_FILENAME%.*}"
rm -rf /tmp/squashfs-root/
cd /tmp/
"$APPIMAGE_FULLPATH" --appimage-extract
cd /tmp/squashfs-root/
echo "Choose icon: "
FILENAMES=($(ls -d *.png))
i=1
for filename in ${FILENAMES[*]}
do
printf " %d) %s\n" $i $filename
i=$(expr $i + 1)
done
read SELECTED_INDEX
ICON_SRC=${FILENAMES[$(expr $SELECTED_INDEX - 1)]}
ICON_EXT="${ICON_SRC##*.}"
ICON_DST="${HOME}/.local/share/icons/$APP_NAME.$ICON_EXT"
cp "$ICON_SRC" "$ICON_DST"
DESKTOP_ENTRY_PATH="${HOME}/.local/share/applications/$APP_NAME.desktop"
APPIMAGE_FULLPATH_ESC_SPACES="${APPIMAGE_FULLPATH// /\\ }"
cat <<EOT > "$DESKTOP_ENTRY_PATH"
[Desktop Entry]
Name=$APP_NAME
Exec=$APPIMAGE_FULLPATH_ESC_SPACES
Icon=$ICON_DST
Type=Application
Terminal=false
EOT
echo "Created";
if [ "$2" == "--remove" ]; then
rm $ICON_DST
rm $DESKTOP_ENTRY_PATH
echo "Removed."
fi