-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·165 lines (128 loc) · 4.45 KB
/
entrypoint.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env bash
#
# Environment variables:
# They are created from an input in a workflow file or a default value by
# GitHub, with the name INPUT_<VARIABLE_NAME>. Cf.,
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions.
#
# The following environment variables correspond to the input identifiers in
# action.yml.
#
# INPUT_RELEASE_NAME
# INPUT_RELEASE_TYPE
# INPUT_PERSIST_DIR_ON_DEVICE
# INPUT_ARTIFACTS_DIR
# INPUT_ROOTFS_IMG_PATH
# INPUT_ZIP_ARCHIVE_DIR
# INPUT_BASE_INSTALL_PATH_ON_DEVICE
# INPUT_PROJECT_ACCESS_TOKEN
# INPUT_SIGNING_KEY_MANAGEMENT
# INPUT_SIGNING_KEY
# INPUT_SIGNING_KEY_PASSWORD
# INPUT_BACKEND_URL
#
set -euxo pipefail
SCRIPT_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly SCRIPT_DIR
TRH_BINARY_PATH="${SCRIPT_DIR}/trh"
readonly TRH_BINARY_PATH
TRH_DOWNLOAD_URL="https://downloads.thistle.tech/embedded-client/1.3.0/trh-1.3.0-x86_64-unknown-linux-musl.gz"
readonly TRH_DOWNLOAD_URL
# Set environment variables
export THISTLE_TOKEN="${INPUT_PROJECT_ACCESS_TOKEN}"
[ -z "${INPUT_SIGNING_KEY_MANAGEMENT}" ] && err "No signing key management provided"
[ "${INPUT_SIGNING_KEY_MANAGEMENT}" = "local" ] || [ "${INPUT_SIGNING_KEY_MANAGEMENT}" = "remote" ] || {
err "Unknown signing key management: ${INPUT_SIGNING_KEY_MANAGEMENT}"
}
[ "${INPUT_SIGNING_KEY_MANAGEMENT}" = "local" ] && {
export THISTLE_KEY="${HOME}/.minisign/minisign.key"
export THISTLE_KEY_PASS="${INPUT_SIGNING_KEY_PASSWORD}"
}
[ -z "${INPUT_BACKEND_URL}" ] || export THISTLE_BACKEND="${INPUT_BACKEND_URL}"
# Set TRH command based on signing method
TRH_COMMAND="${TRH_BINARY_PATH} --signing-method=${INPUT_SIGNING_KEY_MANAGEMENT}"
readonly TRH_COMMAND
# Functions
err() {
echo -e "$*"
exit 1
}
download_trh() {
curl -A "curl (thistletech/ota-release-action)" -L -o /tmp/trh.gz "${TRH_DOWNLOAD_URL}"
gunzip -c /tmp/trh.gz > "${TRH_BINARY_PATH}"
chmod +x "${TRH_BINARY_PATH}"
"${TRH_BINARY_PATH}" --version
}
get_manifest_template_hack() {
# Hack alert: Need to do this to get a manifest template
local persist_dir="${INPUT_PERSIST_DIR_ON_DEVICE:-}"
[ -z "${persist_dir}" ] && err "No persist directory provided"
if [ "${INPUT_SIGNING_KEY_MANAGEMENT}" = "local" ]; then
mkdir -p "$(dirname "${THISTLE_KEY}")"
echo "${INPUT_SIGNING_KEY}" > "${THISTLE_KEY}"
fi
eval "${TRH_COMMAND}" init --persist="${persist_dir}" > /dev/null
}
file_release() {
get_manifest_template_hack
local release_name="${INPUT_RELEASE_NAME:-}"
local artifacts_dir="${INPUT_ARTIFACTS_DIR:-}"
[ -z "${artifacts_dir}" ] && err "No artifacts directory provided"
local base_install_path="${INPUT_BASE_INSTALL_PATH_ON_DEVICE:-}"
[ -z "${base_install_path}" ] && err "No base install path provided"
eval "${TRH_COMMAND}" prepare --target="\"${artifacts_dir}\"" --file-base-path="\"${base_install_path}\""
if [ -n "${release_name}" ]; then
eval "${TRH_COMMAND}" release --name="\"${release_name}\""
else
eval "${TRH_COMMAND}" release
fi
echo "done"
}
rootfs_release() {
get_manifest_template_hack
local release_name="${INPUT_RELEASE_NAME:-}"
local rootfs_img_path="${INPUT_ROOTFS_IMG_PATH:-}"
[ -z "${rootfs_img_path}" ] && err "No rootfs image path provided"
eval "${TRH_COMMAND}" prepare --target="\"${rootfs_img_path}\""
if [ -n "${release_name}" ]; then
eval "${TRH_COMMAND}" release --name="\"${release_name}\""
else
eval "${TRH_COMMAND}" release
fi
echo "done"
}
zip_archive_release() {
get_manifest_template_hack
local release_name="${INPUT_RELEASE_NAME:-}"
local zip_archive_dir="${INPUT_ZIP_ARCHIVE_DIR:-}"
[ -z "${zip_archive_dir}" ] && err "No zip archive directory provided"
local base_install_path="${INPUT_BASE_INSTALL_PATH_ON_DEVICE:-}"
[ -z "${base_install_path}" ] && err "No base install path provided"
eval "${TRH_COMMAND}" prepare --zip-target --target="\"${zip_archive_dir}\"" --file-base-path="\"${base_install_path}\""
if [ -n "${release_name}" ]; then
eval "${TRH_COMMAND}" release --name="\"${release_name}\""
else
eval "${TRH_COMMAND}" release
fi
echo "done"
}
do_it() {
local release_type="${INPUT_RELEASE_TYPE:-}"
[ -z "${release_type}" ] && err "No release type provided"
download_trh
case "${INPUT_RELEASE_TYPE}" in
"file")
file_release
;;
"rootfs")
rootfs_release
;;
"zip_archive")
zip_archive_release
;;
*)
err "Unknown release type: ${INPUT_RELEASE_TYPE}"
;;
esac
}
do_it