-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.sh
executable file
·120 lines (98 loc) · 2.89 KB
/
deploy.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
#!/bin/bash
BUCKET="syncrobit-firmware"
S3CMD="s3cmd -c ${HOME}/.s3cfg-chameleon"
function exit_usage() {
echo "Usage: $0 <upload|promote-beta|promote-stable|unrelease-stable|unrelease-beta> [image.xz]"
exit 1
}
if [[ -z "$1" ]]; then
exit_usage
fi
cmd=$1
image_path=$2
base_path=$(dirname $0)
if [[ -z "$2" ]]; then
if [[ ${cmd} == release-* ]] || [[ ${cmd} == upload ]] || [[ ${cmd} == promote-beta ]]; then
exit_usage
fi
fi
function s3upload() {
# $1 - prefix
# $2 - file
${S3CMD} put --acl-public --guess-mime-type $2 s3://${BUCKET}/$1/$(basename $2)
}
function s3delete() {
# $1 - prefix
# $2 - file
${S3CMD} del s3://${BUCKET}/$1/$2
}
function s3copy() {
# $1 - prefix
# $2 - src_file
# $3 - dst_file
${S3CMD} cp s3://${BUCKET}/$1/$2 s3://${BUCKET}/$1/$3
}
function make_latest() {
# $1 - path
# $2 - version
echo "{"
echo " \"path\": \"$1\","
echo " \"version\": \"$2\","
echo " \"date\": \"$(date +%Y-%m-%d)\""
echo "}"
}
function get_image_params() {
# $1 - image name (e.g. chameleonos-cham-raspberrypi64-2021.03.14.1.img.xz)
image_name=$1
image_name=${image_name:0:-7} # strip trailing ".img.xz"
IFS=-; image_params=(${image_name}); unset IFS
echo "${image_params[@]}"
}
function main() {
if [[ -n "${image_path}" ]]; then
image_name=$(basename ${image_path})
image_params=($(get_image_params ${image_name}))
os_name=${image_params[0]}
os_prefix=${image_params[1]}
platform=${image_params[2]}
version=${image_params[3]}
fi
case ${cmd} in
upload)
if [[ "${os_prefix}" != "${THINGOS_PREFIX}" ]]; then
echo "Invalid OS image prefix: ${os_prefix}"
exit 1
fi
s3upload ${THINGOS_PREFIX} ${image_path}
;;
promote-beta)
if [[ "${os_prefix}" != "${THINGOS_PREFIX}" ]]; then
echo "Invalid OS image prefix: ${os_prefix}"
exit 1
fi
latest_file="latest_beta_info.json"
path="/${THINGOS_PREFIX}/${os_name}-${os_prefix}-"'${platform}'"-${version}.img.xz"
make_latest "${path}" ${version} > /tmp/${latest_file}
s3upload ${THINGOS_PREFIX} /tmp/${latest_file}
;;
promote-stable)
s3copy ${THINGOS_PREFIX} latest_beta_info.json latest_stable_info.json
;;
unrelease-stable | unrelease-beta)
if [[ ${cmd} == *stable ]]; then
latest_file="latest_stable_info.json"
else
latest_file="latest_beta_info.json"
fi
s3delete ${THINGOS_PREFIX} ${latest_file}
;;
esac
}
if [[ -z "${VENDOR}" ]]; then
echo "Variable VENDOR is unset"
exit 1
fi
set -a
source ${base_path}/vendors/${VENDOR}.conf
set +a
main