aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlo Landmeter <clandmeter@alpinelinux.org>2020-01-18 14:39:04 +0100
committerCarlo Landmeter <clandmeter@alpinelinux.org>2020-01-18 14:39:04 +0100
commit86fc81da6841708a04bcc4d084e03a43dc508334 (patch)
tree850b7565438827b61c746ecef60e559d5bb39fa9
parent01864fcb022ea355be58f366d8e30ce5008a51f3 (diff)
downloaddocker-abuild-86fc81da6841708a04bcc4d084e03a43dc508334.tar.bz2
docker-abuild-86fc81da6841708a04bcc4d084e03a43dc508334.tar.xz
admin: multiarch add enable/disable with warning
-rwxr-xr-xdabuild-admin45
1 files changed, 40 insertions, 5 deletions
diff --git a/dabuild-admin b/dabuild-admin
index a235f24..6303e9c 100755
--- a/dabuild-admin
+++ b/dabuild-admin
@@ -4,6 +4,24 @@ set -eu
readonly cmd=${1:-help}
+die() {
+ echo "$@" >&2
+ exit 1
+}
+
+ask() {
+ local question="$1"
+ while true; do
+ # SC2039 -p is non posix but widely available
+ read -rp "$question" yn
+ case $yn in
+ [Yy]) return 0;;
+ [Nn]) exit;;
+ *) echo "Please answer y/n.";;
+ esac
+ done
+}
+
manage_config() {
docker run --user 1000:1000 --rm -it --workdir /mnt/abuild \
-v dabuild-config:/mnt/abuild alpine sh
@@ -13,9 +31,27 @@ list_volumes() {
docker volume ls --quiet --filter name="^dabuild"
}
-enable_multiarch() {
- docker run --rm --privileged multiarch/qemu-user-static \
- --reset --persistent yes --credential yes
+multiarch() {
+ case "${2:-help}" in
+ enable) ask "Are you sure you want to enable multi-arch system wide? (y/n): "
+ docker run --rm --privileged multiarch/qemu-user-static \
+ --reset --persistent yes --credential yes ;;
+ disable) sudo --prompt="Sudo password:" find /proc/sys/fs/binfmt_misc \
+ -type f -name 'qemu-*' -exec sh -c 'echo -1 > {}' \; ;;
+ help) multiarch_usage ;;
+ *) die "Unknown subcommand \"$2\"" ;;
+ esac
+}
+
+multiarch_usage() {
+ cat <<- EOF
+ dabuild: version (unknown)
+
+ Available subcommands:
+ enable: enable multi-arch support via binfmt_misc
+ disable: disable mutli-arch support
+ help: this help screen
+ EOF
}
usage() {
@@ -30,11 +66,10 @@ usage() {
EOF
}
-
case $cmd in
config) manage_config;;
volumes) list_volumes;;
- multiarch) enable_multiarch;;
+ multiarch) multiarch "$@";;
help) usage;;
*) usage; exit 1;;
esac