Debian Codegraph @

scripts/sbin/drbl-gen-ssi-files

raw symbols SCIP
1 #!/bin/bash
2 # Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 #
5 # Loading setting
6 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
7
8 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
9 [ -e /etc/drbl/drbl-ocs.conf ] && . /etc/drbl/drbl-ocs.conf
10 [ -e $DRBL_SCRIPT_PATH/sbin/ocs-functions ] && . $DRBL_SCRIPT_PATH/sbin/ocs-functions
11 #
12 check_if_root
13 # drbl_deploy.conf can only be access by root, so check_if_root should be run first.
14 . /etc/drbl/drbl_deploy.conf
15 #
16 USAGE() {
17 echo "Usage: $0 Options"
18 echo "Options:"
19 echo "-n, --no-stop-ocs do NOT stop ocs. (It's better to stop OCS so that the unnecessary services in rc1.d will be removed!)."
20 echo "-h, --help display this help and exit"
21 echo "-x, --exclude-X-config when creating template, exclude X config."
22 echo "-t, --template HOST use HOST as the template to create etc and var tarballs. If not assigned, $0 will find the first client one in dir $drblroot."
23 echo "Example:"
24 echo "$0 -t 192.168.1.1"
25 }
26
27 # default settings
28 stop_ocs="yes"
29 template=""
30 # Parse command-line options
31 while [ $# -gt 0 ]; do
32 case "$1" in
33 -n|--no-stop-ocs)
34 stop_ocs="no"
35 shift;;
36 -h|--help)
37 USAGE >& 2
38 exit 2 ;;
39 -x|--exclude-X-config)
40 exclude_template_X_conf="yes"
41 shift;;
42 -t|--template)
43 shift
44 if [ -z "$(echo $1 |grep ^-.)" ]; then
45 # skip the -xx option, in case
46 template="$1"
47 shift
48 fi
49 ;;
50 -*) echo "${0}: ${1}: invalid option" >&2
51 USAGE >& 2
52 exit 2 ;;
53 *) break ;;
54 esac
55 done
56
57 # check if template exists.
58 if [ -n "$template" -a ! -d "$drblroot/$template" ]; then
59 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
60 echo "$drblroot/$template is not found!"
61 echo "Template client does NOT exist! Program terminated!!!"
62 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
63 exit 1
64 fi
65
66 # default is to stop ocs so that we can get the clean rc1.d
67 if [ "$stop_ocs" = "yes" ]; then
68 echo "*****************************************************"
69 if [ -x $DRBL_SCRIPT_PATH/sbin/drbl-ocs ]; then
70 echo -n "Trying to stop clonezilla if necessary so that the unnecessary services in rc1.d will be removed... "
71 $DRBL_SCRIPT_PATH/sbin/drbl-ocs -n -l 0 stop &>/dev/null
72 echo "done!"
73 fi
74 echo "*****************************************************"
75 fi
76 # We need $drbl_common_root/drbl_ssi/rc1.d/ for SSI clonezilla, root_ssh_key for root's ssh public key.
77 rm -rf $drbl_common_root/drbl_ssi/root_ssh_key
78 mkdir -p $drbl_common_root/drbl_ssi/{rc1.d,root_ssh_key}
79 # Clean the old files if they exist
80 rm -f $drbl_common_root/drbl_ssi/{template_root.tgz,template_etc.tgz,template_var.tgz,template_opt.tgz}
81 # Find the template client
82 if [ -z "$template" ]; then
83 for ih in $drblroot/*; do
84 # use the 1st one drbl client we found as template
85 if [ -d "$ih" ]; then
86 template="$ih"
87 break
88 fi
89 done
90 else
91 # append to full path
92 template="$drblroot/$template"
93 fi
94 echo "Using template host $template"
95 # If any reason, some stale files are still in DRBL SSI /tftpboot/node_root/drbl_ssi/rc1.d, reset them
96 [ "$copy_rc1d_for_drbl_ssi_clone_box" = "yes" ] && remove_rc1d_for_drbl_ssi $template
97
98 # Generate the ssh hostkey for the template so that client won't have to generate.
99 drbl-gen-ssh-host-keys generate "$(basename $template)"
100
101 #
102 if [ "$exclude_template_X_conf" = "yes" ]; then
103 echo "Excluding X config in DRBL SSI template."
104 etc_exclude_X_files="xorg.conf XF86Config XF86Config-4"
105 fi
106
107 #
108 etc_exclude_opt=""
109 for ietc in $etc_exclude_dirs $etc_exclude_X_files; do
110 etc_exclude_opt="$etc_exclude_opt --exclude=$ietc"
111 done
112
113 echo -n "Generating the files for DRBL single system image template... "
114 # use only one drbl client as template, the 1st one.
115 echo -n "root... "
116 (cd $template/; tar -czf $drbl_common_root/drbl_ssi/template_root.tgz root)
117 echo -n "etc... "
118 (cd $template/; tar $etc_exclude_opt -czf $drbl_common_root/drbl_ssi/template_etc.tgz etc)
119 echo -n "var... "
120 # 2 >/dev/null to avoid some warnings about socket files in /var/
121 (cd $template/; tar -czf $drbl_common_root/drbl_ssi/template_var.tgz var 2>/dev/null)
122 # make them can read by root only, better security
123 chmod 600 $drbl_common_root/drbl_ssi/template_*.tgz
124
125 #
126 echo -n "Root's openssh public key... "
127 # For ssh public key
128 if [ ! -f /root/.ssh/id_rsa ]; then
129 #$DRBL_SCRIPT_PATH/sbin/autosshkeygen $USER
130 ssh-keygen -t rsa -q -f /root/.ssh/id_rsa -N ""
131 fi
132 if [ -f /root/.ssh/id_rsa.pub ]; then
133 cp -f /root/.ssh/id_rsa.pub $drbl_common_root/drbl_ssi/root_ssh_key/authorized_keys
134 fi
135
136 # Create a template dir for client
137 mkdir -p $drbl_common_root/drbl_ssi/clients
138 cat <<-CLI_END > $drbl_common_root/drbl_ssi/clients/00_README
139 To overwrite or put some files to DRBL SSI clients, you can put the corresponding dir and files in this directory. When client boots, it will sync them.
140 For example, if you want to overwrite the /etc/X11/xorg.conf for client with IP address 192.168.50.2, then you can
141 1. Create a directory "192.168.50.2/etc/X11/" in this directory (By "mkdir -p 192.168.50.2/etc/X11/")
142 2. Copy a xorg.conf to 192.168.50.2/etc/X11/
143 Therefore next time when client boots, it will copy 192.168.50.2/etc/X11/xorg.conf to its /etc/X11/xorg.conf.
144 # Schematic
145 $drbl_common_root/drbl_ssi/clients/192.168.50.1/etc/X11/xorg.conf -> 192.168.50.1:/etc/X11/xorg.conf
146 $drbl_common_root/drbl_ssi/clients/192.168.50.2/etc/X11/xorg.conf -> 192.168.50.2:/etc/X11/xorg.conf
147
148 CLI_END
149
150 # Output drbl/clonezilla related packages info in /drbl_ssi/.
151 rm -f $drbl_common_root/drbl_ssi/DRBL-Clonezilla-related-pkgs.txt
152 output_ocs_related_pkgs $drbl_common_root/drbl_ssi DRBL-Clonezilla-related-pkgs.txt
153
154 echo "done!"