forked from redtocatta/cloudstack-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudstack-set-guest-password
More file actions
executable file
·105 lines (90 loc) · 3.6 KB
/
Copy pathcloudstack-set-guest-password
File metadata and controls
executable file
·105 lines (90 loc) · 3.6 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
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
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Installation steps (ArchLinux using base/dhcpcd-6.0.5-1)
#
# Install "wget" and "dhcpcd"
# $ pacman -S wget dhcpcd
# $ systemctl enable dhcpcd@eth0
# Copy script to /usr/lib/systemd/scripts/
# $ cp -v cloudstack-set-guest-password \
# /usr/lib/systemd/scripts/
# Copy the service file to /usr/lib/systemd/system/
# $ cp -v cloudstack-set-guest-password.service \
# /usr/lib/systemd/system/
# Enable the service
# $ systemctl enable cloudstack-set-guest-password.service
interface=eth0
user=root
password_received=0
if [ ! -x /usr/bin/dhcpcd ]; then
logger -t "cloudstack" "$0 only works with base/dhcpcd"
exit 1
fi
if [ ! -x /usr/bin/chpasswd ]; then
logger -t "cloudstack" "$0 requires /usr/bin/chpasswd command"
exit 1
fi
PASSWORD_SERVER_IP=$(dhcpcd -U $interface | grep dhcp_server_identifier | cut -f2 -d=)
if [ -n $PASSWORD_SERVER_IP ]; then
logger -t "cloudstack" "Found password server IP $PASSWORD_SERVER_IP"
logger -t "cloudstack" "Sending request to password server at $PASSWORD_SERVER_IP"
password=$(wget -q -t 3 -T 20 -O - --header "DomU_Request: send_my_password" $PASSWORD_SERVER_IP:8080)
if [ $? -ne 0 ]; then
logger -t "cloudstack" "Failed to run wget correctly. Network not ready?"
exit 1
fi
password=$(echo $password | tr -d '\r')
logger -t "cloudstack" "Got password as - $password - "
if [ $? -eq 0 ]; then
logger -t "cloudstack" "Got response from server at $PASSWORD_SERVER_IP"
case $password in
"")
logger -t "cloudstack" "Password server at $PASSWORD_SERVER_IP did not have any password for the VM"
;;
"bad_request")
logger -t "cloudstack" "VM sent an invalid request to password server at $PASSWORD_SERVER_IP"
;;
"saved_password")
logger -t "cloudstack" "VM has already saved a password from the password server at $PASSWORD_SERVER_IP"
;;
*)
logger -t "cloudstack" "VM got a valid password from server at $PASSWORD_SERVER_IP"
password_received=1
;;
esac
else
logger -t "cloudstack" "Failed to send request to password server at $PASSWORD_SERVER_IP"
fi
else
logger -t "cloudstack" "Could not find password server IP for $interface"
fi
if [ "$password_received" == "1" ]; then
logger -t "cloudstack" "Changing password ..."
echo $user:$password | /usr/bin/chpasswd
if [ $? -gt 0 ]; then
logger -t "cloudstack" "Failed to change password for user $user"
exit 1
fi
logger -t "cloudstack" "Successfully changed password for user $user"
logger -t "cloudstack" "Sending acknowledgment to password server at $PASSWORD_SERVER_IP"
wget -t 3 -T 20 -O - --header "DomU_Request: saved_password" $PASSWORD_SERVER_IP:8080
fi
exit 0
# vim: set ts=2 sw=2 expandtab