-
Notifications
You must be signed in to change notification settings - Fork 23
/
generate-single-repo.sh
executable file
·234 lines (188 loc) · 6.26 KB
/
generate-single-repo.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
#! /bin/sh
# Author: Boris Pek <[email protected]>
# License: GPLv2 or later
# Created: 2012-02-13
# Updated: 2024-05-05
# Version: N/A
set -e
export SNAPSHOTS_DIR="$(dirname $(realpath -s ${0}))"
export MAIN_DIR="$(realpath -s ${SNAPSHOTS_DIR}/..)"
PSI_URL=https://github.com/psi-im/psi.git
PLUGINS_URL=https://github.com/psi-im/plugins.git
PSIMEDIA_URL=https://github.com/psi-im/psimedia.git
RESOURCES_URL=https://github.com/psi-im/resources.git
SNAPSHOTS_URL=https://github.com/psi-plus/psi-plus-snapshots.git
SNAPSHOTS_RAW_URL=https://raw.github.com/psi-plus/psi-plus-snapshots
# Test Internet connection:
host github.com > /dev/null
cd "${SNAPSHOTS_DIR}"
if [ "${1}" = "push" ]; then
git push
git push --tags
exit 0
fi
DownloadRepo()
{
echo "Downloading ${MAIN_DIR}/${MOD}"
cd "${MAIN_DIR}"
git clone "${URL}"
echo
}
UpdateRepo()
{
echo "Updating ${MAIN_DIR}/${MOD}"
cd "${MAIN_DIR}/${MOD}"
git checkout HEAD .
git pull --all --prune -f
echo
}
UpdateSubmodules()
{
cd "${MAIN_DIR}/${MOD}"
git submodule init
git submodule update
echo
}
UpdateOrDownloadRepo()
{
if [ -d "${MAIN_DIR}/${MOD}" ]; then
UpdateRepo
else
DownloadRepo
fi
}
MOD=$(basename "${SNAPSHOTS_DIR}")
URL="$(git remote -v | grep '(fetch)' | awk '{ print $2 }')"
if [ "${URL}" = "${SNAPSHOTS_URL}" ]; then
UpdateRepo
else
echo "Error! Unknown URL = ${URL}"
exit 1
fi
MOD=psi
URL="${PSI_URL}"
UpdateOrDownloadRepo
UpdateSubmodules
MOD=plugins
URL="${PLUGINS_URL}"
UpdateOrDownloadRepo
MOD=psimedia
URL="${PSIMEDIA_URL}"
UpdateOrDownloadRepo
MOD=resources
URL="${RESOURCES_URL}"
UpdateOrDownloadRepo
cd "${SNAPSHOTS_DIR}"
echo "Checking for updates..."
PSI_OLD_HASH=$(cd "${SNAPSHOTS_DIR}" && git show -s --pretty='format:%B' | sed -ne 's/^\* psi: \(.*\)$/\1/p')
PLUGINS_OLD_HASH=$(cd "${SNAPSHOTS_DIR}" && git show -s --pretty='format:%B' | sed -ne 's/^\* plugins: \(.*\)$/\1/p')
PSIMEDIA_OLD_HASH=$(cd "${SNAPSHOTS_DIR}" && git show -s --pretty='format:%B' | sed -ne 's/^\* psimedia: \(.*\)$/\1/p')
RESOURCES_OLD_HASH=$(cd "${SNAPSHOTS_DIR}" && git show -s --pretty='format:%B' | sed -ne 's/^\* resources: \(.*\)$/\1/p')
PSI_NEW_HASH=$(cd "${MAIN_DIR}/psi" && git show -s --pretty='format:%h')
PLUGINS_NEW_HASH=$(cd "${MAIN_DIR}/plugins" && git show -s --pretty='format:%h')
PSIMEDIA_NEW_HASH=$(cd "${MAIN_DIR}/psimedia" && git show -s --pretty='format:%h')
RESOURCES_NEW_HASH=$(cd "${MAIN_DIR}/resources" && git show -s --pretty='format:%h')
if [ "${PSI_OLD_HASH}" = "${PSI_NEW_HASH}" ] && \
[ "${PLUGINS_OLD_HASH}" = "${PLUGINS_NEW_HASH}" ] && \
[ "${PSIMEDIA_OLD_HASH}" = "${PSIMEDIA_NEW_HASH}" ] && \
[ "${RESOURCES_OLD_HASH}" = "${RESOURCES_NEW_HASH}" ]; then
echo "Updating is not required!"
git checkout HEAD . 2> /dev/null
echo
exit 0
fi
echo "Updating is required!"
echo
cd "${SNAPSHOTS_DIR}"
echo "Starting Psi+ update..."
find . -type f | \
grep -v "^\./\.git" | \
grep -v "^\./generate-single-repo.sh$" | \
grep -v "^\./README$" | \
while read var; do rm "$var"; done
find . -depth -type d -empty -exec rmdir {} \;
echo "* Directory is cleaned."
# Some paranoid checks
for FILE in generate-single-repo.sh README .gitignore; do
if [ ! -e "${SNAPSHOTS_DIR}/${FILE}" ]; then
wget -c "${SNAPSHOTS_RAW_URL}/master/${FILE}"
fi
done
chmod uog+x generate-single-repo.sh
cp -f "${SNAPSHOTS_DIR}/README" "${MAIN_DIR}/README"
cp -f "${SNAPSHOTS_DIR}/.gitignore" "${MAIN_DIR}/.gitignore"
rsync -a --del "${MAIN_DIR}/psi/" "${SNAPSHOTS_DIR}/" \
--exclude=".git*" \
--exclude="/builddir*" \
--exclude="/generate-single-repo.sh" \
--exclude="/README.md" \
--exclude="/README"
mv "${MAIN_DIR}/README" "${SNAPSHOTS_DIR}/README"
mv "${MAIN_DIR}/.gitignore" "${SNAPSHOTS_DIR}/.gitignore"
echo "* Files from Psi project are copied."
FROM_STR="option(PSI_PLUS .*\$"
TO_STR="option(PSI_PLUS \"Build Psi+ client instead of Psi\" ON)"
sed -i "s|${FROM_STR}|${TO_STR}|g" CMakeLists.txt
echo "* Psi+ specific options are enabled."
cp -a "${SNAPSHOTS_DIR}/mac/application-plus.icns" \
"${SNAPSHOTS_DIR}/mac/application.icns"
echo "* Psi+ specific icons are set."
rsync -a "${MAIN_DIR}/plugins" "${SNAPSHOTS_DIR}/" \
--exclude=".git*" \
--exclude="/builddir*"
rsync -a "${MAIN_DIR}/psimedia" "${SNAPSHOTS_DIR}/plugins/generic/" \
--exclude=".git*" \
--exclude="/builddir*"
echo "* All plugins from Psi project are copied."
rsync -a "${MAIN_DIR}/resources/sound/" "${SNAPSHOTS_DIR}/sound/"
echo "* Extra sound files from Psi project are copied."
rsync -a "${MAIN_DIR}/resources/skins" "${SNAPSHOTS_DIR}/"
echo "* Extra skins from Psi project are copied."
# rm -rf *.exe
# rm -rf */*.exe
# rm -rf src/libpsi/tools/idle/win32/
find . -type f -name "*.orig" -delete
echo "* Trash is removed."
echo
# Update repo and run an analysis
git add -A .
TEST_ALL=$(LC_ALL=C git status | grep ": " |
grep -v " generate-single-repo.sh" | \
grep -v " README" | \
grep -v " version" | \
wc -l)
if [ "${TEST_ALL}" = "0" ]; then
echo "Updating is not required!"
git checkout HEAD .
echo
exit 0
fi
REVISION_DATE_LIST="$(cd ${MAIN_DIR}/psi && git log -n1 --date=short --pretty=format:'%ad')
$(cd ${MAIN_DIR}/plugins && git log -n1 --date=short --pretty=format:'%ad')
$(cd ${MAIN_DIR}/resources && git log -n1 --date=short --pretty=format:'%ad')"
LAST_REVISION_DATE=$(echo "${REVISION_DATE_LIST}" | sort -r | head -n1)
PSI_VERSION="$(cd ${MAIN_DIR}/psi && git describe --tags | cut -d - -f1)"
PATCHES_NUM="$(cd ${MAIN_DIR}/psi && git rev-list --count ${PSI_VERSION}..HEAD)"
NEW_VER="${PSI_VERSION}.${PATCHES_NUM}"
OLD_VER=$(cd "${SNAPSHOTS_DIR}" && git tag -l | sort -V | tail -n1)
echo "OLD_VER = ${OLD_VER}"
echo "NEW_VER = ${NEW_VER}"
echo
echo "${NEW_VER} (${LAST_REVISION_DATE}, ${PSI_NEW_HASH})" > version
echo "Version file is created:"
cat version
echo
COMMENT="Current version of Psi+ is ${NEW_VER}
It is based on:
* psi: ${PSI_NEW_HASH}
* plugins: ${PLUGINS_NEW_HASH}
* psimedia: ${PSIMEDIA_NEW_HASH}
* resources: ${RESOURCES_NEW_HASH}
"
echo "${COMMENT}"
git commit -a -m "${COMMENT}" 2>&1 > /dev/null
if [ "${NEW_VER}" != "${OLD_VER}" ]; then
git tag "${NEW_VER}"
echo "Git tag \"${NEW_VER}\" is created."
fi
echo