This repository was archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.sh
executable file
·60 lines (48 loc) · 2.13 KB
/
init.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
#!/bin/bash
set -e
echo "1/5 What is the name of this instance?"
read INSTANCE_NAME
echo "2/5 Who is maintaining it?"
read INSTANCE_MAINTAINER
echo "3/5 What is the IP of the target server?"
read SERVER_IP
SERVER_IP=${SERVER_IP:-"0.0.0.0"}
echo "4/5 What is the Sendinblue update list id ?"
read SIB_UPDATE_LIST_ID
SIB_UPDATE_LIST_ID=${SIB_UPDATE_LIST_ID:-0}
echo "5/5 What is the Sendinblue update template id ?"
read SIB_UPDATE_TEMPLATE_ID
SIB_UPDATE_TEMPLATE_ID=${SIB_UPDATE_TEMPLATE_ID:-0}
usage() {
echo "At least instance name and maintainer are needed"
exit 1
}
if ! test $INSTANCE_NAME || ! test "$INSTANCE_MAINTAINER"
then
usage
fi
rm templates/.DS_Store # avoid “Illegal byte sequence” error
echo "Replacing variables in template files..."
echo "$\{instanceName\}: ${INSTANCE_NAME}"
echo "$\{instanceMaintainer\}: ${INSTANCE_MAINTAINER}"
echo "$\{serverIp\}: ${SERVER_IP}"
echo "$\{sendinblueUpdateListId\}: ${SIB_UPDATE_LIST_ID}"
echo "$\{sendinblueUpdateTemplateId\}: ${SIB_UPDATE_TEMPLATE_ID}"
IFS=$'\n' # This makes the find method below allow space in file names
TEMPLATE_FILES=$(find templates -type f)
# Use intermediate backup files (`-i`) with a weird syntax due to lack of portable 'no backup' option. See https://stackoverflow.com/q/5694228/594053.
# Credit to https://github.com/openfisca/country-template/blob/master/bootstrap.sh
sed -i.template "s|\${instanceName}|$INSTANCE_NAME|g" $TEMPLATE_FILES
sed -i.template "s|\${instanceMaintainer}|$INSTANCE_MAINTAINER|g" $TEMPLATE_FILES
sed -i.template "s|\${serverIp}|$SERVER_IP|g" $TEMPLATE_FILES
sed -i.template "s|\${sendinblueUpdateListId}|$SIB_UPDATE_LIST_ID|g" $TEMPLATE_FILES
sed -i.template "s|\${sendinblueUpdateTemplateId}|$SIB_UPDATE_TEMPLATE_ID|g" $TEMPLATE_FILES
find . -name "*.template" -type f -delete
echo "Using templates"
shopt -s dotglob # If set, bash includes filenames beginning with a '.' in the results of pathname expansion.
mv templates/* .
rm -Rf templates init.sh
git init
git add .
git commit --message "Initialise collection from template" --author "Open Terms Archive Bot <[email protected]>" --no-gpg-sign
echo "🎉 You're all done, congratulations"