forked from filebrowser/filebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwizard.sh
executable file
·322 lines (262 loc) · 6.3 KB
/
wizard.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/sh
set -e
untracked="(untracked)"
REPO=$(cd $(dirname $0); pwd)
LINT="false"
BUILD="false"
PUSH_LATEST="false"
RELEASE=""
debugInfo () {
echo "Repo: $REPO"
echo "Will lint: $LINT"
echo "Will build: $BUILD"
echo "Will release: $RELEASE"
echo "Will push latest docker: $PUSH_LATEST"
echo "Use Docker: $USE_DOCKER"
echo "Is CI: $CI"
}
dockerLogin () {
if [ "$CI" = "true" ]; then
gpg --batch --gen-key <<-EOF
%echo Generating a standard key
Key-Type: DSA
Key-Length: 1024
Subkey-Type: ELG-E
Subkey-Length: 1024
Name-Real: Meshuggah Rocks
Name-Email: [email protected]
Expire-Date: 0
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOF
key=$(gpg --no-auto-check-trustdb --list-secret-keys | grep ^sec | cut -d/ -f2 | cut -d" " -f1)
pass init $key
if [ "$(command -v docker-credential-pass)" = "" ]; then
docker run --rm -itv /usr/local/bin:/src filebrowser/dev sh -c "cp /go/bin/docker-credential-pass /src"
fi
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
fi
}
dockerLogout () {
if [ "$CI" = "true" ]; then
docker logout
fi
}
dockerPushLatest () {
docker build -t filebrowser/filebrowser .
dockerLogin
docker push filebrowser/filebrowser
dockerLogout
}
dockerPushTag () {
dockerLogin
for tag in `echo $(docker images filebrowser/filebrowser* | awk -F ' ' '{print $1 ":" $2}') | cut -d ' ' -f2-`; do
if [ "$tag" = "REPOSITORY:TAG" ]; then break; fi
docker push $tag
done
dockerLogout
}
installRice () {
if ! [ -x "$(command -v rice)" ]; then
go get github.com/GeertJohan/go.rice/rice
fi
}
buildAssets () {
installRice
cd $REPO/frontend
if [ -d "dist" ]; then
rm -rf dist/*
fi;
yarn install
yarn build
echo "Run rice"
cd $REPO/http
rice embed-go
}
updateVersion () {
from=$1
to=$2
echo "Updating version from \"$from\" to \"$to\""
sed -i.bak "s|$from|$to|g" $REPO/version/version.go
}
buildBinary () {
cd $REPO
go get -v ./...
updateVersion $untracked "($COMMIT_SHA)"
echo "Build CLI"
CGO_ENABLED=0 go build -a -o filebrowser
updateVersion "($COMMIT_SHA)" $untracked
}
lint () {
cd $REPO
if [ "$USE_DOCKER" != "" ]; then
$(command -v winpty) docker run --rm -itv "/$(pwd)://src" -w "//src" filebrowser/dev sh -c "\
go get -v ./... && \
golangci-lint run -v"
else
golangci-lint run -v
fi
}
pushRicebox () {
COMMIT_SHA="$(git rev-parse --verify HEAD | cut -c1-8)"
cd $REPO
eval `ssh-agent -s`
openssl aes-256-cbc -K $encrypted_9ca81b5594f5_key -iv $encrypted_9ca81b5594f5_iv -in ./.ci/deploy_key.enc -d | ssh-add -
git clone [email protected]:filebrowser/caddy caddy
cd caddy
cp ../http/rice-box.go ./
sed -i 's/package http/package caddy/g' ./rice-box.go
git checkout -b update-rice-box origin/master
git config --local user.name "Filebrowser Bot"
git config --local user.email "[email protected]"
git commit -am "update rice-box $COMMIT_SHA"
if [ $(git tag | grep "$TRAVIS_TAG" | wc -l) -ne 0 ]; then
git tag -d "$TRAVIS_TAG"
fi
git tag "$TRAVIS_TAG"
if [ "$(git ls-remote --heads origin update-rice-box)" != "" ]; then
git push -u origin update-rice-box
else
git push origin +update-rice-box
fi
if [ "$(git ls-remote --heads origin update-rice-box)" != "" ]; then
git push origin "$TRAVIS_TAG"
else
git push origin :"$TRAVIS_TAG"
git push origin "$TRAVIS_TAG"
fi
}
ciRelease () {
docker run --rm -t \
-v $(pwd):/src \
-w /src \
-v /var/run/docker.sock:/var/run/docker.sock \
filebrowser/dev \
sh -c "\
go get ./... && \
goreleaser \
"
dockerPushTag
pushRicebox
}
build () {
cd $REPO
if [ -d http/"rice-box.go" ]; then
rm -rf http/rice-box.go
fi
if [ "$USE_DOCKER" != "" ]; then
if [ -d "frontend/dist" ]; then
rm -rf frontend/dist
fi;
if [ -f "http/rice-box.go" ]; then
rm -f http/rice-box.go
fi;
if [ "$(command -v git)" != "" ]; then
COMMIT_SHA="$(git rev-parse HEAD | cut -c1-8)"
else
COMMIT_SHA="untracked"
fi
$(command -v winpty) docker run --rm -it \
-u "$(id -u)" \
-v /$(pwd):/src:z \
-w //src \
-e COMMIT_SHA=$COMMIT_SHA \
-e HOME="//tmp" \
-e GOPATH=//tmp/gopath \
filebrowser/dev \
sh -c "./wizard.sh -b"
else
buildAssets
buildBinary
fi
}
release () {
cd $REPO
echo "> Checking semver format"
if [ $# -ne 1 ]; then
echo "This release script requires a single argument corresponding to the semver to be released. See semver.org"
exit 1
fi
semver=$(echo "$1" | grep -P '^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)')
if [ $? -ne 0 ]; then
echo "Not valid semver format. See semver.org"
exit 1
fi
echo "> Checking matching $semver in frontend submodule"
cd frontend
git fetch --all
if [ $(git tag | grep "$semver" | wc -l) -eq 0 ]; then
echo "Tag $semver does not exist in submodule 'frontend'. Tag it and run this script again."
exit 1
fi
set +e
git rev-parse --verify --quiet release
exitcode=$?
set -e
if [ $exitcode -ne 0 ]; then
git checkout -b release "$semver"
else
git checkout release
git reset --hard "$semver"
fi
cd ..
echo "> Updating submodule ref to $semver"
updateVersion $untracked $1
git commit -am "chore: version $semver"
git tag "$1"
git push
git push --tags
echo "> Commiting untracked version notice..."
updateVersion $1 $untracked
git commit -am "chore: setting untracked version [ci skip]"
git push
echo "> Done!"
}
usage() {
echo "Usage: $0 [-l] [-b] [-p] [-r <string>]" 1>&2;
exit 1;
}
DEBUG="false"
while getopts "pdlbr:" o; do
case "${o}" in
l)
LINT="true"
;;
b)
BUILD="true"
;;
r)
RELEASE=${OPTARG}
;;
p)
PUSH_LATEST="true"
;;
d)
DEBUG="true"
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ "$DEBUG" = "true" ]; then
debugInfo
fi
if [ "$LINT" = "true" ]; then
lint
fi
if [ "$BUILD" = "true" ]; then
build
fi
if [ "$PUSH_LATEST" = "true" ]; then
dockerPushLatest
fi
if [ "$RELEASE" != "" ]; then
if [ "$CI" = "true" ]; then
ciRelease
else
release $RELEASE
fi
fi