-
Notifications
You must be signed in to change notification settings - Fork 2
/
prep-appimage
executable file
·133 lines (119 loc) · 2.98 KB
/
prep-appimage
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
#!/bin/bash
APPNAME=""
APPVERSION=""
APPDIR=""
BINARIES=""
NBINARIES=0
ICONDIR="icon"
usage()
{
echo "Usage: $0 -a APPNAME -v APPVERSION [-d DESKTOP file] [-m META file] [-i ICONDIR]"
echo " DESKTOP file defaults to ci/appimage/com.projectaten.APPNAME.desktop"
echo " META file defaults to ci/appimage/com.projectaten.APPNAME.appdata.xml"
echo " ICONDIR to search defaults to icon/"
exit 1
}
# Parse options
while getopts ":a:v:d:m:i:b:" opt
do
case "${opt}" in
a)
APPNAME=${OPTARG}
echo "Application name set to '${APPNAME}'"
;;
b)
BINARIES[NBINARIES]=${OPTARG}
echo "Added binary '${BINARIES[NBINARIES]} to the list of targets"
let NBINARIES=NBINARIES+1
;;
v)
APPVERSION=${OPTARG}
echo "Application version set to '${APPVERSION}'"
;;
d)
DESKTOP=${OPTARG}
echo "Desktop file is '${DESKTOP}'"
;;
m)
META=${OPTARG}
echo "Desktop metafile is '${META}'"
;;
i)
ICONDIR=${OPTARG}
echo "Directory to search for icons is '${ICONDIR}'"
;;
*)
usage
;;
esac
done
# Check for valid arguments
if [ "x$APPNAME" = "x" ]; then echo "Error: A valid APPNAME must be provided."; exit 1; fi
if [ "x$APPVERSION" = "x" ]; then echo "Error: A valid APPVERSION must be provided."; exit 1; fi
if [ "${NBINARIES}" -eq "0" ]; then echo "Error: At least one binary must be specified."; exit 1; fi
# Set dependent variables
APPDIR=${APPNAME}-${APPVERSION}.AppDir
if [ "x$DESKTOP" = "x" ]; then DESKTOP="ci/appimage/com.projectaten.${APPNAME}.desktop"; fi
if [ "x$META" = "x" ]; then META="ci/appimage/com.projectaten.${APPNAME}.appdata.xml"; fi
# Report settings
echo "APPDIR=${APPDIR}"
echo "DESKTOP=${DESKTOP}"
echo "META=${META}"
# Enable erroring
set -e
# Create basic AppDir structure
rm -rf ${APPDIR}
mkdir -p ${APPDIR}/usr/bin
mkdir -p ${APPDIR}/usr/lib
mkdir -p ${APPDIR}/usr/share/applications
mkdir -p ${APPDIR}/usr/share/metainfo
mkdir -p ${APPDIR}/usr/share/icons/hicolor
# Copy in binaries
echo -e "\nCopying binaries...\n"
for b in ${BINARIES[@]}
do
if [ ! -e $b ]
then
echo "Error: Binary '$b' not found."
exit 1
fi
cp -v $b ${APPDIR}/usr/bin
done
# Copy desktop file
echo -e "\nCopying desktop file...\n"
if [ ! -e $DESKTOP ]
then
echo "Error: Desktop file '$DESKTOP' does not exist."
exit 1
fi
cp -v $DESKTOP ${APPDIR}/usr/share/applications
# Copy metainfo file
echo -e "\nCopying desktop metafile...\n"
if [ ! -e $META ]
then
echo "Error: Metainfo file '$META' does not exist."
exit 1
fi
cp -v $META ${APPDIR}/usr/share/metainfo
# Search for and copy icons
echo -e "\nCopying icons...\n"
NFOUND=0
for i in 64 128 256 512
do
icon=${ICONDIR}/icon-${i}x${i}.png
if [ -e "${icon}" ]
then
mkdir -p ${APPDIR}/usr/share/icons/hicolor/${i}x${i}
cp -v ${icon} ${APPDIR}/usr/share/icons/hicolor/${i}x${i}/${APPNAME}.png
let NFOUND=NFOUND+1
fi
done
# If no specific icons were found, try the default name
if [ "${NFOUND}" -eq "0" ]
then
icon="${ICONDIR}/${APPNAME}.png"
if [ -e "${icon}" ]
then
cp -v ${icon} ${APPDIR}
fi
fi