This repository was archived by the owner on Jan 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_static_website.sh
executable file
·56 lines (45 loc) · 1.9 KB
/
build_static_website.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
#!/bin/bash
# set -xe
#------------------------------------------------------------------------------
# Build the static website from the Symfony 3.4 one, in the "www" directory
# Build before commiting and deploying
# * copy the assets, keeping directory structure
# * generate the html pages and put them in /www (no / in path)
# todo: list the routes from the debug:router command and make a loop on it
#------------------------------------------------------------------------------
function findAFreePort() {
occupied_ports=$(netstat -aunt | grep "^.*127.0.0.1:" | sed "s/^.\{30\}\([[:digit:]]*\).*$/\1/")
read lowerPort upperPort < /proc/sys/net/ipv4/ip_local_port_range
for (( port = lowerPort ; port <= upperPort ; port++ )); do
available="false"
for occ_port in $occupied_ports; do
if [ $occ_port == $port ]; then
continue 2
fi
done
available="true"
break
done
if [ $available == "false" ]; then # the loop ended because there were no availables ports
echo "Pas de port disponible !!!"; exit 1
fi
echo $port
}
# Directory of the current script
projectDir=$(dirname $(readlink -f $0))
#-- Copy the assets
rsync -rv $projectDir/public/ $projectDir/www/ --delete --exclude=*.php --exclude=.htaccess
#-- Generates the html files from routes
# Run built in server
freePort=$(findAFreePort)
php bin/console server:start 127.0.0.1:$freePort
sleep 1
# todo: list the routes from the debug:router command and make a loop on it
# todo: instead of listing here the pages
# php bin/console debug:router |awk '$2 == "ANY" {print $5}'
curl --noproxy "*" 127.0.0.1:$freePort/ > $projectDir/www/index.html
curl --noproxy "*" 127.0.0.1:$freePort/mentions-legales > $projectDir/www/mentions-legales.html
# stop server
php bin/console server:stop
# Add newly generated files to git
git add -v --all $projectDir/www/