-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-ext.dist.sh
executable file
·192 lines (163 loc) · 5.92 KB
/
build-ext.dist.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
#!/bin/bash
# vi: set sw=4 ts=4 et:
CURDIR=`pwd`
GIT_MODULE=`cat git-module.cfg`
MY_GIT_MODULE=`basename $CURDIR`
MY_SRC_DIR=`echo $CURDIR | sed -e s%/$MY_GIT_MODULE%%`
MY_SRC_DIR=`basename $MY_SRC_DIR`
#ESPOCRM_DIR=`echo $CURDIR | sed -e s%/$MY_SRC_DIR/$MY_GIT_MODULE%%`
ESPOCRM_DIR=~/crm
echo ""
echo "$0"
echo ""
echo "-------------------------------------------------------------------------------------"
echo "GIT Module Configured: $GIT_MODULE"
echo "Derived GIT module : $MY_GIT_MODULE"
echo "Src dir : $MY_SRC_DIR"
echo "ESPOCRM Directory : $ESPOCRM_DIR"
echo "-------------------------------------------------------------------------------------"
OK=1
#if [ "$MY_SRC_DIR" != "src" ]; then
# OK=0
# echo "This source module is not in a 'src/$GIT_MODULE' directory under $ESPOCRM_DIR"
#elif [ "$MY_GIT_MODULE" != "$GIT_MODULE" ]; then
# OK=0
# echo "This source module is not in a 'src/$GITMODULE' directory under $ESPOCRM_DIR"
#fi
#if [ $OK = 0 ]; then
# echo "We expect this script to be in a subdirectory of a 'src' directory, which has to be"
# echo "right underneath the CRM main directory. Make sure it is."
# exit 1
#fi
echo ""
echo "Building module..."
echo ""
echo "-------------------------------------------------------------------------------------"
echo ""
INSTALL_PREFIX=$ESPOCRM_DIR
INSTALL_FILES="$INSTALL_PREFIX/data/installed"
function usage()
{
echo ""
echo "usage: $0 <buildext|cleanup|install|uninstall> <version> <extension-filename> <extension-name> <description> <module-dir>"
echo ""
echo " buildext - builds the EspoCRM extension in the 'build' directory."
echo " cleanup - removes the 'build' directory."
echo " install - installs the files of this extension into the EspoCRM tree at '$INSTALL_PREFIX'"
echo " uninstall - uninstalls the files of this extension from '$INSTALL_PREFIX', if , '$INSTALL_FILES/<module-dir' exists"
echo ""
exit 1;
}
if [ "$#" -ne 6 ]; then
usage
fi
CMD=$1;
VERSION=$2
EXT=$3
NAME=$4
DESCRIPTION=$5
MODULE=$6
CDIR=`pwd`
BUILD_DIR="$CDIR/build"
DIRS="application client custom api"
TARDIRS=""
for D in $DIRS
do
if [ -d $D ]; then
TARDIRS="$TARDIRS $D"
fi
done
if [ "$CMD" == "install" ]; then
mkdir -p $INSTALL_FILES
tar cf - $TARDIRS | (cd $INSTALL_PREFIX; tar hxvf - ) >$INSTALL_FILES/$MODULE
FILES=`cat $INSTALL_FILES/$MODULE`
for F in $FILES
do
F="$INSTALL_PREFIX/$F"
if [ -f "$F" ]; then
echo "installed $F"
fi
done
echo "$MODULE installed, installed files in $INSTALL_FILES/$MODULE"
elif [ "$CMD" == "uninstall" ] ; then
if [ -r $INSTALL_FILES/$MODULE ]; then
FILES=`cat $INSTALL_FILES/$MODULE`
for F in $FILES
do
F="$INSTALL_PREFIX/$F"
if [ -f "$F" ]; then
echo "removing $F"
rm $F;
fi
done
else
echo "Cannot uninstall, $INSTALL_FILES/$MODULE does not exist"
fi
elif [ "$CMD" == "cleanup" ]; then
rm -rf $BUILD_DIR
elif [ "$CMD" == "buildext" ]; then
DIR=/tmp/$EXT
rm -rf $DIR
mkdir $DIR
MANIFEST=$DIR/manifest.json
DT=`date +%Y-%m-%d`
echo "{" >$MANIFEST
echo " \"name\": \"$NAME\", " >>$MANIFEST
echo " \"version\": \"$VERSION\", " >>$MANIFEST
echo " \"acceptableVersions\": [ \">=7.5.5\" ], " >>$MANIFEST
echo " \"php\": [ \">=7.0.0\" ], " >>$MANIFEST
echo " \"releaseDate\": \"$DT\", " >>$MANIFEST
echo " \"author\": \"Hans Dijkema\", " >>$MANIFEST
echo " \"description\": \"$DESCRIPTION\"" >>$MANIFEST
echo "}" >>$MANIFEST
mkdir $DIR/files
if [ -d scripts ]; then
TARDIRS="$TARDIRS scripts"
fi
tar cf - $TARDIRS | (cd $DIR/files; tar xf - )
mkdir $DIR/scripts
F=$DIR/scripts/BeforeInstall.php
echo "<?php" >$F
echo "class BeforeInstall" >>$F
echo "{" >>$F
echo " public function run($container) {" >>$F
echo " }" >>$F
echo "}" >>$F
echo "?>" >>$F
F=$DIR/scripts/AfterInstall.php
echo "<?php" >$F
echo "class AfterInstall" >>$F
echo "{" >>$F
echo " public function run($container) {}" >>$F
echo "}" >>$F
echo "?>" >>$F
F=$DIR/scripts/BeforeUninstall.php
echo "<?php" >$F
echo "class BeforeUninstall" >>$F
echo "{" >>$F
echo " public function run($container) {}" >>$F
echo "}" >>$F
echo "?>" >>$F
F=$DIR/scripts/AfterUninstall.php
echo "<?php" >$F
echo "class AfterUninstall" >>$F
echo "{" >>$F
echo " public function run($container) {}" >>$F
echo "}" >>$F
echo "?>" >>$F
if [ -d $DIR/files/scripts ]; then
(cd $DIR/files; tar cf - scripts) | (cd $DIR; tar xvf - )
rm -rf $DIR/files/scripts
fi
EXTENSION="espocrm-$EXT-$VERSION.zip"
EXT_FILE="$BUILD_DIR/$EXTENSION"
mkdir -p $BUILD_DIR
echo "creating extension in $EXT_FILE"
rm -f $EXT_FILE
(cd $DIR;zip -q -r $EXT_FILE .)
echo "$EXTENSION created in directory $BUILD_DIR"
else
echo ""
echo "Command '$CMD' given, but it is not a supported command"
usage
fi