Created
February 19, 2025 22:55
-
-
Save jesselang/97e747981b06001b4f1f9a7c759c5512 to your computer and use it in GitHub Desktop.
Package management wrapper for Alpine/Ubuntu suitable for container image builds
This file contains hidden or 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
__package_detect_distribution() { | |
if [ -f /etc/alpine-release ]; then | |
return 1 | |
elif [ -f /etc/debian_version ]; then | |
return 2 | |
else | |
return -1 | |
fi | |
} | |
package() { | |
__package_detect_distribution | |
case $? in | |
1) # alpine | |
case "$1" in | |
update) | |
(set -ex; | |
apk update \ | |
&& apk upgrade --no-progress --no-cache | |
) | |
;; | |
install) | |
shift | |
(set -ex; | |
apk add --no-progress --no-cache "$@" | |
) | |
;; | |
esac | |
;; | |
2) # ubuntu | |
case "$1" in | |
update) | |
(set -ex; | |
apt-get -qq update \ | |
&& apt-get upgrade -y -qq \ | |
&& apt-get clean \ | |
&& rm -rf /var/lib/apt/lists/* | |
) | |
;; | |
install) | |
shift | |
(set -ex; | |
apt-get -qq update \ | |
&& apt-get install -y -qq --no-install-recommends "$@" \ | |
&& rm -rf /var/lib/apt/lists/* \ | |
&& apt-get autoremove -y -qq \ | |
&& apt-get clean | |
) | |
;; | |
esac | |
;; | |
*) # unsupported | |
echo "error: unsupported distribution" >&2 | |
return 1 | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment