Debian Codegraph @

bin/fai-setup

raw symbols SCIP
1 #! /bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 #*********************************************************************
4 #
5 # fai-setup -- set up FAI
6 #
7 # This script is part of FAI (Fully Automatic Installation)
8 # (c) 2000-2026 by Thomas Lange, [email protected]
9 # Universitaet zu Koeln
10 #
11 #*********************************************************************
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
21 #
22 # A copy of the GNU General Public License is available as
23 # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
24 # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
25 # can also obtain it by writing to the Free Software Foundation, Inc.,
26 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27 #*********************************************************************
28
29 PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbinscip-shell filesystem . . `/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin`.
30
31 set -e
32
33 cfdir=/etc/faiscip-shell filesystem . . `/etc/fai`.
34
35 options=$@ # all options are also passed to fai-make-nfsroot
36
37 while getopts pPvC:efgkKV:B: opt ; do
38 case "$opt" in
39 C) cfdir=$OPTARG ;;
40 v) verbose=1 ; v=-v ;;
41 e) expert=1 ;;
42 esac
43 done
44
45
46 . $cfdir/fai.conf
47 . $cfdir/nfsroot.conf
48
49 : ${FAI_LOGPROTO:=ssh}
50
51 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52 add_export_linescip-shell shell fai 6.6 add_export_line().() {
53
54 # add a line to /etc/exports
55
56 pattern=$1
57 shift
58 options="$@"
59
60 [scip-shell system . . `[`. -f /etc/exportsscip-shell filesystem . . `/etc/exports`. ] && grepscip-shell system . . grep. -q "^$pattern[[:space:]]" /etc/exportsscip-shell filesystem . . `/etc/exports`. && return
61 echoscip-shell system . . echo. "Adding line to /etc/exports: $pattern $options"
62 echoscip-shell system . . echo. "$pattern $options" >> /etc/exportsscip-shell filesystem . . `/etc/exports`.
63 }
64 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
65 add_fai_accountscip-shell shell fai 6.6 add_fai_account().() {
66
67 if idscip-shell system . . id. $LOGUSER 2>/dev/nullscip-shell filesystem . . `/dev/null`. 1>&2 ; then
68 echoscip-shell system . . echo. Account \$LOGUSER=$LOGUSER already exists.
69 echoscip-shell system . . echo. Make sure that all install clients can
70 echoscip-shell system . . echo. log into this account without a password.
71 return
72 fi
73
74 adduserscip-shell system . . adduser. --system --disabled-password --home /var/log/fai/remote-logsscip-shell filesystem . . `/var/log/fai/remote-logs`. --gecos "FAI account for remote log files" --shell /bin/shscip-shell filesystem . . `/bin/sh`. $LOGUSER
75 # get the home dir of a user in a variable; do not exit when set -e is used
76 # loguserhome is unset if $LOGUSER does not exists
77 # this is not a evil hack, it's a very clever piece of code
78 loguserhome=$(eval "cd ~$LOGUSER 2>/dev/null && pwd;true")
79 touchscip-shell system . . touch. $loguserhome/.account_created_by_fai_package
80 }
81 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82 setup_fai_accountscip-shell shell fai 6.6 setup_fai_account().() {
83
84 # most things should be executed as user $LOGUSER, since root may not have write
85 # permissions to $loguserhome (e.g if mount via NFS without no_root_squash)
86
87 set +e
88 loguserhome=$(eval "cd ~$LOGUSER 2>/dev/null && pwd;true")
89 sshdir=$loguserhome/.ssh
90 if [scip-shell system . . `[`. -z "$loguserhome" ]; then
91 echoscip-shell system . . echo. "Can't determine home directory for user $LOGUSER."
92 echoscip-shell system . . echo. "LOGUSER= $LOGUSER loguserhome= $loguserhome"
93 exit 8
94 fi
95
96 if [scip-shell system . . `[`. "$FAI_LOGPROTO" = "ssh" ]; then
97 # set up ssh on the server
98 mkdirscip-shell system . . mkdir. -p -m 700 $loguserhome/.ssh
99
100 #Generating keys for LOGUSER
101 [scip-shell system . . `[`. -f $sshdir/id_rsa ] || {
102 ssh-keygenscip-shell system . . ssh-keygen. -t rsa -N '' -f $sshdir/id_rsa -C "$LOGUSER@$HOSTNAME"
103 catscip-shell system . . cat. $sshdir/id_rsa.pub >> $sshdir/authorized_keys
104 }
105
106 [scip-shell system . . `[`. -f $sshdir/id_ed25519 ] || {
107 ssh-keygenscip-shell system . . ssh-keygen. -t ed25519 -N '' -f $sshdir/id_ed25519 -C "$LOGUSER@$HOSTNAME"
108 catscip-shell system . . cat. $sshdir/id_ed25519.pub >> $sshdir/authorized_keys
109 }
110
111 [scip-shell system . . `[`. -f $sshdir/id_ecdsa ] || {
112 ssh-keygenscip-shell system . . ssh-keygen. -t ecdsa -N '' -f $sshdir/id_ecdsa -C "$LOGUSER@$HOSTNAME"
113 catscip-shell system . . cat. $sshdir/id_ecdsa.pub >> $sshdir/authorized_keys
114 }
115
116 #Adding servers keys to known_hosts list of LOGUSER.
117 #So that installed clients can ssh $LOGUSER@$HOSTNAME without password
118 if [scip-shell system . . `[`. ! -f $sshdir/known_hosts ]; then
119 [scip-shell system . . `[`. -f /etc/ssh/ssh_host_ed25519_key.pubscip-shell filesystem . . `/etc/ssh/ssh_host_ed25519_key.pub`. ] && ED25519SERVER=$(sedscip-shell system . . sed. -e "s/= .*$/=/" /etc/ssh/ssh_host_ed25519_key.pubscip-shell filesystem . . `/etc/ssh/ssh_host_ed25519_key.pub`.)
120 [scip-shell system . . `[`. -f /etc/ssh/ssh_host_rsa_key.pubscip-shell filesystem . . `/etc/ssh/ssh_host_rsa_key.pub`. ] && RSASERVER=$(sedscip-shell system . . sed. -e "s/= .*$/=/" /etc/ssh/ssh_host_rsa_key.pubscip-shell filesystem . . `/etc/ssh/ssh_host_rsa_key.pub`. )
121 [scip-shell system . . `[`. -f /etc/ssh/ssh_host_ecdsa_key.pubscip-shell filesystem . . `/etc/ssh/ssh_host_ecdsa_key.pub`. ] && ECDSASERVER=$(sedscip-shell system . . sed. -e "s/= .*$/=/" /etc/ssh/ssh_host_ecdsa_key.pubscip-shell filesystem . . `/etc/ssh/ssh_host_ecdsa_key.pub`. )
122 # determine all IP addresses, and their host names
123 ips=$(ip addr show up| grepscip-shell system . . grep. -P -o '(?<=inet )[^/]+' | grepscip-shell system . . grep. -v 127.0.0.1)
124 for ip in $ips; do
125 hname=$(getentscip-shell system . . getent. hosts $ip| trscip-shell system . . tr. -s ' ' ',')
126 : ${hname:=$ip}
127 echoscip-shell system . . echo. "Adding $hname to known_hosts."
128 [scip-shell system . . `[`. -z "$ED25519SERVER" ] || echoscip-shell system . . echo. "$hname $ED25519SERVER" >> $sshdir/known_hosts
129 [scip-shell system . . `[`. -z "$RSASERVER" ] || echoscip-shell system . . echo. "$hname $RSASERVER" >> $sshdir/known_hosts
130 [scip-shell system . . `[`. -z "$ECDSASERVER" ] || echoscip-shell system . . echo. "$hname $ECDSASERVER" >> $sshdir/known_hosts
131 done
132 echoscip-shell system . . echo. "$sshdir/known_hosts created."
133 else
134 echoscip-shell system . . echo. "$sshdir/known_hosts remained unchanged."
135 fi
136
137 chmodscip-shell system . . chmod. 0600 $sshdir/authorized_keys
138 echoscip-shell system . . echo. "$sshdir/authorized_keys created."
139 fi
140 if [scip-shell system . . `[`. "$FAI_LOGPROTO" = "rsh" ] && [scip-shell system . . `[`. ! -f $loguserhome/.rhosts ]; then
141 # use .rhosts authentication
142 echoscip-shell system . . echo. "+@faiclients root" > $loguserhome/.rhosts
143 chmodscip-shell system . . chmod. go-rwx $loguserhome/.rhosts
144 echoscip-shell system . . echo. "$loguserhome/.rhosts created."
145 fi
146
147 logusergid=$(idscip-shell system . . id. -ng $LOGUSER)
148 echoscip-shell system . . echo. "User account $LOGUSER set up."
149 set -e
150 }
151 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
152
153 { # start huge block for capturing output
154
155 if [scip-shell system . . `[`. -n "$LOGUSER" ]; then
156 add_fai_accountscip-shell shell fai 6.6 add_fai_account().
157 setup_fai_accountscip-shell shell fai 6.6 setup_fai_account().
158 fi
159
160 cpscip-shell system . . cp. /dev/nullscip-shell filesystem . . `/dev/null`. /var/log/fai/variablesscip-shell filesystem . . `/var/log/fai/variables`.
161 set +e
162 if ! fai-make-nfsroot $options ; then
163 echoscip-shell system . . echo. "ERROR when calling fai-make-nfsroot."
164 exit 9
165 fi
166 set -e
167
168 if [scip-shell system . . `[`. -n "$LOGUSER" ]; then
169 # chown only if cd was successful
170 if cd $loguserhome; then
171 [scip-shell system . . `[`. -e .rhosts ] && chownscip-shell system . . chown. $LOGUSER:$logusergid . .rhosts || truescip-shell system . . true.
172 [scip-shell system . . `[`. -d .ssh ] && chownscip-shell system . . chown. -R $LOGUSER:$logusergid .ssh || truescip-shell system . . true.
173 fi
174 mkdirscip-shell system . . mkdir. -p $TFTPROOT
175 chownscip-shell system . . chown. -R $LOGUSER:$logusergid $TFTPROOT || truescip-shell system . . true.
176 fai-chboot -o default
177 fi
178
179 if [scip-shell system . . `[`. -z "$FAI_CONFIGDIR" ]; then
180 echoscip-shell system . . echo. "FAI_CONFIGDIR not set in /etc/fai/nfsroot.conf."
181 exit 7
182 fi
183 mkdirscip-shell system . . mkdir. -p $FAI_CONFIGDIR
184
185 # in expert mode, do not export nfs directories
186 if [scip-shell system . . `[`. -z "$expert" ]; then
187 # by default use the first interface which is up
188 if [scip-shell system . . `[`. -z "$SERVERINTERFACE" ]; then
189 opt="up"
190 else
191 opt="dev $SERVERINTERFACE"
192 fi
193 nip=$(ip -br ad show $opt | awkscip-shell system . . awk. '/UP / {if ($3) print $3}scip-shell filesystem . . `/UP / {if ($3) print $3}`.' | wcscip-shell system . . wc. -l)
194 iprange=$(ip -br ad show $opt | awkscip-shell system . . awk. '/UP / {if ($3) print $3}scip-shell filesystem . . `/UP / {if ($3) print $3}`.' | headscip-shell system . . head. -1)
195 myip=${iprange%/*}
196 if [scip-shell system . . `[`. $nip -gt 1 ]; then
197 echoscip-shell system . . echo. "Warning. More than one network interface found for FAI server."
198 echoscip-shell system . . echo. "Using IP address $myip. Please set \$SERVERINTERFACE in"
199 echoscip-shell system . . echo. "nfsroot.conf if you want to use another interface."
200 fi
201 echoscip-shell system . . echo. "FAI_CONFIGDIR=$FAI_CONFIGDIR" >> /var/log/fai/variablesscip-shell filesystem . . `/var/log/fai/variables`.
202 echoscip-shell system . . echo. "FAI_CONFIG_SRC=nfs://${myip}$FAI_CONFIGDIR" >> /var/log/fai/variablesscip-shell filesystem . . `/var/log/fai/variables`.
203
204 add_export_linescip-shell shell fai 6.6 add_export_line(). $FAI_CONFIGDIR "$iprange(async,ro,no_subtree_check)"
205 add_export_linescip-shell shell fai 6.6 add_export_line(). $NFSROOT "$iprange(async,ro,no_subtree_check,no_root_squash)"
206 systemctl reload-or-restart nfs-kernel-server
207 fi
208
209 if [scip-shell system . . `[`. ! -d $FAI_CONFIGDIR/class ]; then
210 fai-mk-configspace
211 echoscip-shell system . . echo. "Please don't forget to fill out the FAI questionnaire after you've finished your project with FAI."
212 echoscip-shell system . . echo. ""
213 fi
214 echoscip-shell system . . echo. "FAI setup finished."
215 } |& teescip-shell system . . tee. /var/log/fai/fai-setup.logscip-shell filesystem . . `/var/log/fai/fai-setup.log`.
216 RC=${PIPESTATUS[0]}
217 echoscip-shell system . . echo. "Log file written to /var/log/fai/fai-setup.log"
218 exit ${RC}