Debian Codegraph @

lib/get-config-dir

raw
1 #!/bin/bash
2
3 #
4 # (c) 2006 Henning Glawe <[email protected]>
5 # (c) 2009-2025 Thomas Lange <[email protected]>
6
7 ### BEGIN SUBROUTINE INFO
8 # Provides-Var:
9 # Requires-Var: $FAI_CONFIG_SRC $FAI
10 # Suggests-Var:
11 # Short-Description: get $FAI directory from $FAI_CONFIG_SRC
12 ### END SUBROUTINE INFO
13
14 if [ -z "$FAI_CONFIG_SRC" ]; then
15 sendmon "TASKERROR get_fai_dir 21"
16 echo "ERROR: No URL defined for the config space." >&2
17 echo "ERROR: Set \$FAI_CONFIG_SRC by using fai-chboot -u or use option -s when calling fai directly." >&2
18 exit 21
19 fi
20
21 echo "FAI_CONFIG_SRC is set to $FAI_CONFIG_SRC"
22
23 # extract method to get the config dir
24 # matched string: "cvs[+ssh]://user@host/path/to/cvsroot module[=tag]"
25 # ^^^
26 # "nfs://host/path/to/exported/config"
27 # ^^^
28 # the "major" protocol name is the one up to the first "+", if it exists
29 method=$(expr match "$FAI_CONFIG_SRC" '\([^+]*\).*://')
30
31 if [ -z "$method" ]; then
32 sendmon "TASKERROR get_fai_dir 22"
33 echo "Error in get-config-dir: scheme undefined." >&2
34 exit 24
35 echo
36 fi
37
38 [ -z "$FAI" -a $method != "file" ] && echo "WARNING: \$FAI is undefined. Let's see if it still works."
39
40 mkdir -m 0750 -p $FAI
41
42 # run get-config-dir-$method script if it exists
43 if command -v get-config-dir-$method &>/dev/null ; then
44 get-config-dir-$method
45 # check for errors
46 lerror=$(< $LOGDIR/task_local_error)
47 if [ "$lerror" -ne 0 ]; then
48 exit 25
49 fi
50 else
51 sendmon "TASKERROR get_fai_dir 22"
52 echo "Error: get-config-dir-"$method "not found" >&2
53 exit 22
54 fi
55
56 if [ $method = "file" ]; then
57 localpath=$(expr match "$FAI_CONFIG_SRC" '.*://\(/.*\)')
58 export FAI=$localpath
59 fi
60
61 ln -snf $FAI /var/run/fai/current_config
62 if [ ! -d $FAI/class ]; then
63 echo "WARNING: directory $FAI/class not found." >&2
64 sendmon "TASKERROR get_fai_dir 23"
65 exit 23
66 fi
67 exit 0