-
Notifications
You must be signed in to change notification settings - Fork 8
/
03-create-deb.sh
212 lines (185 loc) · 5.01 KB
/
03-create-deb.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#
# Create folder structure
#
PKG_NAME=rport-guacamole
PKG_ROOT=/pkg
test -e $PKG_ROOT && rm -rf $PKG_ROOT
mkdir -p ${PKG_ROOT}/opt
cp -a /opt/rport-guacamole ${PKG_ROOT}/opt
mkdir -p ${PKG_ROOT}/lib/systemd/system
mkdir -p ${PKG_ROOT}/etc/default/
mkdir -p ${PKG_ROOT}/opt/rport-guacamole/tmp
mkdir -p ${PKG_ROOT}/usr/share/doc/${PKG_NAME}
#
# Fix file modes
#
find ${PKG_ROOT} -type d -exec chmod 0755 {} \;
find ${PKG_ROOT} -type f -exec chmod 0644 {} \;
chmod 0755 ${PKG_ROOT}/opt/rport-guacamole/sbin/guacd
if stat ${PKG_ROOT}/opt/rport-guacamole/sbin/guacd | grep "Access.*0755"; then
true
else
echo "File permission not set"
ls -la ${PKG_ROOT}/opt/rport-guacamole/sbin/
ls -la ${PKG_ROOT}/opt/rport-guacamole/lib/
false
fi
find ${PKG_ROOT} -type f -name "*.la" -exec rm {} \;
find ${PKG_ROOT} -type f -name "*.so*" -exec strip {} \;
strip ${PKG_ROOT}/opt/rport-guacamole/sbin/guacd
#
# Create a systemd service file
#
cat <<EOF >${PKG_ROOT}/lib/systemd/system/rport-guacd.service
[Unit]
Description=Guacamole proxy daemon (guacd) for the rport.
ConditionFileIsExecutable=/opt/rport-guacamole/sbin/guacd
[Service]
Environment=HOME=/opt/rport-guacamole/tmp
Environment=LD_LIBRARY_PATH=/opt/rport-guacamole/lib
EnvironmentFile=/etc/default/rport-guacamole
ExecStart=/opt/rport-guacamole/sbin/guacd -f -b \${RPORT_GUACD_BIND} -l \${RPORT_GUACD_PORT}
User=daemon
Restart=always
RestartSec=120
[Install]
WantedBy=multi-user.target
EOF
chmod 0644 ${PKG_ROOT}/lib/systemd/system/rport-guacd.service
cat <<EOF >${PKG_ROOT}/etc/default/rport-guacamole
#
# Environment read by rport-guacd.service
#
# TCP Port used by the guacd
RPORT_GUACD_PORT=9445
# IP address used to bind the guacd
RPORT_GUACD_BIND=127.0.0.1
EOF
chmod 0644 ${PKG_ROOT}/etc/default/rport-guacamole
INSTALLED_SIZE=$(du -sb ${PKG_ROOT}/ | awk '{print $1}')
#
# Create package meta data
#
. /etc/os-release
if [ $ID = "ubuntu" ]; then
# Ubuntu package name
LIB_JPEG="libjpeg-turbo8"
else
# Debian package name
LIB_JPEG="libjpeg62-turbo"
fi
case $VERSION_CODENAME in
jammy|bookworm)
LIB_WEBP=libwebp7
;;
*)
LIB_WEBP=libwebp6
;;
esac
case $(uname -m) in
x86_64)
ARCH='amd64'
;;
armv7l)
ARCH='armhf'
;;
aarch64)
ARCH='arm64'
;;
esac
echo "ARCH = ${ARCH}"
GUACA_VERSION="1.5.0"
mkdir ${PKG_ROOT}/DEBIAN
chmod 0755 ${PKG_ROOT}/DEBIAN
#
# Create the package control file
#
cat <<EOF >${PKG_ROOT}/DEBIAN/control
Package: rport-guacamole
Version: ${GUACA_VERSION}
Maintainer: RealVNC Limited <[email protected]>
Depends: libc6, systemd, libcairo2, ${LIB_JPEG}, libpng16-16, libfreerdp-client2-2, libssh2-1, ${LIB_WEBP}
Installed-Size: ${INSTALLED_SIZE}
Architecture: ${ARCH}
Section: misc
Priority: optional
Homepage: https://github.com/realvnc-labs/rport-guacamole/
Description: Guacamole proxy daemon (guacd) for the rport server daemon
This version of guacd is intended to be used with rportd only.
The only configuration file is /etc/default/rport-guacamole.
EOF
#
# List of config files
#
cat <<EOF >${PKG_ROOT}/DEBIAN/conffiles
/etc/default/rport-guacamole
EOF
#
# Create a changelog, even dummy
#
cat <<EOF | gzip -n --best -c >${PKG_ROOT}/usr/share/doc/${PKG_NAME}/changelog.gz
rport-guacamole; urgency=low
* Non-maintainer upload.
EOF
chmod 0644 ${PKG_ROOT}/usr/share/doc/${PKG_NAME}/changelog.gz
cat <<EOF >${PKG_ROOT}/usr/share/doc/${PKG_NAME}/copyright
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Source: https://apache.org/dyn/closer.lua/guacamole/
Copyright: 2022
License: Apache-2
Files: *
Copyright: 2022
License: Apache-2
EOF
chmod 0644 ${PKG_ROOT}/usr/share/doc/${PKG_NAME}/copyright
#
# Create a postinst script
#
cat <<EOF >${PKG_ROOT}/DEBIAN/postinst
#!/bin/sh
set -e
chown daemon:daemon /opt/rport-guacamole/tmp
chmod 0755 /opt/rport-guacamole/sbin/guacd
systemctl daemon-reload
deb-systemd-invoke enable rport-guacd.service
deb-systemd-invoke start rport-guacd.service
EOF
chmod 0555 ${PKG_ROOT}/DEBIAN/postinst
#find /opt/rport-guacamole/ -type d -exec chmod 0755 {} \;
#find /opt/rport-guacamole/ -type f -exec chmod 0644 {} \;
#
# Create a prerm script
#
cat <<EOF >${PKG_ROOT}/DEBIAN/prerm
#!/bin/sh
set -e
deb-systemd-invoke stop rport-guacd.service
deb-systemd-invoke disable rport-guacd.service
rm -rf /opt/rport-guacamole/tmp
EOF
chmod 0555 ${PKG_ROOT}/DEBIAN/prerm
#
# Create a postrm script
#
cat <<EOF >${PKG_ROOT}/DEBIAN/postrm
#!/bin/sh
set -e
test -e /opt||mkdir /opt
EOF
chmod 0555 ${PKG_ROOT}/DEBIAN/postrm
#
# Build the debian package
#
. /etc/os-release
PKG_FILE=${PKG_NAME}_${GUACA_VERSION}_${ID}_${VERSION_CODENAME}_$(uname -m).deb
cd /
dpkg-deb -v --build ${PKG_ROOT}
mv ${PKG_ROOT}.deb /${PKG_FILE}
echo "Created $PKG_NAME in $PKG_FILE"
## Check the content of the package
dpkg-deb -c /${PKG_FILE}
echo "======================================================================================================"
echo ""
echo " Successfully created debian package ${PKG_FILE}"
echo ""
echo "======================================================================================================"