Created
February 16, 2017 05:22
-
-
Save ascandella/3b0218080e143e992cfd509b56c4bc03 to your computer and use it in GitHub Desktop.
Golang debian postinst for Uber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/debian/golang-X.Y-go.postinst b/debian/golang-X.Y-go.postinst | |
index 160957243..388aef2d1 100644 | |
--- a/debian/golang-X.Y-go.postinst | |
+++ b/debian/golang-X.Y-go.postinst | |
@@ -5,6 +5,20 @@ case "$1" in | |
configure) | |
# Very ugly hack to set timestamps same as /usr/lib/go-X.Y/bin/go | |
find /usr/lib/go-X.Y/pkg -exec touch -r /usr/lib/go-X.Y/bin/go {} \; | |
+ # Setup alternatives | |
+ # Priority: base of 100 + go version; 1.4.2 = 100 + 42; 1.5 = 100 + 50 | |
+ go=$(/usr/lib/go-X.Y/bin/go version | awk '{ | |
+ gsub(/^go1|[.]/, "", $3); | |
+ gsub(/([^0-9.]+.*)$/, "", $3); | |
+ if ($3 ~ /^[0-9]$/) { | |
+ $3 = $3 "0"; | |
+ }; | |
+ print $3; | |
+ }') | |
+ priority=$(( 100 + $go )) | |
+ update-alternatives \ | |
+ --install /usr/bin/go go /usr/lib/go-X.Y/bin/go $priority \ | |
+ --slave /usr/bin/gofmt gofmt /usr/lib/go-X.Y/bin/gofmt | |
;; | |
*) | |
;; | |
diff --git a/debian/golang-X.Y-go.prerm b/debian/golang-X.Y-go.prerm | |
new file mode 100644 | |
index 000000000..ad946c89e | |
--- /dev/null | |
+++ b/debian/golang-X.Y-go.prerm | |
@@ -0,0 +1,21 @@ | |
+#!/bin/sh | |
+set -e | |
+ | |
+case "$1" in | |
+ remove|deconfigure) | |
+ update-alternatives --remove go /usr/lib/go-X.Y/bin/go | |
+ ;; | |
+ | |
+ upgrade|failed-upgrade) | |
+ ;; | |
+ | |
+ *) | |
+ echo >&2 "prerm called with unknown argument: $1" | |
+ exit 0 | |
+ ;; | |
+esac | |
+ | |
+ | |
+#DEBHELPER# | |
+ | |
+exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment