Skip to content

Commit d44ba1a

Browse files
committed
chore(base): add install-packages log
1 parent 87e345b commit d44ba1a

5 files changed

Lines changed: 91 additions & 66 deletions

File tree

debootstrap/bookworm/rootfs/usr/bin/install-stack

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ function main() {
4949
echo "Extract data to a temporary directory: ${TMP_DIR}"
5050
tar --directory "${TMP_DIR}" --extract --gunzip --file "${TMP_DIR}"/"${stack_filename}" --no-same-owner
5151

52-
echo "Install stack to directory: ${stack_path}"
53-
# shellcheck disable=SC2046,SC2086
54-
install-packages $(< "${TMP_DIR}"/meta/dependencies)
52+
packages=$(grep -vE '^\s*(#|$)' "${TMP_DIR}"/meta/dependencies)
53+
if [[ -n "${packages:+x}" ]]; then
54+
echo "Install system packages: ${packages}"
55+
install-packages "$packages"
56+
fi
57+
58+
echo "Install stack: ${name} ${version}"
5559
"${TMP_DIR}"/meta/preinstall
5660
cp -rf "${TMP_DIR}"/data/* "${stack_path}"
5761
"${TMP_DIR}"/meta/postinstall
5862
echo "Stack installation completed"
5963
}
6064

61-
main "$@"
65+
main "$@"

debootstrap/bookworm/rootfs/usr/sbin/install-packages

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
set -e
44
set -u
55

6-
export DEBIAN_FRONTEND=noninteractive
7-
86
function main {
97
n=0
108
max=2
119
until [ $n -gt $max ]; do
1210
set +e
1311
(
14-
apt-get update -qq &&
12+
apt-get update &&
1513
apt-get install -y --no-install-recommends "$@"
1614
)
1715
CODE=$?
Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,65 @@
11
#!/bin/bash
22

3-
# mark INIT_STACK
4-
export INIT_STACK=1
5-
# check to see if this file is being run or sourced from another script
6-
_is_sourced() {
7-
# https://unix.stackexchange.com/a/215279
8-
[ "${#FUNCNAME[@]}" -ge 2 ] \
9-
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \
10-
&& [ "${FUNCNAME[1]}" = 'source' ]
3+
set -e
4+
set -u
5+
# Constants
6+
TMP_DIR=$(mktemp -d)
7+
STACK_CACHE_ROOT="/tmp/drycc/stack/cache"
8+
STACK_DOWNLOAD_URL="${STACK_DOWNLOAD_URL:-https://download.drycc.cc/stacks}"
9+
10+
# OS Release
11+
# shellcheck source=/dev/null
12+
. /etc/os-release
13+
14+
function clean {
15+
# delay before exiting, so stdout/stderr flushes through the logging system
16+
rm -rf "${TMP_DIR}"
17+
sleep 3
18+
}
19+
trap clean EXIT
20+
21+
function main() {
22+
local name="${1:?name is required}"
23+
local version="${2:?version is required}"
24+
25+
local os_name="${OS_NAME:-linux}"
26+
local os_arch="${OS_ARCH:-$(dpkg --print-architecture)}"
27+
local os_flavour="${OS_FLAVOUR:-${ID}-${VERSION_ID}}"
28+
29+
local stack_path="/opt/drycc/${name}"
30+
local stack_name="${name}-${version}-${os_name}-${os_arch}-${os_flavour}"
31+
local stack_filename="${stack_name}".tar.gz
32+
local stack_download_url="${STACK_DOWNLOAD_URL}/${name}/${stack_filename}"
33+
34+
echo "Downloading $stack_filename package"
35+
if [ -f "${STACK_CACHE_ROOT}/${stack_filename}" ]; then
36+
echo "${STACK_CACHE_ROOT}/${stack_filename} already exists, skipping download."
37+
cp "${STACK_CACHE_ROOT}/${stack_filename}" "${TMP_DIR}/${stack_filename}"
38+
rm "${STACK_CACHE_ROOT}/${stack_filename}"
39+
else
40+
curl --silent --show-error --fail "${stack_download_url}" -o "${TMP_DIR}/${stack_filename}"
41+
fi
42+
echo "Generate installation directory: ${stack_path}"
43+
if [ -d "${stack_path}" ]; then
44+
echo "Clean up the directory: ${stack_path}"
45+
rm -rf "${stack_path}"
46+
fi
47+
mkdir -p "${stack_path}"
48+
49+
echo "Extract data to a temporary directory: ${TMP_DIR}"
50+
tar --directory "${TMP_DIR}" --extract --gunzip --file "${TMP_DIR}"/"${stack_filename}" --no-same-owner
51+
52+
packages=$(grep -vE '^\s*(#|$)' "${TMP_DIR}"/meta/dependencies)
53+
if [[ -n "${packages:+x}" ]]; then
54+
echo "Install system packages: ${packages}"
55+
install-packages "$packages"
56+
fi
57+
58+
echo "Install stack: ${name} ${version}"
59+
"${TMP_DIR}"/meta/preinstall
60+
cp -rf "${TMP_DIR}"/data/* "${stack_path}"
61+
"${TMP_DIR}"/meta/postinstall
62+
echo "Stack installation completed"
1163
}
1264

13-
env_list=$(find /opt/drycc/*/env/* 2>/dev/null || echo "")
14-
for env in ${env_list}
15-
do
16-
key=$(echo "${env}" | awk -F "/" '{print $NF}')
17-
value=$(<"${env}")
18-
# shellcheck source=/dev/null
19-
export "${key}=${value}"
20-
done
21-
22-
env_launch_list=$(find /opt/drycc/*/env.launch/* 2>/dev/null || echo "")
23-
for env in ${env_launch_list}
24-
do
25-
key=$(echo "${env}" | awk -F "/" '{print $NF}')
26-
value=$(<"${env}")
27-
# shellcheck source=/dev/null
28-
export "${key}=${value}"
29-
done
30-
31-
profile_list=$(find /opt/drycc/*/profile.d/* 2>/dev/null || echo "")
32-
for profile in ${profile_list}
33-
do
34-
# shellcheck source=/dev/null
35-
. "${profile}"
36-
done
37-
38-
exec_list=$(find /opt/drycc/*/exec.d/* 2>/dev/null) || echo ""
39-
for _exec in ${exec_list}
40-
do
41-
"${_exec}"
42-
done
43-
44-
if ! _is_sourced; then
45-
if [[ "$$" == "1" ]] ; then
46-
exec tini -g -- "$@"
47-
else
48-
exec tini -sg -- "$@"
49-
fi
50-
fi
65+
main "$@"

debootstrap/bullseye/rootfs/usr/bin/install-stack

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function main() {
2626
local os_arch="${OS_ARCH:-$(dpkg --print-architecture)}"
2727
local os_flavour="${OS_FLAVOUR:-${ID}-${VERSION_ID}}"
2828

29+
local stack_path="/opt/drycc/${name}"
2930
local stack_name="${name}-${version}-${os_name}-${os_arch}-${os_flavour}"
3031
local stack_filename="${stack_name}".tar.gz
3132
local stack_download_url="${STACK_DOWNLOAD_URL}/${name}/${stack_filename}"
@@ -38,18 +39,27 @@ function main() {
3839
else
3940
curl --silent --show-error --fail "${stack_download_url}" -o "${TMP_DIR}/${stack_filename}"
4041
fi
41-
echo "Generate installation directory: /opt/drycc/${name}"
42-
if [ -d /opt/drycc/"${name}" ]; then
43-
rm -rf /opt/drycc/"${name}"
42+
echo "Generate installation directory: ${stack_path}"
43+
if [ -d "${stack_path}" ]; then
44+
echo "Clean up the directory: ${stack_path}"
45+
rm -rf "${stack_path}"
4446
fi
45-
mkdir -p /opt/drycc/"${name}"
46-
47+
mkdir -p "${stack_path}"
48+
49+
echo "Extract data to a temporary directory: ${TMP_DIR}"
4750
tar --directory "${TMP_DIR}" --extract --gunzip --file "${TMP_DIR}"/"${stack_filename}" --no-same-owner
48-
# shellcheck disable=SC2046,SC2086
49-
install-packages $(< "${TMP_DIR}"/meta/dependencies)
51+
52+
packages=$(grep -vE '^\s*(#|$)' "${TMP_DIR}"/meta/dependencies)
53+
if [[ -n "${packages:+x}" ]]; then
54+
echo "Install system packages: ${packages}"
55+
install-packages "$packages"
56+
fi
57+
58+
echo "Install stack: ${name} ${version}"
5059
"${TMP_DIR}"/meta/preinstall
51-
cp -rf "${TMP_DIR}"/data/* /opt/drycc/"${name}"
60+
cp -rf "${TMP_DIR}"/data/* "${stack_path}"
5261
"${TMP_DIR}"/meta/postinstall
62+
echo "Stack installation completed"
5363
}
5464

55-
main "$@"
65+
main "$@"

debootstrap/bullseye/rootfs/usr/sbin/install-packages

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
set -e
44
set -u
55

6-
export DEBIAN_FRONTEND=noninteractive
7-
86
function main {
97
n=0
108
max=2
119
until [ $n -gt $max ]; do
1210
set +e
1311
(
14-
apt-get update -qq &&
12+
apt-get update &&
1513
apt-get install -y --no-install-recommends "$@"
1614
)
1715
CODE=$?
@@ -28,4 +26,4 @@ function main {
2826
rm -rf /var/lib/apt/lists /var/cache/apt/archives
2927
}
3028

31-
main "$@"
29+
main "$@"

0 commit comments

Comments
 (0)