Skip to content

Instantly share code, notes, and snippets.

@egeneralov
Last active November 7, 2021 09:34
Show Gist options
  • Save egeneralov/e79fc3e7fc873c240cfe6d4e70df87d0 to your computer and use it in GitHub Desktop.
Save egeneralov/e79fc3e7fc873c240cfe6d4e70df87d0 to your computer and use it in GitHub Desktop.
#!/bin/bash -xe
apt-get install -yq md5deep wget fakeroot
[ -z "${GO_VERSION}" ] && GO_VERSION=1.17
mkdir -p /tmp/golang/{DEBIAN,usr/local}
cd /tmp/golang/
wget https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz
tar -C usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
rm go${GO_VERSION}.linux-amd64.tar.gz
cat << EOF > DEBIAN/control
Package: golang
Version: ${GO_VERSION}
Section: develop
Architecture: amd64
Maintainer: Eduard Generalov <eduard@generalov.net>
Description: Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
EOF
cat << EOF > DEBIAN/postinst
#!/bin/sh -xe
ln -sf /usr/local/go/bin/go /usr/local/bin/go
EOF
cat << EOF > DEBIAN/prerm
#!/bin/sh -xe
[ -f /usr/local/bin/go ] && rm /usr/local/bin/go
EOF
chmod +x DEBIAN/postinst DEBIAN/prerm
md5deep -r usr > DEBIAN/md5sums
fakeroot dpkg-deb --build ${PWD} /tmp/go_${GO_VERSION}_amd64.deb
dpkg -i /tmp/go_${GO_VERSION}_amd64.deb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment