-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·147 lines (118 loc) · 2.89 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
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
#!/bin/bash
# script directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# list executable commands separated by space
commandependencies=( php mysql npm grunt compass composer )
# show success message
function msgsuccess() {
echo "$(tput setaf 2)OK$(tput sgr0)";
}
# show fail message and stop execution
function msgfail() {
echo -e >&2 "$(tput setaf 1)FAIL$(tput sgr0)"; exit 1;
}
# check executable is on env path
function checkcommand() {
command -v $1 >/dev/null 2>&1 || { msgfail; }
}
# check for project dependencies
function checkdependencies() {
for i in "${commandependencies[@]}"
do
echo -n "Checking for executable $i..."
checkcommand $i
msgsuccess
done
}
function checkdevdependencies() {
checkdependencies
echo -n "Checking for executable bower..."
checkcommand bower
msgsuccess
}
# install project dependencies
function installdependencies() {
# install npm modules
echo "Installing npm dependencies..."
echo "Updating composer"
composer self-update
cd ${DIR}/build/
npm install
# need to run composer in the workbench first
if [ -d workbench ]
then
for c in `find ${DIR}/build/workbench -name composer.json`; do
d=`dirname $c`
if ! `echo $d | grep -q /vendor/`; then
echo "Installing composer dependencies in $d..."
cd $d
composer install
fi
done
fi
cd ${DIR}/build/
# install composer modules
if [ -f composer.json ]
then
echo "Installing composer dependencies..."
composer install
fi
if [ -f artisan ]
then
echo "Generating Laravel encryption key..."
php artisan key:generate
fi
if [ -d app/storage ]
then
echo "Update storage folder permissions"
chmod -R 777 app/storage
fi
if [ -d public/silverstripe/assets/Uploads ]
then
echo "Update Uploads folder permissions"
chmod -R 777 public/silverstripe/assets
fi
cd ${OLDPWD}
}
function installdevdependencies() {
echo "Installing basic javascript files..."
cd ${DIR}/build/
bower install
cd ${OLDPWD}
}
# Setup building process
function build() {
cd ${DIR}/build/
# run grunt default task
echo "Running grunt default task.."
grunt
# generate documentation
echo "Generating documentation.."
grunt docs
cd ${OLDPWD}
}
# commands to restore default state
function revertbuild() {
: cleaning commands
echo "Removing npm dependencies.."
rm -rf ${DIR}/build/node_modules
}
case "$1" in
"")
checkdevdependencies
installdevdependencies
installdependencies
build
;;
build)
build
;;
rebuild)
revertbuild
build
;;
check)
checkdependencies
installdependencies
;;
esac