-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbootstrap-sudo-linux-alpine
executable file
·86 lines (73 loc) · 3.13 KB
/
bootstrap-sudo-linux-alpine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
set -euo pipefail
YP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null && pwd)"
source ${YP_DIR}/sh/common.inc.sh
source ${YP_DIR}/sh/package-managers/apk.inc.sh
if [[ "${EUID}" != "0" ]]; then
echo_info "EUID=${EUID}"
[[ -n "${YP_SUDO}" ]] || {
echo_info "YP_SUDO=${YP_SUDO}"
echo_err "Restarting this shell script as root is impossible."
exit 1
}
echo_warn "Restarting this shell script as root."
exe ${YP_SUDO} --preserve-env --set-home ${BASH_SOURCE[0]}
exit 0
fi
# keep in sync with dockerfiles/yp-alpine/Dockerfile.build.sh
echo_do "Setup apk..."
apk_update
apk_install_one ca-certificates
apk_install_one gnupg
apk_install_one git
apk_install_one openssl
apk_install_one openssh-client
apk_install_one sudo
echo_done
# Basic
echo_do "apk: Installing basic packages..."
apk_install_one build-base # as per homebrew-install
apk_install_one coreutils
apk_install_one findutils
apk_install_one util-linux
apk_install_one bash
apk_install_one curl
apk_install_one file
apk_install_one python3
# NOTE homebrew alpine deps as per https://github.com/Linuxbrew/docker/blob/2c7ecfe/alpine/Dockerfile
# NOTE skipping libc6-compat since it conflicts with the glibc installation below
for f in bash coreutils curl file g++ grep git make sudo; do
apk_install_one ${f}
done
# NOTE homebrew needs ruby 2.6, which last existed in alpine 3.11
# NOTE expecting ruby 2.6 preinstalled e.g. from https://hub.docker.com/_/ruby
exe_and_grep_q "ruby --version | head -1" "^ruby 2\.6\."
# NOTE install glibc as required by homebrew, it also sets up locales
# NOTE using glibc on alpine is not recommended!
# see https://github.com/sgerrand/alpine-pkg-glibc
# see https://ariadne.space/2021/08/26/there-is-no-such-thing-as-a-glibc-based-alpine-image/
(
cd $(mktemp -d -t yplatform.XXXXXXXXXX)
curl -qfsSL -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
# shellcheck disable=SC1091
GLIBC_VSN=$(source ${YP_DIR}/CONST.inc && echo "${YP_ALPINE_PKG_GLIBC_VSN}")
curl -qfsSL -O \
https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VSN}/glibc-${GLIBC_VSN}.apk
curl -qfsSL -O \
https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VSN}/glibc-bin-${GLIBC_VSN}.apk
curl -qfsSL -O \
https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VSN}/glibc-i18n-${GLIBC_VSN}.apk
apk add glibc-${GLIBC_VSN}.apk glibc-bin-${GLIBC_VSN}.apk glibc-i18n-${GLIBC_VSN}.apk
rm glibc-${GLIBC_VSN}.apk glibc-bin-${GLIBC_VSN}.apk glibc-i18n-${GLIBC_VSN}.apk
sed -i "s|/usr/bin/bash|/bin/bash|g" /usr/glibc-compat/bin/*
/usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8
echo "export LANG=en_US.UTF-8" >/etc/profile.d/locale.sh
)
# NOTE fixes for 'brew install perl'
apk_install_one expat
apk_install_one expat-dev
[[ -e /usr/include/xlocale.h ]] || ln -s /usr/include/locale.h /usr/include/xlocale.h
# scripts tend to call /usr/bin/pyhon to intend calling python2 or python3, whichever is available
[[ -e /usr/bin/python ]] || ln -s /usr/bin/python3 /usr/bin/python
echo_done
apk_list_installed