#!/bin/bash # $1 is the arch, $2 is the version, $3 is the binary tarball URL if [ $# -ne 3 ]; then echo "Usage: build.sh [architecture] [package version] [binary tar.gz url]" echo "Note: It is recommended to use \`fakeroot build.sh ...\` to ensure correct file permissions" echo -e "Example usage:\n\tfakeroot ./build.sh amd64 0.38.4 https://dl.nwjs.io/v0.38.4/nwjs-v0.38.4-linux-x64.tar.gz" exit 1 fi ARCH=$1 VERSION=$2 URL=$3 FILENAME="nwjs-normal_$VERSION-1_$ARCH.deb" mkdir -p out # Fill in real architecture and version info # Need to escape periods in the version string first ESCAPEDVERSION=$(echo "$VERSION" | sed 's/\./\\\./g') echo "Setting package version and architecture in control file" sed -i "s/ARCH/$ARCH/" debian/DEBIAN/control sed -i "s/VERSION/$ESCAPEDVERSION/" debian/DEBIAN/control function clean_exit() { echo "Resetting arch/version strings in control file" sed -i "s/$ARCH/ARCH/" debian/DEBIAN/control sed -i "s/$ESCAPEDVERSION/VERSION/" debian/DEBIAN/control exit 0 } # Clean and remake binary folder rm -rf debian/usr/lib/nw.js mkdir -p debian/usr/lib/nw.js # Make sure the control file resets even when Ctrl-C pressed trap "clean_exit" 2 # Download binary echo "Downloading and unpacking $URL" wget -q -O- $URL | tar -xvz --strip 1 -C debian/usr/lib/nw.js echo "Packaging deb file $FILENAME" dpkg-deb -b debian "out/$FILENAME" clean_exit