-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-deb.sh
executable file
·134 lines (99 loc) · 2.66 KB
/
make-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
#! /bin/bash
# make-deb.sh
set -e
# Build .deb installer using app name and version from package.json.
PACKAGE=$(cat package.json | jq -r '.name')
VERSION=$(cat package.json | jq -r '.version')
DESCRIPTION="REST API Microservice"
ORGANIZATION="Acme Labs"
PLATFORM=ubuntu
ARCH=all
if [ -z "$PACKAGE" ]; then
echo "ERROR: package.json app name undefined"
exit 1
fi
if [ -z "$VERSION" ]; then
echo "ERROR: package.json app version undefined"
exit 1
fi
# RELEASE identifies package spin version.
if [ $# -eq 1 ]; then
RELEASE=$1;
FILENAME=${PACKAGE}_${VERSION}-${RELEASE}_${PLATFORM}_${ARCH}.deb
else
for ((i = 0; i < 1000; i++))
do
RELEASE=$i
FILENAME=${PACKAGE}_${VERSION}-${RELEASE}_${PLATFORM}_${ARCH}.deb
if [ ! -f $FILENAME ]; then
break
fi
done
fi
rm -rf ./deb-build
mkdir -p ./deb-build/DEBIAN
mkdir -p ./deb-build/usr/local/exp/${PACKAGE}
mkdir -p ./deb-build/usr/local/exp/${PACKAGE}/node_modules
cp app.js ./deb-build/usr/local/exp/${PACKAGE}/.
cp package.json ./deb-build/usr/local/exp/${PACKAGE}/.
cp npm-shrinkwrap.json ./deb-build/usr/local/exp/${PACKAGE}/.
cat << EOF >./deb-build/DEBIAN/install
/usr/local/exp/${PACKAGE}
EOF
cat << EOF >./deb-build/DEBIAN/preinst
#! /bin/sh
EOF
chmod 755 ./deb-build/DEBIAN/preinst
cat << EOF >./deb-build/DEBIAN/postinst
#! /bin/sh
id ${PACKAGE} >/dev/null 2>&1
if [ \$? -ne 0 ]; then
useradd --shell /bin/bash --password ${PACKAGE} -m ${PACKAGE}
fi
chown ${PACKAGE}:${PACKAGE} /usr/local/exp/${PACKAGE}
chown ${PACKAGE}:${PACKAGE} /usr/local/exp/${PACKAGE}/node_modules
chown ${PACKAGE}:${PACKAGE} /usr/local/exp/${PACKAGE}/app.js
chown ${PACKAGE}:${PACKAGE} /usr/local/exp/${PACKAGE}/package.json
chown ${PACKAGE}:${PACKAGE} /usr/local/exp/${PACKAGE}/npm-shrinkwrap.json
EOF
chmod 755 ./deb-build/DEBIAN/postinst
cat << EOF >./deb-build/DEBIAN/prerm
#! /bin/sh
EOF
chmod 755 ./deb-build/DEBIAN/prerm
cat << EOF >./deb-build/DEBIAN/postrm
#! /bin/sh
EOF
chmod 755 ./deb-build/DEBIAN/postrm
cat << EOF >./deb-build/DEBIAN/control
Package: ${PACKAGE}
Version: ${VERSION}-${RELEASE}
Section: non-free/misc
Priority: optional
Architecture: ${ARCH}
Maintainer: ${ORGANIZATION}
Description: ${DESCRIPTION}
EOF
cat << EOF >./deb-build/DEBIAN/copyright
This package was created on $(date)
Copyright:
Copyright (C) $(date +"%Y") ${ORGANIZATION}
License:
Commercial. All rights reserved.
EOF
# intentional tab at beginning of dh line:
cat << EOF >./deb-build/DEBIAN/rules
#!/usr/bin/make -f
%:
dh $@
EOF
cat << EOF >./deb-build/DEBIAN/compat
7
EOF
fakeroot dpkg-deb --build deb-build $FILENAME
file $FILENAME
md5sum $FILENAME
ls -l $FILENAME
rm -rf ./deb-build
exit 0
# end.