-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.sh
97 lines (85 loc) · 1.91 KB
/
driver.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
#!/bin/bash
# Global and secret configs
SECRETS='configs/secrets.env'
GLOBAL='configs/global.env'
# Print script usage
function usage {
echo "Usage: $0 --profile <profile> --host <ip/hostname>"
echo " -p, --profile specify profile file"
echo " -h, --host specify host"
echo " -k, --key ssh key file"
echo " --help Displays Help Information"
echo "Example: $0 --config config/virtual-machine.env --host computer.example.com"
}
# Check is no arguements are supplied
if [ $# -eq 0 ]
then
echo "No arguments supplied"
usage
exit
fi
# Read options/flags
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-p|--profile)
PROFILE="$2"
shift
shift
;;
-h|--host)
SSH_HOST="$2"
shift
shift
;;
-k|--key)
SSH_KEY="$2"
shift
shift
;;
--help)
usage
exit
shift
;;
*)
usage
exit
shift
;;
esac
done
# Write master config file
echo "" > master.env
cat $SECRETS >> master.env
echo "" >> master.env
cat $GLOBAL >> master.env
echo "" >> master.env
cat $PROFILE >> master.env
echo "" >> master.env
echo > master.sh
cat functions/*.sh >> master.sh
# Remove remote host from known-hosts file
ssh-keygen -R $SSH_HOST
# Copy ssh keys to remote host
if [ $SSH_KEY ]
then
ssh-copy-id -i $SSH_KEY root@$SSH_HOST
fi
echo "Transferring config files to remote host"
# Transfer master config and functions to remote host
scp -r master.env master.sh functions/chroot-functions root@$SSH_HOST:/root/
# scp -r functions root@$SSH_HOST:/root/
echo "Running script on remote host"
# Run install script on remote host
if [ $SSH_KEY ]
then
ssh -oStrictHostKeyChecking=no root@$SSH_HOST -i $SSH_KEY < archinstall-acm.sh
else
ssh -oStrictHostKeyChecking=no root@$SSH_HOST < archinstall-acm.sh
fi
# Remove master.env
rm master.env master.sh
echo -e "\n\n\nScript Ended\n\n\n"
exit