-
-
Notifications
You must be signed in to change notification settings - Fork 490
/
update.sh
executable file
·153 lines (137 loc) · 6.08 KB
/
update.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
#!/bin/bash
# args: privkey, privkey pwd, tags or dev
# config
root=`pwd`
build="composer-src"
buildscript="bin/compile"
buildphar="composer.phar"
target="web"
repo="https://github.com/composer/composer.git"
composer="composer"
privkeypath="$2"
privkeypwd="$3"
if [ "" == "$1" ]
then
echo "Missing arg1: target (dev or tags)"
exit 1
fi
if [ "" == "$2" ]
then
echo "Missing arg2: path to private key"
exit 1
fi
if [ "" == "$3" ]
then
if [ "tags" == "$1" ]
then
echo -n 'Password: '
stty -echo
read -r privkeypwd
stty echo
if [ "" == "$privkeypwd" ]
then
echo ''
echo 'No pwd pasted in'
exit 1
fi
echo ''
echo 'Building versions'
else
echo "Missing arg3: password for private key"
exit 1
fi
fi
set -euo pipefail
# init
if [ ! -d "$root/$build" ]
then
cd $root
git clone $repo $build
fi
cd "$root/$build"
# update main
git fetch -q origin
git fetch --tags -q origin
git checkout main -q --force
git rebase -q origin/main > /dev/null
version=`git log --pretty="%H" -n1 HEAD`
touch "$root/$target/version"
# create latest dev build
if [ "dev" == "$1" ]
then
if [ ! -f "$root/$target/$version" -o "$version" != "`cat \"$root/$target/version\"`" ]
then
rm -rf vendor && \
$composer install -q --no-dev && \
php -d phar.readonly=0 $buildscript && \
touch --date="`git log -n1 --pretty=%ci HEAD`" "$buildphar" && \
php "$root/bin/sign.php" "$buildphar" "$root/$privkeypath" "$privkeypwd" && \
sha256sum "$buildphar" > "$buildphar.sha256sum" && \
git reset --hard -q $version && \
mv "$buildphar.sig" "$root/$target/$buildphar.sig" && \
mv "$buildphar.sha256sum" "$root/$target/$buildphar.sha256sum" && \
mv "$buildphar" "$root/$target/$buildphar" && \
echo $version > "$root/$target/version_new" && \
mv "$root/$target/version_new" "$root/$target/version"
fi
fi
# create tagged releases
for version in `git tag`; do
if [ ! -f "$root/$target/download/$version/$buildphar" ]
then
if [ "tags" != "$1" ]
then
echo "$version was found but not built, build should be ran manually to get the correct signature"
else
if [[ "$version" == 2.2* ]]; then
php="php8.0"
else
php="php"
fi
mkdir -p "$root/$target/download/$version/"
git checkout $version -q && \
rm -rf vendor && \
$composer install -q --no-dev && \
$php -d phar.readonly=0 $buildscript && \
touch --date="`git log -n1 --pretty=%ci $version`" "$buildphar" && \
php "$root/bin/sign.php" "$buildphar" "$root/$privkeypath" "$privkeypwd" && \
git reset --hard -q $version && \
mv "$buildphar.sig" "$root/$target/download/$version/$buildphar.sig" && \
mv "$buildphar" "$root/$target/download/$version/$buildphar"
cd "$root/$target/download/$version" && sha256sum "$buildphar" > "$buildphar.sha256sum" && cd -
echo "$target/download/$version/$buildphar (and .sig) was just built and should be committed to the repo"
fi
else
touch --date="`git log -n1 --pretty=%ci $version`" "$root/$target/download/$version/$buildphar"
fi
done
git checkout main -q --force
lastStableVersion=$(ls "$root/$target/download" | grep -E '^2\.([3-9]|[0-9]{2})\.[0-9]+$' | xargs -I@ git log --format=format:"%ai @%n" -1 @ | sort -r | head -1 | awk '{print $4}')
lastStableV1Version=$(ls "$root/$target/download" | grep -E '^1\.[0-9.]+$' | xargs -I@ git log --format=format:"%ai @%n" -1 @ | sort -r | head -1 | awk '{print $4}')
lastStableV22Version=$(ls "$root/$target/download" | grep -E '^2\.2\.[0-9.]+$' | xargs -I@ git log --format=format:"%ai @%n" -1 @ | sort -r | head -1 | awk '{print $4}')
lastV2Version=$(ls "$root/$target/download" | grep -E '^2\.([3-9]|[0-9]{2})' | xargs -I@ git log --format=format:"%ai @%n" -1 @ | sort -r | head -1 | awk '{print $4}')
lastSnapshot=$(head -c40 "$root/$target/version")
if [ "$(ls "$root/$target/download" | grep -E '^2\.[0-9.]+$')" == "" ]
then
# Use preview so long as there is no stable version
lastStableV2Version=$(ls "$root/$target/download" | grep -E '^2\.' | xargs -I@ git log --format=format:"%ai @%n" -1 @ | sort -r | head -1 | awk '{print $4}')
lastStableV2VersionPath="/download/$lastStableV2Version/composer.phar"
else
lastStableV2Version=$(ls "$root/$target/download" | grep -E '^2\.([3-9]|[0-9]{2})\.[0-9]+$' | xargs -I@ git log --format=format:"%ai @%n" -1 @ | sort -r | head -1 | awk '{print $4}')
lastStableV2VersionPath="/download/$lastStableV2Version/composer.phar"
fi
{
# TODO add "eol":true to a version to mark eol releases and warn users
read -r -d '' versions << EOM
{
"stable": [{"path": "/download/$lastStableVersion/composer.phar", "version": "$lastStableVersion", "min-php": 70205},{"path": "/download/$lastStableV22Version/composer.phar", "version": "$lastStableV22Version", "min-php": 50300}],
"preview": [{"path": "/download/$lastV2Version/composer.phar", "version": "$lastV2Version", "min-php": 70205},{"path": "/download/$lastStableV22Version/composer.phar", "version": "$lastStableV22Version", "min-php": 50300}],
"snapshot": [{"path": "/composer.phar", "version": "$lastSnapshot", "min-php": 70205},{"path": "/download/$lastStableV22Version/composer.phar", "version": "$lastStableV22Version", "min-php": 50300}],
"1": [{"path": "/download/$lastStableV1Version/composer.phar", "version": "$lastStableV1Version", "min-php": 50300}],
"2": [{"path": "$lastStableV2VersionPath", "version": "$lastStableV2Version", "min-php": 70205},{"path": "/download/$lastStableV22Version/composer.phar", "version": "$lastStableV22Version", "min-php": 50300}],
"2.2": [{"path": "/download/$lastStableV22Version/composer.phar", "version": "$lastStableV22Version", "min-php": 50300}]
}
EOM
} || true
echo "$versions" > "$root/$target/versions_new" && mv "$root/$target/versions_new" "$root/$target/versions"
rm -f "$root/$target/stable"