-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstack-utils
More file actions
executable file
·71 lines (60 loc) · 1.87 KB
/
stack-utils
File metadata and controls
executable file
·71 lines (60 loc) · 1.87 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
66
67
68
69
70
71
#!/bin/bash
set -e
shopt -s expand_aliases
alias gzip="gzip -n -9"
. /etc/os-release
export GO_VERSION=1.22
export RUBY_VERSION=3.3
export STACK_NAME="${STACK_NAME:?name is required}"
export STACK_VERSION="${STACK_VERSION:?version is required}"
export OS_NAME="${OS_NAME:-linux}"
export OS_ARCH=$(dpkg --print-architecture)
export OS_FLAVOUR="${OS_FLAVOUR:-${ID}-${VERSION_ID}}"
export TARNAME="${STACK_NAME}-${STACK_VERSION}-${OS_NAME}-${OS_ARCH}-${OS_FLAVOUR}"
export DATA_DIR=/workspace/"${TARNAME}"/data
export META_DIR=/workspace/"${TARNAME}"/meta
export PROFILE_DIR=/workspace/"${TARNAME}"/data/profile.d
_is_sourced() {
# https://unix.stackexchange.com/a/215279
[ "${#FUNCNAME[@]}" -ge 2 ] \
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \
&& [ "${FUNCNAME[1]}" = 'source' ]
}
function generate-stack-template() {
mkdir -p "${META_DIR}"
mkdir -p "${DATA_DIR}"
mkdir -p "${PROFILE_DIR}"
touch "${META_DIR}"/dependencies
touch "${META_DIR}"/preinstall
touch "${META_DIR}"/postinstall
chmod +x "${META_DIR}"/preinstall "${META_DIR}"/postinstall
}
function generate-stack-package() {
dist_dir="${1:? miss dist dir}"/"${STACK_NAME}"
mkdir -p "${dist_dir}"
tar --numeric-owner -czf "${dist_dir}"/${TARNAME}.tar.gz -C /workspace/"${TARNAME}" . --transform='s,^./,,'
rm -rf /workspace/"${TARNAME}"
}
function generate-stack-path() {
cat << EOF > ${PROFILE_DIR}/${STACK_NAME}.sh
export PATH="/opt/drycc/${STACK_NAME}/bin:\$PATH"
EOF
}
function generate-stack-dependencies() {
scanelp "${DATA_DIR}" | awk -F ":" '{print $1}' >> ${META_DIR}/dependencies
sort ${META_DIR}/dependencies -u -o ${META_DIR}/dependencies
}
function source-stack-path() {
. "${PROFILE_DIR}"/"${STACK_NAME}".sh
}
function build-stack() {
generate-stack-template
build || exit 1
generate-stack-dependencies
generate-stack-package "$1"
}
if ! _is_sourced; then
action=$1
shift 1
$action "$@"
fi