This repository has been archived by the owner on Oct 16, 2022. It is now read-only.
forked from dnschneid/crouton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·82 lines (71 loc) · 2.35 KB
/
release.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
#!/bin/sh -e
# Copyright (c) 2016 The crouton Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
# Generates a release in the releases/ directory (which should be a checkout of
# the releases branch of the same repo) and pushes it.
USAGE="Usage: ${0##*/} [-f] bundle [..]
-f Hard-reset the releases branch in case of unpushed releases."
FORCE=''
# CD into the repo's root directory
dir="`readlink -f "$0"`"
cd "${dir%/*}/.."
# Import common functions
. installer/functions
if [ "$1" = '-f' ]; then
FORCE=y
shift
fi
if [ "$#" = 0 ]; then
error 2 "$USAGE"
fi
# Check the releases directory and update, or create it if necessary
if [ -d releases/.git ]; then
if ! grep -q 'releases$' releases/.git/HEAD; then
error 1 'releases/ is not in the releases branch.'
fi
if ! awk "/'releases'/{print \$1}" releases/.git/FETCH_HEAD | \
diff -q releases/.git/refs/heads/releases - >/dev/null; then
echo 'releases/ is ahead of or not up-to-date with remote' 1>&2
if [ -z "$FORCE" ]; then
exit 1
fi
fi
git -C releases fetch origin releases
git -C releases reset --hard origin/releases
elif [ -e releases ]; then
error 1 "releases/ is not a git repo"
else
url="`git remote -v | awk '$1=="origin" && $3=="(fetch)" {print $2}'`"
git clone --single-branch --branch releases --reference . "$url" releases
fi
# Apply the releases
for bundle in "$@"; do
bundle="${bundle##*/}"
if [ ! -f "$bundle" ]; then
error 1 "$bundle bundle does not exist"
fi
version="`sh "$bundle" -V`"
if [ "$version" = "${version#crouton*:}" ]; then
error 1 "$bundle bundle is invalid"
fi
branch="${version#*~}"
branch="${branch%:*}"
dest="${branch#master}"
dest="crouton${dest:+-}$dest"
# Compare the current release to avoid duplicates
if [ -f "releases/$dest" ] && \
sh "releases/$dest" -V | grep -q "${version#*~}"; then
echo "Release already current: `sh "$bundle" -V`"
continue
fi
# Copy it in and make a commit
cp -fv "$bundle" "releases/$dest"
git -C releases add "$dest"
git -C releases commit -m "$version"
done
# Push the resulting releases
git -C releases push origin releases
git -C releases fetch origin releases
exit 0