forked from letharion/Drupal-build-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_functions.sh
More file actions
119 lines (98 loc) · 2.1 KB
/
base_functions.sh
File metadata and controls
119 lines (98 loc) · 2.1 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# Functions at the top, initialization at the bottom.
source build/signals.sh
while getopts ":n" opt; do
case $opt in
n)
KEEPNS=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
# OSX does not necessarily have seq, so we implement it.
seq() {
local I=$1;
while [ $2 != $I ]; do {
echo -n "$I ";
I=$(( $I + 1 ))
}; done;
echo $2
}
# pushd and popd doesn't have a quite option, so we enforce silence
run_cmd() {
if pushd "${2}" > /dev/null; then
if ! eval ${1}; then
die "Command ${1} failed in directory ${2}!";
fi
popd > /dev/null
else
die "Wanted to run ${1} in ${2} but ${2} does not exist!";
fi
}
apply_patch() {
DEPTH=$(echo ${2}|sed 's/[^/]//g'|wc -m)
PATCH_DIR="patches/";
for i in $(seq 1 ${DEPTH}); do
PATCH_DIR="../${PATCH_DIR}";
done
echo "Applying patch ${1} in ${2}"
run_cmd "git apply ${PATCH_DIR}${1}" "${2}"
}
invoke() {
if [ "$(type -t ${DOMAIN}_${1})" = "function" ]; then
${DOMAIN}_${1}
fi
}
run_hooked_cmd() {
invoke "pre_${1}"
run_cmd "${2}" "${3}"
invoke "post_${1}"
}
die() {
echo "${1}"
exit 1;
}
ask() {
local ACCEPT="y"
if [ "${3}" != "" ]; then
local ACCEPT="${3}"
fi
read -p "${1} (y/N)? "
if [ "${REPLY}" == "${ACCEPT}" ]; then
run_cmd "${2}";
fi
}
relink() {
run_hooked_cmd "relink" "ln -sfn \"${NEWWEB}\" web";
}
if [ ! -f build.conf ]; then
echo "You need to create a build.conf file. See the README for an example.";
exit 1;
fi
source build.conf;
if [ -e web ] && [ ! -L web ]; then
die "web/ exists, but is not a symlink. Please remove it, as it will be overwritten."
else
OLDWEB=`readlink web`;
fi
if [ -z "$DATEFORMAT" ]; then
DATEFORMAT="%F-%T";
fi
if [ -z "$WEBDIRECTORY" ]; then
WEBDIRECTORY="web";
fi
if [ -z "$NEWWEB" ]; then
NEWWEB="${WEBDIRECTORY}-$(date +${DATEFORMAT})";
fi
KEEPNS=false;
NS="nodestream";
NSPROFILE="profiles/nodestream";
FULLDOMAIN="${DOMAIN}.${TOPDOMAIN}";
if [ -n "${SUBDOMAIN}" ]; then
FULLDOMAIN="${SUBDOMAIN}.${FULLDOMAIN}";
fi
if [ ! $PROFILENAME ]; then
PROFILENAME=${DOMAIN}
fi