-
Notifications
You must be signed in to change notification settings - Fork 8
/
deploy.sh
executable file
路38 lines (31 loc) 路 943 Bytes
/
deploy.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
#!/bin/bash
# IP address is passed as an argument to this script
user_name=$1
ip_address=$2
# Validate user name
if [[ -z $user_name ]]; then
echo "User name not specified"
exit 1
fi
# Validate IP address
if [[ ! $ip_address =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid IP address"
exit 1
fi
# Zip all files in project directory apart from the following:
# - .tmp
# - *.example
# - composes/*/certs/
zip -r project.zip . -x .tmp\* .git .env.example.\* composes/\*/certs\* > /dev/null
# Copy entire project directory to remote host using SCP
scp -r -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null project.zip $user_name@$ip_address:/home/$user_name > /dev/null && rm project.zip
if [[ $? -eq 0 ]]; then
echo "[OK] Project copied to $ip_address in /home/$user_name"
else
echo "Error copying project to remote host"
exit 1
fi
cd ..
# Destroy variables
unset user_name
unset ip_address