-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mkpkg
executable file
·196 lines (171 loc) · 6.6 KB
/
mkpkg
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
#!/bin/bash
#
# shellcheck disable=SC1090,SC2220
#
PKG="rooncommandline"
SRC_NAME="RoonCommandLine"
PKG_NAME="RoonCommandLine"
TOP="usr"
DESTDIR="${TOP}/local"
ROON="${DESTDIR}/Roon"
SRC=${HOME}/src
SUDO=sudo
GCI=
dpkg=$(type -p dpkg-deb)
[ "${dpkg}" ] || {
echo "Debian packaging tools do not appear to be installed on this system"
echo "Are you on the appropriate Linux system with packaging requirements ?"
echo "Exiting"
exit 1
}
[ -f "${SRC}/${SRC_NAME}/VERSION" ] || {
[ -f "/builds/doctorfree/${SRC_NAME}/VERSION" ] || {
echo "$SRC/$SRC_NAME/VERSION does not exist. Exiting."
exit 1
}
SRC="/builds/doctorfree"
SUDO=
GCI=1
}
. "${SRC}/${SRC_NAME}/VERSION"
PKG_VER=${VERSION}
PKG_REL=${RELEASE}
umask 0022
# Subdirectory in which to create the distribution files
OUT_DIR="dist/${PKG_NAME}_${PKG_VER}"
[ -d "${SRC}/${SRC_NAME}" ] || {
echo "$SRC/$SRC_NAME does not exist or is not a directory. Exiting."
exit 1
}
cd "${SRC}/${SRC_NAME}" || exit 1
${SUDO} rm -rf dist
mkdir dist
[ -d "${OUT_DIR}" ] && rm -rf "${OUT_DIR}"
mkdir "${OUT_DIR}"
cp -a pkg/debian "${OUT_DIR}"/DEBIAN
chmod 755 "${OUT_DIR}" "${OUT_DIR}"/DEBIAN "${OUT_DIR}"/DEBIAN/*
echo "Package: ${PKG_NAME}
Version: ${PKG_VER}-${PKG_REL}
Section: misc
Priority: optional
Architecture: all
Depends: git (>= 2.20.1), python3-pip, jq
Maintainer: ${DEBFULLNAME} <${DEBEMAIL}>
Installed-Size: 1308
Build-Depends: debhelper (>= 11)
Standards-Version: 4.1.3
Homepage: https://github.com/doctorfree/RoonCommandLine
Description: Roon Command Line Tools
Manage your Roon Audio System from the command line" > "${OUT_DIR}"/DEBIAN/control
chmod 644 "${OUT_DIR}"/DEBIAN/control
for dir in "${TOP}" "${DESTDIR}" "${ROON}" \
"${DESTDIR}/share" "${DESTDIR}/share/applications" \
"${DESTDIR}/share/doc" "${DESTDIR}/share/doc/${PKG}"
do
[ -d "${OUT_DIR}"/${dir} ] || ${SUDO} mkdir "${OUT_DIR}"/"${dir}"
${SUDO} chown root:root "${OUT_DIR}"/"${dir}"
done
for dir in bin etc api patches
do
[ -d "${OUT_DIR}"/${ROON}/${dir} ] && ${SUDO} rm -rf "${OUT_DIR}"/${ROON}/${dir}
done
${SUDO} cp -a api "${OUT_DIR}"/${ROON}/api
${SUDO} cp -a bin "${OUT_DIR}"/${ROON}/bin
${SUDO} cp -a etc "${OUT_DIR}"/${ROON}/etc
${SUDO} cp VERSION "${OUT_DIR}"/${ROON}/etc/VERSION
${SUDO} cp -a patches "${OUT_DIR}"/${ROON}/patches
${SUDO} cp ./*.desktop "${OUT_DIR}/${DESTDIR}/share/applications"
${SUDO} cp AUTHORS "${OUT_DIR}"/${DESTDIR}/share/doc/${PKG}/AUTHORS
${SUDO} cp LICENSE "${OUT_DIR}"/${DESTDIR}/share/doc/${PKG}/copyright
${SUDO} cp CHANGELOG.md "${OUT_DIR}"/${DESTDIR}/share/doc/${PKG}/changelog
${SUDO} cp README.md "${OUT_DIR}"/${DESTDIR}/share/doc/${PKG}/README
${SUDO} cp VERSION "${OUT_DIR}"/${DESTDIR}/share/doc/${PKG}/VERSION
${SUDO} gzip -9 "${OUT_DIR}"/${DESTDIR}/share/doc/${PKG}/changelog
${SUDO} cp -a markdown "${OUT_DIR}/${DESTDIR}/share/doc/${PKG}/markdown"
${SUDO} cp -a man "${OUT_DIR}/${DESTDIR}/share/doc/${PKG}/man"
${SUDO} cp -a man "${OUT_DIR}/${DESTDIR}/share/man"
[ -f .gitignore ] && {
while read -r ignore
do
${SUDO} rm -f "${OUT_DIR}"/${ROON}/"${ignore}"
done < .gitignore
}
${SUDO} chmod 644 "${OUT_DIR}"/${ROON}/etc/* \
"${OUT_DIR}"/${ROON}/api/* \
"${OUT_DIR}"/${ROON}/patches/*.md "${OUT_DIR}"/${ROON}/patches/*.patch \
"${OUT_DIR}"/${ROON}/patches/roonapi/* \
"${OUT_DIR}"/${DESTDIR}/share/man/*/* \
"${OUT_DIR}"/${ROON}/patches/roon-web-controller/*
${SUDO} chmod 755 "${OUT_DIR}"/${ROON}/bin/* \
"${OUT_DIR}"/${ROON}/bin \
"${OUT_DIR}"/${ROON}/etc/discover \
"${OUT_DIR}"/${ROON}/etc/install-fzf \
"${OUT_DIR}"/${ROON}/etc/install-roon-gui \
"${OUT_DIR}"/${ROON}/etc/install-roon-tui \
"${OUT_DIR}"/${ROON}/etc/install-figlet \
"${OUT_DIR}"/${ROON}/etc/install-gum \
"${OUT_DIR}"/${ROON}/etc/roon_faded \
"${OUT_DIR}"/${ROON}/etc \
"${OUT_DIR}"/${ROON}/etc/postinstall \
"${OUT_DIR}"/${ROON}/etc/preremove \
"${OUT_DIR}"/${ROON}/api \
"${OUT_DIR}"/${ROON}/patches \
"${OUT_DIR}"/${ROON}/patches/mk* \
"${OUT_DIR}"/${ROON}/patches/roonapi \
"${OUT_DIR}"/${DESTDIR}/share/man \
"${OUT_DIR}"/${DESTDIR}/share/man/* \
"${OUT_DIR}"/${ROON}/patches/roon-web-controller
${SUDO} chown -R root:root "${OUT_DIR}"/${DESTDIR}
cd dist || exit 1
echo "Building ${PKG_NAME}_${PKG_VER} package"
${SUDO} dpkg-deb -Zxz --build ${PKG_NAME}_"${PKG_VER}" ${PKG_NAME}_"${PKG_VER}"-"${PKG_REL}".deb
cd "${PKG_NAME}"_"${PKG_VER}" || exit 1
echo "Creating compressed tar archive of ${PKG_NAME} ${PKG_VER} distribution"
tar cf - usr | gzip -9 > ../${PKG_NAME}_"${PKG_VER}"-"${PKG_REL}".tgz
have_zip=$(type -p zip)
[ "${have_zip}" ] || {
${SUDO} apt-get update
${SUDO} apt-get install zip -y
}
echo "Creating zip archive of ${PKG_NAME} ${PKG_VER} distribution"
zip -q -r ../${PKG_NAME}_"${PKG_VER}"-"${PKG_REL}".zip usr
cd ..
[ "${GCI}" ] || {
[ -d ../releases ] || mkdir ../releases
[ -d ../releases/"${PKG_VER}" ] || mkdir ../releases/"${PKG_VER}"
${SUDO} cp ./*.deb ./*.tgz ./*.zip ../releases/"${PKG_VER}"
}
cd "${SRC}/${SRC_NAME}" || exit 1
[ -d pkg/rpm ] && cp -a pkg/rpm "${OUT_DIR}"/rpm
[ -d "${OUT_DIR}"/rpm ] || mkdir "${OUT_DIR}"/rpm
have_rpm=$(type -p rpmbuild)
[ "${have_rpm}" ] || {
${SUDO} apt-get update
export DEBIAN_FRONTEND=noninteractive
${SUDO} ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
${SUDO} apt-get install rpm -y
${SUDO} dpkg-reconfigure --frontend noninteractive tzdata
}
rpmbuild -ba --build-in-place \
--define "_topdir ${OUT_DIR}" \
--define "_sourcedir ${OUT_DIR}" \
--define "_version ${PKG_VER}" \
--define "_release ${PKG_REL}" \
--buildroot "${SRC}"/${SRC_NAME}/"${OUT_DIR}"/BUILDROOT \
"${OUT_DIR}"/rpm/${PKG_NAME}.spec
# Rename RPMs if necessary
for rpmfile in "${OUT_DIR}"/RPMS/*/*.rpm
do
[ "${rpmfile}" == "${OUT_DIR}/RPMS/*/*.rpm" ] && continue
rpmbas=$(basename "${rpmfile}")
rpmdir=$(dirname "${rpmfile}")
newnam=$(echo "${rpmbas}" | sed -e "s/${PKG_NAME}-${PKG_VER}-${PKG_REL}/${PKG_NAME}_${PKG_VER}-${PKG_REL}/" -e "s/noarch.rpm/rpm/")
[ "${rpmbas}" == "${newnam}" ] && continue
mv "${rpmdir}"/"${rpmbas}" "${rpmdir}"/"${newnam}"
done
${SUDO} cp "${OUT_DIR}"/RPMS/*/*.rpm dist
[ "${GCI}" ] || {
[ -d releases ] || mkdir releases
[ -d releases/"${PKG_VER}" ] || mkdir releases/"${PKG_VER}"
${SUDO} cp "${OUT_DIR}"/RPMS/*/*.rpm releases/"${PKG_VER}"
}