Debian Codegraph @

scripts/sbin/drbl-gen-ssi-files

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/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 [scip-shell system . . `[`. -e /etc/drbl/drbl-ocs.confscip-shell filesystem . . `/etc/drbl/drbl-ocs.conf`. ] && . /etc/drbl/drbl-ocs.confscip-shell source . . `/etc/drbl/drbl-ocs.conf`.
10 [scip-shell system . . `[`. -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.confscip-shell source . . `/etc/drbl/drbl_deploy.conf`.
15 #
16 USAGEscip-shell shell shell-project 0.0.0 USAGE().() {
17 echoscip-shell system . . echo. "Usage: $0 Options"
18 echoscip-shell system . . echo. "Options:"
19 echoscip-shell system . . 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 echoscip-shell system . . echo. "-h, --help display this help and exit"
21 echoscip-shell system . . echo. "-x, --exclude-X-config when creating template, exclude X config."
22 echoscip-shell system . . 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 echoscip-shell system . . echo. "Example:"
24 echoscip-shell system . . 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 [scip-shell system . . `[`. $# -gt 0 ]; do
32 case "$1" in
33 -n|--no-stop-ocs)
34 stop_ocs="no"
35 shift;;
36 -h|--help)
37 USAGEscip-shell shell shell-project 0.0.0 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 [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then
45 # skip the -xx option, in case
46 template="$1"
47 shift
48 fi
49 ;;
50 -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2
51 USAGEscip-shell shell shell-project 0.0.0 USAGE(). >& 2
52 exit 2 ;;
53 *) break ;;
54 esac
55 done
56
57 # check if template exists.
58 if [scip-shell system . . `[`. -n "$template" -a ! -d "$drblroot/$template" ]; then
59 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
60 echoscip-shell system . . echo. "$drblroot/$template is not found!"
61 echoscip-shell system . . echo. "Template client does NOT exist! Program terminated!!!"
62 [scip-shell system . . `[`. "$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 [scip-shell system . . `[`. "$stop_ocs" = "yes" ]; then
68 echoscip-shell system . . echo. "*****************************************************"
69 if [scip-shell system . . `[`. -x $DRBL_SCRIPT_PATH/sbin/drbl-ocs ]; then
70 echoscip-shell system . . 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/nullscip-shell filesystem . . `/dev/null`.
72 echoscip-shell system . . echo. "done!"
73 fi
74 echoscip-shell system . . 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 rmscip-shell system . . rm. -rf $drbl_common_root/drbl_ssi/root_ssh_key
78 mkdirscip-shell system . . mkdir. -p $drbl_common_root/drbl_ssi/{rc1.d,root_ssh_key}
79 # Clean the old files if they exist
80 rmscip-shell system . . 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 [scip-shell system . . `[`. -z "$template" ]; then
83 for ih in $drblroot/*; do
84 # use the 1st one drbl client we found as template
85 if [scip-shell system . . `[`. -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 echoscip-shell system . . 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 [scip-shell system . . `[`. "$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 "$(basenamescip-shell system . . basename. $template)"
100
101 #
102 if [scip-shell system . . `[`. "$exclude_template_X_conf" = "yes" ]; then
103 echoscip-shell system . . 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 echoscip-shell system . . echo. -n "Generating the files for DRBL single system image template... "
114 # use only one drbl client as template, the 1st one.
115 echoscip-shell system . . echo. -n "root... "
116 (cd $template/; tarscip-shell system . . tar. -czf $drbl_common_root/drbl_ssi/template_root.tgz root)
117 echoscip-shell system . . echo. -n "etc... "
118 (cd $template/; tarscip-shell system . . tar. $etc_exclude_opt -czf $drbl_common_root/drbl_ssi/template_etc.tgz etc)
119 echoscip-shell system . . echo. -n "var... "
120 # 2 >/dev/null to avoid some warnings about socket files in /var/
121 (cd $template/; tarscip-shell system . . tar. -czf $drbl_common_root/drbl_ssi/template_var.tgz var 2>/dev/nullscip-shell filesystem . . `/dev/null`.)
122 # make them can read by root only, better security
123 chmodscip-shell system . . chmod. 600 $drbl_common_root/drbl_ssi/template_*.tgz
124
125 #
126 echoscip-shell system . . echo. -n "Root's openssh public key... "
127 # For ssh public key
128 if [scip-shell system . . `[`. ! -f /root/.ssh/id_rsascip-shell filesystem . . `/root/.ssh/id_rsa`. ]; then
129 #$DRBL_SCRIPT_PATH/sbin/autosshkeygen $USER
130 ssh-keygenscip-shell system . . ssh-keygen. -t rsa -q -f /root/.ssh/id_rsascip-shell filesystem . . `/root/.ssh/id_rsa`. -N ""
131 fi
132 if [scip-shell system . . `[`. -f /root/.ssh/id_rsa.pubscip-shell filesystem . . `/root/.ssh/id_rsa.pub`. ]; then
133 cpscip-shell system . . cp. -f /root/.ssh/id_rsa.pubscip-shell filesystem . . `/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 mkdirscip-shell system . . mkdir. -p $drbl_common_root/drbl_ssi/clients
138 catscip-shell system . . 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 rmscip-shell system . . 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 echoscip-shell system . . echo. "done!"