1#!/bin/bash
2
3# preflight check
4if [[ ! -f ./make_deb.sh ]]; then
5	echo "You must run this script from within the installer_linux directory!"
6	exit 1
7fi
8
9# version
10
11if [ "$SURGE_VERSION" != "" ]; then
12    VERSION="$SURGE_VERSION"
13elif [ "$1" != "" ]; then
14    VERSION="$1"
15fi
16
17if [ "$VERSION" == "" ]; then
18    echo "You must specify the version you are packaging!"
19    echo "eg: ./make_deb.sh 1.0.6b4"
20    exit 1
21fi
22
23# Valid version for DEB start with a digit.
24DEB_VERSION=$VERSION
25if [[ ${DEB_VERSION:0:1} =~ [0-9] ]]; then
26    echo "DEB VERSION same as Version (${DEB_VERSION})"
27elif [[ ${DEB_VERSION} = NIGHTLY* ]]; then
28    DEB_VERSION="9.${VERSION}"
29    echo "NIGHTLY; DEB VERSION is ${DEB_VERSION}"
30else
31    DEB_VERSION="0.${VERSION}"
32    echo "DEB VERSION is ${DEB_VERSION}"
33fi
34
35
36# Names
37SURGE_NAME=surge
38PACKAGE_NAME="$SURGE_NAME"
39# SURGE_NAME=surge-synthesizer
40
41# locations
42
43# Cleanup from failed prior runs
44rm -rf ${PACKAGE_NAME} product
45mkdir -p ${PACKAGE_NAME}/usr/lib/vst3
46# mkdir -p ${PACKAGE_NAME}/usr/lib/lv2
47mkdir -p ${PACKAGE_NAME}/usr/share/${SURGE_NAME}/doc
48mkdir -p ${PACKAGE_NAME}/DEBIAN
49chmod -R 0755 ${PACKAGE_NAME}
50
51# build control file
52
53if [[ -f ${PACKAGE_NAME}/DEBIAN/control ]]; then
54	rm ${PACKAGE_NAME}/DEBIAN/control
55fi
56touch ${PACKAGE_NAME}/DEBIAN/control
57cat <<EOT >> ${PACKAGE_NAME}/DEBIAN/control
58Source: ${PACKAGE_NAME}
59Package: ${PACKAGE_NAME}
60Version: $DEB_VERSION
61Architecture: amd64
62Maintainer: surgeteam <noreply@github.com>
63Depends: libc6 (>=2.27), libcairo2, libfontconfig1, libfreetype6, libx11-6, libxcb-cursor0, libxcb-util1, libxcb-xkb1, libxcb1, libxkbcommon-x11-0, libxkbcommon0, fonts-lato, xdg-utils, zenity, xclip
64Provides: vst-plugin
65Section: sound
66Priority: optional
67Description: Subtractive hybrid synthesizer virtual instrument
68 Surge includes VST3, and LV2 virtual instrument formats for use in compatible hosts.
69EOT
70
71touch ${PACKAGE_NAME}/usr/share/${SURGE_NAME}/doc/changelog.Debian
72DATE=`date --rfc-email`
73MSG=`git log -n 1 --pretty="%s (git hash %H)"`
74cat <<EOT > ${PACKAGE_NAME}/usr/share/${SURGE_NAME}/doc/changelog.Debian
75${PACKAGE_NAME} (${DEB_VERSION}) stable; urgency=medium
76
77  * ${MSG}
78  * For more details see https://github.com/surge-synthesizer/surge
79
80 -- Surge Synthesizer Team <noreply@github.com>  ${DATE}
81EOT
82gzip -9 -n ${PACKAGE_NAME}/usr/share/${SURGE_NAME}/doc/changelog.Debian
83
84#copy data and vst plugins
85
86cp ../LICENSE ${PACKAGE_NAME}/usr/share/${SURGE_NAME}/doc/copyright
87cp -r ../resources/data/* ${PACKAGE_NAME}/usr/share/${SURGE_NAME}/
88
89# Copy the VST3 bundld
90cp -r ../build/surge_products/Surge.vst3 ${PACKAGE_NAME}/usr/lib/vst3/
91cp -r ../build/surge_products/SurgeEffectsBank.vst3 ${PACKAGE_NAME}/usr/lib/vst3/
92
93# copy the lv2 bundle
94# cp -r ../build/surge_products/Surge.lv2 ${PACKAGE_NAME}/usr/lib/lv2/
95
96# set permissions on shared libraries
97find ${PACKAGE_NAME}/usr/lib/vst3/ -type f -iname "*.so" | xargs chmod 0644
98# find ${PACKAGE_NAME}/usr/lib/lv2/ -type f -iname "*.so" | xargs chmod 0644
99
100echo "----- LIBRARY CONTENTS (except resource) -----"
101find ${PACKAGE_NAME}/usr/lib -print
102
103# build package
104
105mkdir -p product
106dpkg-deb --build ${PACKAGE_NAME} product/${PACKAGE_NAME}-linux-x64-${VERSION}.deb
107rm -rf ${PACKAGE_NAME}
108
109echo "Built DEB Package"
110pwd
111