Skip to content

Instantly share code, notes, and snippets.

@dmke
Created September 26, 2016 13:30
Show Gist options
  • Save dmke/7efbdfc6d93897896b27251ff326b075 to your computer and use it in GitHub Desktop.
Save dmke/7efbdfc6d93897896b27251ff326b075 to your computer and use it in GitHub Desktop.
Convert unifi_sysvinit_all.deb to DIY.tar.gz
#!/bin/bash -e
self=$(readlink -f "$0")
root=$(dirname "$self")
version="$1"
checksum="$2"
if [ -z "$version" ]; then
echo >&2 "Missing version specifier."
echo >&2 "Usage: ${self} VERSION [SHA256]"
exit 1
fi
echo "-- Checking dependencies"
for bin in curl ar tar gzip sha256sum awk stat rsync; do
if ! which $bin >/dev/null 2>&1; then
echo >&2 " Binary ${bin} not found in PATH"
exit 1
fi
done
debfile="${root}/dl/${version}.deb"
debdir="${root}/tmp/${version}-deb"
tarfile="tmp/${version}.tar.gz"
mkdir -p "${root}/dl"
echo "-- Downloading UniFi Controller v${version}"
if [ -f "${debfile}" ]; then
echo " [SKIP] file already exist"
else
curl -sL "http://dl.ubnt.com/unifi/${version}/unifi_sysvinit_all.deb" > "${debfile}"
echo " OK."
fi
echo "-- Verify download"
if [ -z "$checksum" ]; then
echo " [SKIP] expected checksum not given"
else
debsum=$(sha256sum "$debfile" | awk '{ print $1 }')
echo " sha256 of download is ${debsum}"
echo " expected sha256 is ${checksum}"
if [ "$checksum" = "$debsum" ]; then
echo " checksums match"
else
echo >&2 " checksum mismatch"
exit 1
fi
fi
echo "-- Unpacking .deb file"
rm -rf "$debdir"
mkdir -p "$debdir"
ar p "$debfile" data.tar.gz | tar xz -C "$debdir"
echo "-- Repacking .tar.gz"
rsync -a --delete "${debdir}/usr/lib/unifi/" "${root}/tmp/unifi-${version}"
ln -sf /usr/bin/mongod "${root}/tmp/unifi-${version}/bin/mongod"
tar czf "$tarfile" -C "${root}/tmp" "unifi-${version}"
tarsum=$(sha256sum "$tarfile" | awk '{ print $1 }')
tarsize=$(stat -c '%s' "$tarfile")
tarsize_human=$(( tarsize/1048576 ))
echo " file: ${tarfile}"
echo " size: ${tarsize} bytes (${tarsize_human} MB)"
echo " sha256: ${tarsum}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment