-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloud-init
More file actions
executable file
·48 lines (39 loc) · 1.21 KB
/
cloud-init
File metadata and controls
executable file
·48 lines (39 loc) · 1.21 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
#!/bin/sh
# exit on failure
set -e
# exit on unassigned variable
set -u
# variables
USER_DATA_FILE=${USER_DATA_FILE:-/var/lib/cloud/user-data}
SSH_AUTHORIZED_KEYS_SRC=${SSH_AUTHORIZED_KEYS_SRC:-/var/lib/cloud/ssh.pub}
SSH_AUTHORIZED_KEYS_DST=${SSH_AUTHORIZED_KEYS_DST:-/root/.ssh/authorized_keys}
# configure SSH access for root user
if [ -f "${SSH_AUTHORIZED_KEYS_SRC}" ]; then
if [ -f "${SSH_AUTHORIZED_KEYS_DST}" ]; then
echo "SSH public key file ${SSH_AUTHORIZED_KEYS_DST} already exists"
echo "Exit to avoid overwrite it in case it was mounted RW using 'docker run --volume'"
# return EACCES (Permission denied) to systemd
exit 13
fi
install \
--verbose \
--mode 0700 \
--owner root \
--group root \
--directory \
/root/.ssh
install \
--verbose \
--mode 0600 \
--owner root \
--group root \
${SSH_AUTHORIZED_KEYS_SRC} ${SSH_AUTHORIZED_KEYS_DST}
fi
# run cloud-init script and send output to the same log file as the *real* cloud-init service
if [ -f "${USER_DATA_FILE}" ]; then
/bin/sh -c ${USER_DATA_FILE} 2>&1 | tee -a /var/log/cloud-init-output.log
else
echo "User-data script ${USER_DATA_FILE} does not exists" >&2
# return ENOENT (No such file or directory) to systemd
exit 2
fi