-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-packages.sh
executable file
·133 lines (115 loc) · 4.07 KB
/
install-packages.sh
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env sh
###
# Environment ${INSTALL_VERSION} pass from Dockerfile
###
CURL="curl ca-certificates"
# https://crates.io/crates/mdbook-plantuml
PLANTUML_DEPS="libssl-dev pkgconf libpq-dev"
BUILD_DEPS="${CURL} ${PLANTUML_DEPS} build-essential cmake musl-dev musl-tools linux-libc-dev sudo"
echo "# ------ TARGETPLATFORM: $TARGETPLATFORM ------ #"
uname -a
export
echo
echo "###"
echo "# Will install build tool"
echo "###"
echo
echo $BUILD_DEPS
echo
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -qq -y --no-install-recommends ${BUILD_DEPS}
#/* put your install code here */#
ln -s "/usr/bin/g++" "/usr/bin/musl-g++" || exit 50
if [ -z "$TARGETPLATFORM" ]; then
TARGETPLATFORM=$(uname -m)
fi
OPENSSL_VERSION=3.0.12
ZLIB_VERSION=1.3
install_aarch64_musl() {
echo "# ------ Building aarch64_musl ------ #"
mkdir -p /opt/musl
curl -Lk "https://musl.cc/aarch64-linux-musl-cross.tgz" | tar -xz -C /opt/musl --strip-components=1 || exit 51
}
install_openssl() {
mkdir -p /usr/local/musl/include
mkdir -p /tmp/openssl-src
ln -s /usr/include/linux /usr/local/musl/include/linux \
&& ln -s /usr/include/${ASM_FOLDER}-gnu/asm /usr/local/musl/include/asm \
&& ln -s /usr/include/asm-generic /usr/local/musl/include/asm-generic
short_version="$(echo "$OPENSSL_VERSION" | sed s'/[a-z]$//')"
(curl -Lk "https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz" \
|| curl -Lk "https://www.openssl.org/source/old/$short_version/openssl-$OPENSSL_VERSION.tar.gz") \
| tar -xz -C /tmp/openssl-src --strip-components=1 \
&& cd /tmp/openssl-src
env C_INCLUDE_PATH=/usr/local/musl/include/ ./Configure no-shared no-zlib -fPIC --prefix=/usr/local/musl -DOPENSSL_NO_SECURE_MEMORY $OPENSSL_PLATFORM
env C_INCLUDE_PATH=/usr/local/musl/include/ make depend
env C_INCLUDE_PATH=/usr/local/musl/include/ make
env C_INCLUDE_PATH=/usr/local/musl/include/ make install
}
install_zlib() {
curl -Lk "https://www.zlib.net/fossils/zlib-${ZLIB_VERSION}.tar.gz" | tar -xz -C /tmp/zlib --strip-components=1 && cd /tmp/zlib
./configure --static --prefix=/usr/local/mus
make -j$(nproc)
make -j$(nproc) install
}
install_sudo() {
useradd rust --user-group --create-home --shell /bin/bash --groups sudo
echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/nopasswd
mkdir -p /home/rust/libs /home/rust/src /home/rust/.cargo
mkdir -p /opt/cargo
chown -R rust:rust /opt/cargo
chown -R rust:rust /home/rust
cat > /home/rust/.cargo/config.toml << EOF
[build]
# Target musl-libc by default when running Cargo.
target = "${RUST_TARGET}"
EOF
if [ 'linux-aarch64' = "${OPENSSL_PLATFORM}" ]; then
cat >> /home/rust/.cargo/config.toml << EOF
[build.env]
passthrough = [
"RUSTFLAGS",
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS",
]
EOF
fi
}
install_rust() {
curl -Lk https://sh.rustup.rs \
| env CARGO_HOME=/opt/rust/cargo \
sh -s -- -y --default-toolchain ${INSTALL_VERSION} --profile minimal --no-modify-path
env CARGO_HOME=/opt/rust/cargo \
rustup component add rustfmt \
&& env CARGO_HOME=/opt/rust/cargo rustup component add clippy \
&& env CARGO_HOME=/opt/rust/cargo rustup target add ${RUST_TARGET} || exit 33
}
case "$TARGETPLATFORM" in
aarch64 | linux/arm64)
export CC="aarch64-linux-musl-gcc"
OPENSSL_PLATFORM="linux-aarch64"
ASM_FOLDER="linux-aarch64"
RUST_TARGET="aarch64-unknown-linux-musl"
install_aarch64_musl
;;
*)
export CC="musl-gcc"
OPENSSL_PLATFORM="linux-x86_64"
ASM_FOLDER="x86_64-linux"
RUST_TARGET="x86_64-unknown-linux-musl"
;;
esac
echo "# ------ Building OpenSSL ------ #"
install_openssl || exit 5
echo "# ------ Building ZLIB ------ #"
install_zlib || exit 4
echo "# ------ Building rust ------ #"
install_rust || exit 3
install_sudo || exit 2
echo $(date +%Y%m%d%S)'-'$TARGETPLATFORM > /build_version
# Clean
apt-get clean autoclean \
&& apt-get autoremove --yes \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/{apt,dpkg,cache,log}/ \
&& rm -rf rm -rf /opt/rust/cargo/registry/* \
&& rm -rf /tmp/* || exit 1
exit 0