-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-laravel-domain.sh
executable file
·143 lines (122 loc) · 3.54 KB
/
setup-laravel-domain.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
#!/bin/bash
OPTIONS="SSL SSLGen HTTP Quit"
RED='\033[0;31m'
NC='\033[0m' # No Color
YLW='\033[1;33m'
BLUE='\033[0;34m'
function project()
{
local __resultvar=$1
echo "What is the domain of your local project (i.e. laravel.test)"
read myresult
eval $__resultvar="'$myresult'"
}
function directory()
{
local __resultvar=$1
echo "What is the folder name in your /var/www/html"
read myresult
eval $__resultvar="'$myresult'"
}
function movessl() {
for file in *
do
if [[ -f $file ]]; then
if [[ $file == *"key.pem" && $file == *"$proj"* ]]; then
{
sudo mv "$DIR/$file" "/etc/ssl/$proj.key"
} || {
clear
echo -e "\nERROR:\t${RED}Failed to move SSL's key file!"
exit
}
continue
fi
if [[ $file == *".pem" && $file == *"$proj"* ]]; then
{
sudo mv "$DIR/$file" "/etc/ssl/$proj.pem"
} || {
clear
echo -e "\nERROR:\t${RED}Failed to move SSL's pem file!"
exit
}
continue
fi
fi
done
}
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
filename='nginxssl'
select opt in $OPTIONS; do
if [ "$opt" = "Quit" ]; then
echo Goodbye
exit
elif [ "$opt" = "SSL" ]; then
project proj
directory dir
echo Creating SSL file for Nginx
elif [ "$opt" = "SSLGen" ]; then
project proj
directory dir
echo Generating an SSL File and Nginx File
{
mkcert -install "$proj" ""*.$proj""
} || {
echo -e "\nERROR:\t${RED}Failed to create certs with mkcert"
exit
}
movessl
elif [ "$opt" = "HTTP" ]; then
project proj
directory dir
filename='nginxhttp'
echo Creating an HTTP file for Nginx
else
clear
echo Invalid option
exit
fi
rm -rf "$proj"
old_IFS=$IFS # save the field separator
IFS=$'\n' # new field separator, the end of line
for line in $(cat $filename)
do
newline="${line/\[\[DOMAIN\]\]/$proj}"
newline="${newline/\[\[DIRECTORY\]\]/$dir}"
echo "$newline" >> "$proj"
done
IFS=$old_IFS # restore default field separator
sudo mv "$DIR/$proj" "/etc/nginx/sites-available/$proj"
sudo ln -s "/etc/nginx/sites-available/$proj" "/etc/nginx/sites-enabled/$proj"
ngxres
clear
echo "==============================================="
echo ""
echo -e "Successfully created ${RED}$proj${NC}'s nginx files/certs!\n"
if [[ $filename == "nginxssl" ]]; then
echo -e "Your certs are listed below:\n"
echo -e "${YLW}Key:${NC}\t/etc/ssl/$proj.key"
echo -e "${YLW}Pem:${NC}\t/etc/ssl/$proj.pem"
echo -e ""
fi
echo -e "Your nginx file is:\n"
echo -e "/etc/nginx/${BLUE}sites-available${NC}/$proj"
echo ""
echo "==============================================="
found=0
for line in $(sudo cat /etc/hosts)
do
if [[ $line == *"$proj"* ]]; then
found=1
fi
done
if [[ $found == 0 ]]; then
echo ""
echo -e "Appended to ${YLW}/etc/hosts${NC} with new domain:\n"
echo -e "127.0.0.1\t$proj" | sudo tee -a /etc/hosts
echo ""
echo "==============================================="
fi
ngxres
exit
done