-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.sh
More file actions
executable file
·181 lines (147 loc) · 2.91 KB
/
Copy pathbundle.sh
File metadata and controls
executable file
·181 lines (147 loc) · 2.91 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#! /usr/bin/env bash
set -e
shopt -s nullglob
assets=""
libdir="$(realpath $(dirname $(readlink -f ${BASH_SOURCE[0]})))"
outdir=bundles
userconfigfile="production.yml"
while [[ $# -gt 0 ]]; do
case $1 in
--pkg-name)
pkgname="$2"
shift
shift
;;
--pkg-dist)
pkgdist="$2"
shift
shift
;;
--pkg-version)
pkgver="$2"
shift
shift
;;
--output-directory)
outdir="$2"
shift
shift
;;
--target-user)
targetuser="$2"
shift
shift
;;
--target-instance)
targetinstance="$2"
shift
shift
;;
--target-domain)
targetdomain="$2"
shift
shift
;;
--assets-manifest)
assetsmanifest="$2"
shift
shift
;;
--configuration-file)
userconfigfile="$2"
shift
shift
;;
--admin-email)
adminemail="$2"
shift
shift
;;
--)
shift
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
assets="${assets} $1"
shift
;;
esac
done
# validation
if [ -z "${pkgname}" ]; then
echo "--pkg-name required" >&2
exit 1
fi
if [ -z "${pkgver}" ]; then
echo "--pkg-version required" >&2
exit 1
fi
if [ -z "${pkgdist}" ]; then
echo "--pkg-dist required" >&2
exit 1
fi
if [ -z "${targetuser}" ]; then
echo "--target-user required" >&2
exit 1
fi
if [ -z "${targetinstance}" ]; then
echo "--target-instance required" >&2
exit 1
fi
if [ -z "${targetdomain}" ]; then
echo "--target-domain required" >&2
exit 1
fi
if [ ! -f "${userconfigfile}" ]; then
echo "cannot find ${userconfigfile}, please provide this file or specify \
another file with --configuration-file option." >&2
fi
if [ -z "${adminemail}" ]; then
echo "--admin-email required" >&2
exit 1
fi
# setup vars
bundlename=${pkgname}-bundle-${pkgver}
bundledir=${outdir}/${bundlename}
# create a temporary directory
mkdir -p ${bundledir}
# cleanup the pre-existing files
if [ -d ${bundledir} ]; then
rm -fr ${bundledir}/*
rm -fr ${bundledir}/.*
fi
# copy python distribution
cp ${pkgdist} ${bundledir}
# assets
if [ -n "${assets}" ]; then
mkdir -p ${bundledir}/assets
cp ${assets} ${bundledir}/assets
fi
if [ -n "${assetsmanifest}" ]; then
cp ${assetsmanifest} ${bundledir}/assets-manifest.json
fi
# install.sh
cp ${libdir}/target-install.sh ${bundledir}/install.sh
chmod +x ${bundledir}/install.sh
# user configuration file
cp ${userconfigfile} ${bundledir}
# vars
echo -n "\
pydist=$(basename ${pkgdist})
pypkg=${pkgname}
user=${targetuser}
instance=${targetinstance}
domain=${targetdomain}
userconfigfile=${userconfigfile}
adminemail=${adminemail}
" > ${bundledir}/.vars
# bundle
outfile=${outdir}/${bundlename}.tar.gz
tar -cv -C ${outdir} -f ${outfile} ${bundlename}
# cleanup
rm -r ${outdir}/${bundlename}
# report
echo "bundle successfully generated: ${outfile}"