-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·95 lines (82 loc) · 2.62 KB
/
init.sh
File metadata and controls
executable file
·95 lines (82 loc) · 2.62 KB
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
#!/bin/sh
# Script to initialise a new wiki2pages project.
set -e
# Load OS information.
# shellcheck source=/dev/null
. /etc/os-release
usage(){
/usr/bin/echo 'init.sh [OPTIONS]'
/usr/bin/echo 'Initialise a wiki2pages project with the repo and branch provided.'
/usr/bin/echo ''
/usr/bin/echo 'Available options:'
/usr/bin/echo '--repo: target repo containing your .wiki2pages.yml config file and markdown'
/usr/bin/echo '--branch: branch to use in target repo (default is main)'
/usr/bin/echo '--no-ce-dev: do not start ce-dev once the config is complete'
/usr/bin/echo ''
}
# Parse options arguments.
parse_options(){
while [ "${1:-}" ]; do
case "$1" in
"--repo")
shift
CONFIG_REPO="$1"
;;
"--branch")
shift
CONFIG_BRANCH="$1"
;;
"--no-ce-dev")
NO_CE_DEV="true"
;;
*)
usage
exit 1
;;
esac
shift
done
}
# Set default variables.
CONFIG_BRANCH="main"
NO_CE_DEV="false"
# Parse options.
parse_options "$@"
if [ -z "$CONFIG_REPO" ]; then
/usr/bin/echo 'ABORTING! You must pass a git repository as argument.'
exit 1
fi
OWN_DIR=$(/usr/bin/dirname "$0")
cd "$OWN_DIR" || exit 1
OWN_DIR=$(/usr/bin/git rev-parse --show-toplevel)
cd "$OWN_DIR" || exit 1
OWN_DIR=$(/usr/bin/pwd -P)
WIKIS_CONFIG_DIR="$OWN_DIR/ce-dev/ansible/wikis"
WORK_DIR=$(/usr/bin/mktemp -d)
CONFIG_FILE=".wikis2pages.yml"
if [ ! -d "$WIKIS_CONFIG_DIR" ]; then
/usr/bin/echo "-------------------------------------------------"
/usr/bin/echo "Creating $WIKIS_CONFIG_DIR"
mkdir "$WIKIS_CONFIG_DIR"
fi
/usr/bin/echo "-------------------------------------------------"
cd "$WORK_DIR"
/usr/bin/echo "Checking out the $CONFIG_BRANCH branch of the repo at $CONFIG_REPO into $WORK_DIR"
/usr/bin/git clone "$CONFIG_REPO" --branch "$CONFIG_BRANCH" --single-branch --depth 1
REPO_NAME="$(ls | head -1)"
if [ ! -f "$WORK_DIR/$REPO_NAME/$CONFIG_FILE" ]; then
/usr/bin/echo "ABORTING! Could not find a .wikis2pages.yml file in $CONFIG_REPO".
exit 1
fi
/usr/bin/echo "-------------------------------------------------"
/usr/bin/echo "Creating $WIKIS_CONFIG_DIR/$REPO_NAME-$CONFIG_BRANCH.yml as a copy of $WORK_DIR/$REPO_NAME/$CONFIG_FILE"
/usr/bin/cp "$WORK_DIR/$REPO_NAME/$CONFIG_FILE" "$WIKIS_CONFIG_DIR/$REPO_NAME-$CONFIG_BRANCH.yml"
cd "$OWN_DIR"
if [ "$NO_CE_DEV" = "false" ]; then
/usr/bin/echo "-------------------------------------------------"
/usr/bin/echo "Initialising ce-dev"
/usr/local/bin/ce-dev init
/usr/local/bin/ce-dev start
/usr/local/bin/ce-dev provision
fi
/usr/bin/echo "-------------------------------------------------"