-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_src.sh
executable file
·84 lines (68 loc) · 2.07 KB
/
build_src.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
#!/usr/bin/env bash
set -e # Abandonner immediatement pour toute erreur d'execution
source image_info.txt
if [ -z $VERSION ]; then
echo "Erreur, la version n'est pas inclue dans image_info.txt"
exit 3
fi
BUILD_FILE=$NAME.$VERSION.tar.gz
BUILD_PATH=$PWD/web
traiter_fichier_react() {
# Decide si on bati ou telecharge un package pour le build react.
# Les RPi sont tres lents pour batir le build, c'est mieux de juste recuperer
# celui qui est genere sur une workstation de developpement.
ARCH=`uname -m`
rm -f $NAME.*.tar.gz
if [ $ARCH == 'x86_64' ] || [ -z $URL_SERVEUR_DEV ]; then
echo "Architecture $ARCH (ou URL serveur DEV non inclus), on fait un nouveau build React"
package_build
else
echo "Architecture $ARCH, on va chercher le fichier avec le build installation web pour React sur $URL_SERVEUR_DEV"
telecharger_package
fi
}
package_build() {
echo "Building new installation web React app"
# Sauvegarder information de version
makeManifest
npm run-script build
echo Creer fichier tar $BUILD_PATH/../$BUILD_FILE
tar -zcf $BUILD_PATH/../$BUILD_FILE build/
echo Fin creation tar file
}
telecharger_package() {
cd $BUILD_PATH/..
sftp ${URL_SERVEUR_DEV}:${PATH_SERVEUR_DEV}/$BUILD_FILE
if [ $? -ne 0 ]; then
echo "Erreur download fichier react"
exit 1
fi
echo "Nouvelle version du fichier react telechargee"
}
installer() {
echo "Installation de l'application deployeur web React dans $BUILD_PATH"
cd $BUILD_PATH/..
rm -rf react_build
mkdir react_build && \
tar -xf $BUILD_FILE -C react_build
}
makeManifest() {
cd $BUILD_PATH/..
source image_info.txt
cd $BUILD_PATH/src
DATECOURANTE=`date "+%Y-%m-%d %H:%M"`
if [ -f manifest.build.js ]; then
mv manifest.build.js manifest.build.js.cp
fi
echo "const build = {" >> manifest.build.js
echo " date: '$DATECOURANTE'," >> manifest.build.js
echo " version: '$VERSION'" >> manifest.build.js
echo "}" >> manifest.build.js
echo "module.exports = build;" >> manifest.build.js
cd $BUILD_PATH
}
sequence() {
traiter_fichier_react
installer
}
sequence