-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·123 lines (96 loc) · 2.11 KB
/
build.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
#!/bin/sh
scriptFolder=$(dirname $(readlink -f $0))
authFileContent=''
outputFolder='./output'
sourceImgFolder=''
getHelp() {
cat <<HELP
Commands related to this script
USAGE:
main.sh build [FLAGS] <srcDirectory>
srcDirectory designating the folder containing the images to build the website.
FLAGS:
-h Print help informations.
--help Print help informations.
--auth Add an authentification to the site.
-o <directory> Sepcify the output folder.
--output=<directory> Sepcify the output folder.
HELP
return 1
}
createAuth() {
read -p "Username: " username
stty -echo
echo -n "Password: "
read password
echo ""
echo -n "Confirm password: "
read confirmationPassword
stty echo
if [ $password = $confirmationPassword ]
then
authFileContent="[{\"$username\":\"$(echo -n $password | shasum -a 256)\"}]"
else
echo "Passwords did not match!" >&2
exit 1
fi
return 1
}
main() {
while getopts ':ho:-:' option; do
case $option in
-)
case ${OPTARG} in
help)
getHelp
exit 0
;;
output=*)
outputFolder=${OPTARG#*=}
;;
auth)
createAuth
;;
*)
echo "Invalid option --${OPTARG}\n">&2
getHelp>&2
exit 1
;;
esac;;
h)
getHelp
exit 0
;;
o)
outputFolder=${OPTARG}
;;
\?)
echo "Invalid option -$option \n" >&2
getHelp >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
sourceImgFolder=$1
mkdir $outputFolder
cd $outputFolder
echo "=== Bottle Dowload & Installation ==="
echo "=> Creation of an virtual environment & connect to it"
~/.local/share/Python-3.10/bin/python3 -m venv venv
. venv/bin/activate
pip install -U bottle
cp -r ${scriptFolder}/site/* .
mkdir ./static/img
cp ${sourceImgFolder}/* ./static/img/
if [ ! -z "$authFileContent" ]
then
echo $authFileContent > ./auth.json
sed -i 's/ -//' ./auth.json
fi
echo "Lancement du serveur sur localhost:8080"
python main.py
echo "=> Disconnection of the virtual environment"
deactivate
}
main ${@}