-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall
More file actions
executable file
·80 lines (66 loc) · 3.13 KB
/
install
File metadata and controls
executable file
·80 lines (66 loc) · 3.13 KB
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
#!/bin/bash
# Author : Abhishek @ EchtOps
# DeployTool Install File ##
## Color Definitions ##
colred='\e[31m' # Red
colgrn='\e[32m' # Green
colmag='\e[35m' # Magenta
coldef='\e[39m' # Default
## Validations ##
ops_dir="/opt/echtops/vanilla-deploy"
[[ "$(pwd)" != "$ops_dir" ]] && { echo -e "$colred\r[-] Please cd to $ops_dir & then Run$coldef $0" ; exit 1 ; }
[[ "$(id -u)" != "0" ]] && { echo -e "$colred\r[-] Please Run From Root Access.$coldef" ; exit 1 ; }
dist="$(cat /etc/os-release|grep ID_LIKE|cut -d '=' -f2|grep -o 'rhel\|debi')"
webuser="$(cat /etc/passwd | grep "/var/www" | cut -d ':' -f1 | head -1)"
[[ "$dist" = "debi" ]] && {
echo -e "$colgrn\r[+] Debian Based Distro Detected .$coldef"
http_pkg="sudo apt install apache2"
[[ -z "$webuser" ]] && { echo -e "$colred\r [-] Whereis Apache??\n\t Try Running => $http_pkg $coldef" ; exit 1 ; }
src="."
}
[[ "$dist" = "rhel" ]] && {
echo -e "$colgrn\r[+] RedHat Based Distro Detected .$coldef"
http_pkg="sudo yum install httpd"
[[ -z "$webuser" ]] && { echo -e "$colred\r [-] Whereis Apache??\n\t Try Running => $http_pkg $coldef" ; exit 1 ; }
src="source"
}
cd "$ops_dir"
$src "$ops_dir/setupvars.conf"
git config --global user.name "$deploy_admin_name"
git config --global user.email "$deploy_admin_mail"
git config --global core.filemode false
[[ -f "/root/.ssh/config" ]] || { mkdir -p "/root/.ssh" ; chmod 700 "/root/.ssh" ; cp "/root/.ssh/config" "/root/.ssh/config_bkp_$(date +%F_%T)" ; }
keyname="`hostname`+`dig +short myip.opendns.com @resolver1.opendns.com`.pem"
[[ -f "$ops_dir/confs/deploykeys/$keyname" ]] || { ssh-keygen -t rsa -N "" -f "$ops_dir/confs/deploykeys/$keyname" > /dev/null ; }
chmod 400 $ops_dir/confs/deploykeys/*pem
sed -i '/## DeployTool Config Start ##/,/## DeployTool Config End ##/d' /root/.ssh/config
keytext="## DeployTool Config Start ##
Host $deploy_host_name
RSAAuthentication yes
StrictHostKeyChecking No
IdentityFile $ops_dir/confs/deploykeys/$keyname
## DeployTool Config End ##"
echo "$keytext" >> /root/.ssh/config
chmod 600 /root/.ssh/config
echo -e "$colgrn\r[+] Your Deploy Key Is Saved To File : $colmag$ops_dir/confs/deploykeys/$keyname.pub$coldef"
echo -e "$colgrn\r[+] You Should Copy The Following key :$coldef"
echo ""
cat "$ops_dir/confs/deploykeys/$keyname.pub"
echo ""
echo -e "$colgrn\r[+] And Paste It To SSH Keys of Deploy User $coldef"
rm -f /etc/init.d/deploy.* /etc/*.deploy.conf /etc/logrotate.d/*.deploy "/usr/sbin/deploy.tool" "/usr/sbin/deploy.bash"
sed -i "s|examplewebuser|$webuser|g" $ops_dir/bins/deploy.bash
sed -i "s|'examplesrc'|'$src'|g" $ops_dir/bins/deploy.bash
ln -s "$ops_dir/confs/main.conf" "/etc/vanilla-deploy.conf"
ln -s "$ops_dir/confs/logrotate.conf" "/etc/logrotate.d/vanilla-deploy"
ln -s "$ops_dir/bins/deploy.bash" "/usr/sbin/deploy.bash"
sed -i '/deploy/d' /etc/rc.local ; sed -i '/deploy.bash/d' /etc/rc.local
echo "sleep 30 && ${ops_dir}/bins/deploy.bash start & " >> /etc/rc.local
sed -i '/exit 0/d' /etc/rc.local && echo 'exit 0' >> /etc/rc.local
echo "" >> /etc/rc.local
mkdir -p /var/log/echtops
git remote remove origin
git add .
git commit -am "`date` Saved DeployTool Install @ `hostname`" > /dev/null
exit 0
## E O F ##