-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall-stack
More file actions
executable file
·65 lines (54 loc) · 2.11 KB
/
install-stack
File metadata and controls
executable file
·65 lines (54 loc) · 2.11 KB
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
#!/bin/bash
set -e
set -u
# Constants
TMP_DIR=$(mktemp -d)
STACK_CACHE_ROOT="/tmp/drycc/stack/cache"
STACK_DOWNLOAD_URL="${STACK_DOWNLOAD_URL:-https://download.drycc.cc/stacks}"
# OS Release
# shellcheck source=/dev/null
. /etc/os-release
function clean {
# delay before exiting, so stdout/stderr flushes through the logging system
rm -rf "${TMP_DIR}"
sleep 3
}
trap clean EXIT
function main() {
local name="${1:?name is required}"
local version="${2:?version is required}"
local os_name="${OS_NAME:-linux}"
local os_arch="${OS_ARCH:-$(dpkg --print-architecture)}"
local os_flavour="${OS_FLAVOUR:-${ID}-${VERSION_ID}}"
local stack_path="/opt/drycc/${name}"
local stack_name="${name}-${version}-${os_name}-${os_arch}-${os_flavour}"
local stack_filename="${stack_name}".tar.gz
local stack_download_url="${STACK_DOWNLOAD_URL}/${name}/${stack_filename}"
echo "Downloading $stack_filename package"
if [ -f "${STACK_CACHE_ROOT}/${stack_filename}" ]; then
echo "${STACK_CACHE_ROOT}/${stack_filename} already exists, skipping download."
cp "${STACK_CACHE_ROOT}/${stack_filename}" "${TMP_DIR}/${stack_filename}"
rm "${STACK_CACHE_ROOT}/${stack_filename}"
else
curl --silent --show-error --fail "${stack_download_url}" -o "${TMP_DIR}/${stack_filename}"
fi
echo "Generate installation directory: ${stack_path}"
if [ -d "${stack_path}" ]; then
echo "Clean up the directory: ${stack_path}"
rm -rf "${stack_path}"
fi
mkdir -p "${stack_path}"
echo "Extract data to a temporary directory: ${TMP_DIR}"
tar --directory "${TMP_DIR}" --extract --gunzip --file "${TMP_DIR}"/"${stack_filename}" --no-same-owner
packages=$(tr '\t\n' ' ' < "${TMP_DIR}/meta/dependencies" | tr -s ' ')
if [[ -n "${packages:+x}" ]]; then
echo "Install system packages: ${packages}"
install-packages "$packages"
fi
echo "Install stack: ${name} ${version}"
"${TMP_DIR}"/meta/preinstall
cp -rf "${TMP_DIR}"/data/* "${stack_path}"
"${TMP_DIR}"/meta/postinstall
echo "Stack installation completed"
}
main "$@"