| 1 | #!/bin/bash |
| 2 | # Author: Steven Shiau <steven _at_ clonezilla org> |
| 3 | # License: GPL |
| 4 | # |
| 5 | # set the NFS, NIS, NAT config for DRBL clients to access |
| 6 | |
| 7 | # Load DRBL setting and functions |
| 8 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 9 | |
| 10 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 11 | |
| 12 | # |
| 13 | check_if_root |
| 14 | |
| 15 | # main |
| 16 | usage() { |
| 17 | echo "To generate or clean NFS, NIS and NAT setting for DRBL clients to access" |
| 18 | echo "Usage: $0 [Options] {generate|clean}" |
| 19 | echo "Options:" |
| 20 | echo "-a, --all-subnet: All subnet can access to this NFS/NIS/NAT server." |
| 21 | echo "-n, --no-restart: Do not restart NFS/NIS services (except NAT, i.e. NAT will always be restarted)" |
| 22 | echo "-v, --verbose: Verbose mode." |
| 23 | echo "Example: To generate NFS, NIS and NAT setting for DRBL clients to access" |
| 24 | echo "$0 generate" |
| 25 | } |
| 26 | |
| 27 | # default setting |
| 28 | all_subnet="no" |
| 29 | restart_srv="yes" |
| 30 | |
| 31 | while [ $# -gt 0 ]; do |
| 32 | case "$1" in |
| 33 | -a|--all-subnet) |
| 34 | all_subnet="yes" |
| 35 | shift;; |
| 36 | -n|--no-restart) |
| 37 | restart_srv="no" |
| 38 | shift;; |
| 39 | -v|--verbose) |
| 40 | shift; verbose="on" |
| 41 | ;; |
| 42 | -*) echo "${0}: ${1}: invalid option" >&2 |
| 43 | usage >& 2 |
| 44 | exit 2 ;; |
| 45 | *) break ;; |
| 46 | esac |
| 47 | done |
| 48 | switch=$1 |
| 49 | |
| 50 | [ -z "$switch" ] && usage && exit 1 |
| 51 | ask_and_load_lang_set en |
| 52 | |
| 53 | [ "$all_subnet" = "yes" ] && SUBNET_OPT="--all-subnet" |
| 54 | [ "$restart_srv" = "no" ] && RESTART_OPT="--no-restart" |
| 55 | # load the preset mode |
| 56 | [ -f "/etc/drbl/drbl_deploy.conf" ] && . /etc/drbl/drbl_deploy.conf |
| 57 | if [ "$drbl_mode" != "drbl_ssi_mode" ]; then |
| 58 | [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 59 | echo "$msg_not_in_SSI_mode" |
| 60 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 61 | echo "$msg_program_stop" |
| 62 | exit 1 |
| 63 | fi |
| 64 | |
| 65 | # update /etc/hosts |
| 66 | drbl-etc-hosts |
| 67 | # Update the /etc/hosts in clients |
| 68 | # Find the template client |
| 69 | for ih in $drblroot/*; do |
| 70 | # use the 1st one drbl client we found as template |
| 71 | if [ -d "$ih" ]; then |
| 72 | template="$ih" |
| 73 | break |
| 74 | fi |
| 75 | done |
| 76 | cp -f /etc/hosts $drbl_common_root/etc/hosts |
| 77 | cp -f /etc/hosts $template/etc/hosts |
| 78 | |
| 79 | case "$switch" in |
| 80 | "generate") |
| 81 | drbl-nfs-exports $SUBNET_OPT $RESTART_OPT generate |
| 82 | echo "$msg_delimiter_star_line" |
| 83 | drbl-yp-securenets $SUBNET_OPT $RESTART_OPT generate |
| 84 | echo "$msg_delimiter_star_line" |
| 85 | drbl-nat-rules $SUBNET_OPT generate |
| 86 | echo "done!" |
| 87 | ;; |
| 88 | "clean") |
| 89 | drbl-nfs-exports clean |
| 90 | echo "$msg_delimiter_star_line" |
| 91 | drbl-yp-securenets clean |
| 92 | echo "$msg_delimiter_star_line" |
| 93 | drbl-nat-rules clean |
| 94 | echo "done!" |
| 95 | ;; |
| 96 | *) |
| 97 | usage |
| 98 | exit 1 |
| 99 | ;; |
| 100 | esac |