Blob


1 #!/bin/sh
2 # shellcheck disable=SC1091
4 state_df() {
5 df -h
6 }
8 state_uname() {
9 uname -a
10 }
12 state_id() {
13 id
14 }
16 state_mount() {
17 mount
18 }
20 state_env() {
21 env
22 }
24 state_hostname() {
25 hostname
26 }
28 install_root_profile() {
29 groupinstall -o root:wheel -m 644 "root.profile.$(uname)" /root/.profile
30 }
32 install_motd() {
33 motd_content="Welcome on $(nodename)"
34 case $(uname) in
35 OpenBSD)
36 printf %s\\n "$motd_content" >motd
37 install -o root:wheel -m 644 motd /etc/motd
38 ;;
39 FreeBSD)
40 printf %s\\n "$motd_content" >motd.template
41 install -o root:wheel -m 644 motd.template /etc && service motd restart
42 ;;
43 esac
44 }
46 install_ssh_authorized_keys() {
47 for file in "$(nodedir)"/ssh/authorized_keys_*; do
48 node "$file" || {
49 error "missing authorized_keys file in $(nodedir)/ssh/"
50 return 1
51 }
52 user=${file##*_}
53 id -u "$user" >/dev/null || return 1
54 home=$(getent passwd "$user" | awk -F: '{ print $6 }')
55 sshdir=$home/.ssh
56 mkdir -p "$sshdir"
57 chmod 700 "$sshdir"
58 install -m 600 -o "$(id -u "$user"):$(id -g "$user")" "$file" "$sshdir/authorized_keys"
59 chown -R "$(id -u "$user"):$(id -g "$user")" "$sshdir"
60 done
61 }