-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_server.sh
More file actions
executable file
·68 lines (55 loc) · 1.34 KB
/
clean_server.sh
File metadata and controls
executable file
·68 lines (55 loc) · 1.34 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
#!/bin/bash
set -x
FOREMAN_URL="https://theforeman.eng.lab.tlv.redhat.com"
METHOD="setBuild"
AUTH_USER=${AUTH_USER:-"augol"}
AUTH_PASS=${AUTH_PASS:-"Gnh,tuduk0"}
IN_HOST=$1
HPASS=$2
TMP_PING=/tmp/tmpping_$1
USAGE="$0 <hostname> <hostpass>\n
example: $0 foo.bar.com 12345\n
\n
you can also specify user name and password like so:\n
AUTH_USER=user AUTH_PASS=pass $0\n"
if [ -z $IN_HOST ] || [ -z $HPASS ]
then
echo -e $USAGE
exit 1
fi
if [ -z $AUTH_USER ]
then
echo username:
read AUTH_USER
fi
if [ -z $AUTH_PASS ]
then
echo password:
read -s AUTH_PASS
fi
rm -rf $TMP_PING
ping -c 1 $IN_HOST &> $TMP_PING
FOUND_HOST=$(cat $TMP_PING | grep ^PING | awk '{print $2}')
rm -rf $TMP_PING
URL="$FOREMAN_URL/hosts/$FOUND_HOST/$METHOD"
echo "setBuild on host"
curl -k -H "Accept:application/json" \
-u ${AUTH_USER}:${AUTH_PASS} $URL &> /dev/null
echo "rebooting server"
sshpass -p $HPASS ssh root@${FOUND_HOST} reboot &> /dev/null
sleep 10
echo "starting to wait for completion"
~/scripts/tryssh.sh $FOUND_HOST
if [ $? -ne 0 ]
then
exit 1
fi
echo "moving key and installation script"
sshpass -p $HPASS \
ssh-copy-id -i ~/.ssh/id_rsa.pub \
root@$FOUND_HOST &> /dev/null
scp ~/scripts/ospd.tar \
root@$FOUND_HOST:/root/ &> /dev/null
#scp ~/scripts/packstack-install.sh \
# root@$FOUND_HOST:/root/ &> /dev/null
echo "DONE"