-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsite.sh
executable file
·132 lines (103 loc) · 3.39 KB
/
site.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
#!/bin/bash
# Set default values
app_name=""
repository=""
flag=""
# Function to display script usage
usage() {
echo "Usage: ./site.sh <domain_name> <repository> [--laravel|--node]"
}
echo "If you want to setup https, you have to point your domain to this server first."
echo -e "\n"
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--laravel)
flag="laravel"
shift
;;
--node)
flag="node"
shift
;;
*)
app_name="$1"
repository="$2"
shift
;;
esac
shift
done
# Validate required arguments
if [[ -z $app_name || -z $repository || -z $flag ]]; then
usage
exit 1
fi
# Perform actions based on the provided flag
case $flag in
laravel)
echo "Performing Laravel-related stuff for $app_name"
GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=no' git clone $repository /var/www/$app_name
# install composer
cd /var/www/$app_name
composer install
cp .env.example .env
php artisan key:generate
# prepare nginx config file
cd /etc/nginx/sites-enabled
sudo wget -O $app_name https://raw.githubusercontent.com/setkyar/operative-bash/f5628816d36ac15ef577621489ccf183c1e10573/structs/laravel
# replace app_name with $app_name
sudo sed -i "s/example.com/$app_name/g" /etc/nginx/sites-enabled/$app_name
# Get the current PHP version
PHP_VERSION=$(php -v | head -n 1 | cut -d ' ' -f 2 | cut -d '.' -f 1-2)
sudo sed -i "s/php-fpm.sock/php${PHP_VERSION}-fpm.sock/g" /etc/nginx/sites-enabled/$app_name
# restart nginx
sudo service nginx restart
# laravel storage permission
sudo chgrp -R www-data /var/www/$app_name/storage /var/www/$app_name/bootstrap/cache
sudo chmod -R ug+rwx /var/www/$app_name/storage /var/www/$app_name/bootstrap/cache
sudo chown www-data:www-data /var/www/$app_name/database/
sudo chmod 775 /var/www/$app_name/database/
# Ask the user if they want to add Certbot
read -p "Do you want to add Certbot? (y/n): " add_certbot
if [[ $add_certbot =~ ^[Yy]$ ]]; then
sudo certbot --nginx -d "$app_name"
fi
echo "Laravel site $app_name has been set up!"
;;
node)
echo "Performing Node-related stuff for $app_name"
# Node-specific commands
echo "Performing Laravel-related stuff for $app_name"
GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=no' git clone $repository /var/www/$app_name
# install npm
cd /var/www/$app_name
npm install
# start with pm2
if pm2 id $app_name &> /dev/null; then
pm2 delete $app_name
fi
pm2 start npm --name "$app_name" -- start
# prepare nginx config file
cd /etc/nginx/sites-enabled
sudo wget -O $app_name https://raw.githubusercontent.com/setkyar/operative-bash/f5628816d36ac15ef577621489ccf183c1e10573/structs/proxy-pass
# replace app_name with $app_name
sudo sed -i "s/example.com/$app_name/g" /etc/nginx/sites-enabled/$app_name
# ask user to enter port number
echo "Enter port number for $app_name"
read port_number
# replace port_number with $port_number
sudo sed -i "s/3000/$port_number/g" /etc/nginx/sites-enabled/$app_name
# restart nginx
sudo service nginx restart
# certbot
# Split the domain into parts using dot as the delimiter
IFS='.' read -ra domain_parts <<< $app_name
sudo certbot --nginx -d $app_name
;;
*)
echo "Invalid flag: $flag"
usage
exit 1
;;
esac