Remove "sofs" command on nodes
authorMartin Schwenke <martin@meltin.net>
Tue, 24 Jun 2014 01:36:14 +0000 (11:36 +1000)
committerMartin Schwenke <martin@meltin.net>
Wed, 2 Jul 2014 04:17:17 +0000 (14:17 +1000)
"onnode -P" implements the only useful feature.

Signed-off-by: Martin Schwenke <martin@meltin.net>
base/all/usr/bin/sofs [deleted file]

diff --git a/base/all/usr/bin/sofs b/base/all/usr/bin/sofs
deleted file mode 100755 (executable)
index fa85e45..0000000
+++ /dev/null
@@ -1,613 +0,0 @@
-#!/bin/bash
-# simple SoFS command line config script
-#
-# Copyright (C) Andrew Tridgell  2008
-
-# catch errors
-set -e
-set -E
-trap 'es=$?; 
-      echo ERROR: failed in function \"${FUNCNAME}\" at line ${LINENO} of ${BASH_SOURCE[0]} with code $es; 
-      exit $es' ERR
-
-# fail on any element of a pipe failing
-set -o pipefail
-
-optionstext='
-  options:
-    -x           enable script debugging
-    -f           force potentially dangerous operations
-    -e EDITOR    select editor
-    -d LEVEL     choose net debug level
-'
-
-####################
-# show program usage
-usage()
-{
-    cat <<EOF
-Usage: sofs [OPTION] ... <COMMAND>
-$optionstext
-  commands:
-     conf COMMAND
-           configuration commands
-     status
-           show status
-     push FILE
-           push a local file to all nodes
-
-  Use subcommand 'help' for information on a command
-EOF
-    exit 1
-}
-
-
-####################
-# show conf * usage
-sofs_conf_usage()
-{
-    cat <<EOF
-Usage: sofs conf [OPTION] ... <COMMAND>
-$optionstext
-
-  commands:
-     conf list
-           show all config options
-
-     conf show OPTION
-           show a single config option
-
-     conf remove OPTION
-           remove a config option
-
-     conf set OPTION VALUE
-           set a config option
-
-     conf load OPTION FILE
-           set a config option from a file
-
-     conf edit OPTION
-           edit a config option with an external editor
-
-     conf backup FILE
-           backup whole configuration to a file
-
-     conf restore FILE
-           restore whole configuration from a file
-
-     conf init
-           initialise config parms
-
-     conf reload <NODES>
-           reload config on the specifed nodes (all nodes by default)
-EOF
-    exit 1
-}
-
-######################################
-# run an onnode - using -p if possible
-run_onnode() {
-    nodes="$1"
-    shift
-    if grep parallel /usr/bin/onnode > /dev/null; then
-       onnode -qp "$nodes" "$@"
-    else
-       onnode "$nodes" "$@" 2> /dev/null
-    fi
-}
-
-##############################
-# pull samba share from option
-samba_share() {
-    echo "$1" | cut -d/ -f2
-}
-
-##############################
-# pull samba option from option
-samba_option() {
-    echo "$1" | cut -d/ -f3
-}
-
-#############################
-# work out the type of option
-option_type() {
-    case $1 in
-       smbconf)
-           echo "samba"; 
-           ;;
-       smbconf/*/*)
-           echo "sambaoption"
-           ;;
-       smbconf/*)
-           echo "sambashare"
-           ;;
-       /*)
-           echo "file"
-           ;;
-       *)
-           echo "sofs"
-           ;;
-    esac
-}
-
-############################
-# list main config options
-sofs_conf_list() {
-    net -d$netdebug registry enumerate 'HKLM\Software\IBM\SoFS' | egrep '^Valuename..=' | cut -c14- |
-    while IFS= read n; do
-       echo "[$n]"
-       sofs_conf_show "$n" | sed -e "s@^@      @"
-       echo
-    done
-    net -d$netdebug registry enumerate 'HKLM\Software\Samba\smbconf' | egrep '^Keyname' | cut -c13- |
-    while IFS= read n; do
-       echo "[smbconf/$n]"
-       net -d$netdebug conf showshare "$n" | grep -v '^\[' || true
-       echo
-    done
-}
-
-
-############################
-# list a config file
-sofs_conf_listfile() {
-    filename="$1"
-    echo
-    echo "[$filename]"
-    if [ -f "$filename" ]; then
-       cat "$filename" | sed -e "s@^@  @"
-    fi
-}
-
-##############################################
-# list a config file that varies between nodes
-sofs_conf_listfile_nodes() {
-    filename="$1"
-    onnode all "echo; echo \"[$filename:\$HOSTNAME]\"; [ -f \"$filename\" ] && cat \"$filename\" | sed -e 's@^@        @'" 2> /dev/null
-}
-
-
-############################
-# list all options and files
-sofs_conf_listall() {
-    sofs_conf_list
-    sofs_conf_listfile_nodes "/etc/ctdb/public_addresses"
-    sofs_conf_listfile_nodes "/etc/ntp.conf"
-    sofs_conf_listfile "/etc/krb5.conf"
-    sofs_conf_listfile "/etc/samba/smb.conf"
-    sofs_conf_listfile "/etc/hosts"
-    sofs_conf_listfile "/etc/resolv.conf"
-    sofs_conf_listfile "/etc/sysconfig/authconfig"
-    sofs_conf_listfile "/etc/sysconfig/ctdb"
-    sofs_conf_listfile "/etc/sysconfig/vsftpd"
-    sofs_conf_listfile "/etc/sysconfig/http"
-    sofs_conf_listfile "/etc/sysconfig/nfs"
-    sofs_conf_listfile "/etc/nsswitch.conf"
-    sofs_conf_listfile "/etc/pam.d/system-auth-ac"
-    sofs_conf_listfile "/etc/pam.d/vsftpd"
-    sofs_conf_listfile "/etc/rssh.conf"
-    sofs_conf_listfile "/etc/httpd/conf.d/shares.config"
-    sofs_conf_listfile "/etc/vsftpd/vsftpd.conf"
-    sofs_conf_listfile "/var/opt/IBM/sofs/configs/scpexports"
-    sofs_conf_listfile "/var/opt/IBM/sofs/configs/ftpexports"
-    sofs_conf_listfile "/var/opt/IBM/sofs/scproot/etc/nsswitch.conf"
-}
-
-############################
-# backup config options
-sofs_conf_backup() {
-    (
-       cat <<EOF
-# SoFS configuration backup 
-# Date: `date`
-# Host: `hostname`
-EOF
-       sofs_conf_listall 
-    ) > "$1"
-}
-
-############################
-# show one config option
-sofs_conf_show() {(
-    option="$1"
-    case `option_type $option` in
-       samba)
-           net -d$netdebug conf list
-           ;;
-       sambaoption)
-           net -d$netdebug conf getparm "`samba_share \"$option\"`" "`samba_option \"$option\"`"
-           ;;
-       sambashare)
-           net -d$netdebug conf showshare "`samba_share \"$option\"`" | egrep '^[      ]'
-           ;;
-       sofs)
-           net -d$netdebug registry getvalueraw 'HKLM\Software\IBM\SoFS' "$option"
-           ;;
-       file)
-           cat "$option"
-           ;;
-    esac
-)}
-
-############################
-# set a config option
-sofs_conf_set() {(
-    option="$1"
-    value="$2"
-    case `option_type $option` in
-       sambaoption)
-           net -d$netdebug conf setparm "`samba_share \"$option\"`" "`samba_option \"$option\"`" "$value"
-           ;;
-
-       samba) 
-           tmpfile=`mktemp -p /tmp sofs.XXXXXX`
-           echo "$value" > $tmpfile
-           if testparm -s $tmpfile 2>&1 | egrep '^WARNING|^ERROR|^Unknown'; then
-               echo "Bad config options - not setting"
-               rm -f $tmpfile
-               exit 1
-           fi
-           net -d$netdebug conf import $tmpfile || {
-               rm -f $tmpfile
-               echo "ERROR: Failed to import smbconf"
-               exit 1
-           }
-           rm -f $tmpfile
-           ;;
-
-       sambashare)
-           tmpfile=`mktemp -p /tmp sofs.XXXXXX`
-           share="`samba_share \"$option\"`"
-           echo "[$share]" >> $tmpfile
-           echo "$value" >> $tmpfile
-           if testparm -s $tmpfile 2>&1 | egrep '^WARNING|^ERROR|^Unknown'; then
-               echo "Bad config options - not setting"
-               rm -f $tmpfile
-               exit 1
-           fi
-           net -d$netdebug conf import $tmpfile $share || {
-               rm -f $tmpfile
-               echo "ERROR: Failed to import share $share"
-               exit 1
-           }
-           rm -f $tmpfile
-           ;;
-
-       sofs)
-           net -d$netdebug registry setvalue 'HKLM\Software\IBM\SoFS' "$option" "SZ" "$value"  || {
-               rm -f $tmpfile
-               echo "ERROR: Failed to set registry value $option"
-               exit 1
-           }
-
-           ;;
-
-       file)
-           case "$option" in
-               *:*)
-                   d=`dirname "$option"`
-                   run_onnode all "mkdir -p \"$d\""
-                   host=`echo "$option" | cut -d: -f2`
-                   opt=`echo "$option" | cut -d: -f1`
-                   tmpfile=`mktemp -p /tmp sofs.XXXXXX`
-                   echo "$value" > "$tmpfile"
-                   rsync $tmpfile $host:$opt
-                   rm -f $tmpfile
-                   ;;
-               *)
-                   d=`dirname "$option"`
-                   mkdir -p "$d"
-                   echo "$value" > "$option"
-
-                   run_onnode all "mkdir -p \"$d\"; rsync $HOSTNAME:\"$option\" \"$option\" 2> /dev/null"
-                   ;;
-           esac
-           ;;
-           
-    esac
-)}
-
-############################
-# remove a config option
-sofs_conf_remove() {(
-    option="$1"
-    case `option_type $option` in
-       samba)
-           echo "To remove entire Samba config please use 'net conf drop'"
-           ;;
-
-       sambaoption)
-           net -d$netdebug conf delparm "`samba_share \"$option\"`" "`samba_option \"$option\"`"
-           ;;
-
-       sambashare)
-           net -d$netdebug conf delshare "`samba_share \"$option\"`"
-           ;;
-
-       sofs)
-           net -d$netdebug registry deletevalue 'HKLM\Software\IBM\SoFS' "$option"
-           ;;
-
-       file)
-           rm -f "$option"
-           ;;
-    esac
-)}
-
-
-############################
-# load a config option from a file
-sofs_conf_load() {(
-    option="$1"
-    file="$2"
-    sofs_conf_set "$option" "`cat $file`"
-)}
-
-############################
-# edit a config option 
-sofs_conf_edit() {(
-    option="$1"
-    editor=""
-    [ "$editor" = "" ] && editor="$EDITOR"
-    [ "$editor" = "" ] && editor="$VISUAL"
-    [ "$editor" = "" ] && editor="vi"
-    tmpfile=`mktemp -p /tmp sofs.XXXXXX`
-    sofs_conf_show "$option" > $tmpfile || true
-    sum1=`md5sum $tmpfile`
-    $editor $tmpfile
-    sum2=`md5sum $tmpfile`
-    if [ "$sum1" = "$sum2" ]; then
-       echo "$option unchanged"
-    else
-       sofs_conf_load "$option" "$tmpfile"
-       echo "$option changed"
-    fi
-    rm -f $tmpfile
-)}
-
-
-############################
-# restore all config options
-sofs_conf_restore() {(
-    sofs_conf_init
-    filename="$1"
-    tmpfile=`mktemp -p /tmp sofs.XXXXXX`
-    option=""
-    while IFS= read line; do
-       case "$line" in
-           \#*)
-               ;;
-           [*)
-               [ "$option" = "" ] || {
-                   echo "Loading option $option"
-                   sofs_conf_load "$option" "$tmpfile"
-               }
-               option=`echo "$line" | cut -d'[' -f2 | cut -d']' -f1`
-               /bin/cp /dev/null $tmpfile
-               ;;
-           *)
-               echo "$line" | sed -e "s@^      @@" >> $tmpfile
-               ;;
-       esac
-    done < "$filename"
-    [ "$option" = "" ] || {
-       echo "Loading option $option"
-       sofs_conf_load "$option" "$tmpfile"
-    }
-    rm -f $tmpfile
-
-    # now the tricky bit - delete any options that were not
-    # set in the backup
-    sofs_conf_listall | grep '^\[' | cut -d'[' -f2 | cut -d']' -f1 | sort -u > $tmpfile.1
-    cat "$filename" | grep '^\[' | cut -d'[' -f2 | cut -d']' -f1 | sort -u > $tmpfile.2
-    comm -23 $tmpfile.1 $tmpfile.2 | 
-    while IFS= read line; do
-       if [ "$force" = "1" ]; then
-           sofs_conf_remove "$line" || true
-           echo "Removed option $line"
-       else 
-           echo "force not set: Not removing option $line"
-       fi
-    done
-    rm -f $tmpfile.1 $tmpfile.2
-)}
-
-
-############################
-# initialise registry config 
-sofs_conf_init() {
-    net -d$netdebug registry createkey 'HKLM' > /dev/null
-    net -d$netdebug registry createkey 'HKLM\Software' > /dev/null
-    net -d$netdebug registry createkey 'HKLM\Software\IBM' > /dev/null
-    net -d$netdebug registry createkey 'HKLM\Software\IBM\SoFS' > /dev/null
-    net -d$netdebug registry createkey 'HKLM\Software\Samba' > /dev/null
-    net -d$netdebug registry createkey 'HKLM\Software\Samba\smbconf' > /dev/null
-    net -d$netdebug registry createkey 'HKLM\Software\Samba\global' > /dev/null
-}
-
-###############
-# reload config
-sofs_conf_reload() {
-    ctdb -n "$1" eventscript reload
-}
-
-###############
-# show status usage
-sofs_status_usage() {
-    cat <<EOF
-Usage: sofs status
-
-   Shows cluster status and public IP assignment
-EOF
-    exit 1    
-}
-
-
-###############
-# show status
-sofs_status() {
-    ctdb status
-    ctdb ip -n all
-    mmgetstate -a
-}
-
-
-###############
-# show push usage
-sofs_push_usage() {
-    cat <<EOF
-Usage: sofs push FILES
-
-   Pushes some files from the current node to all nodes
-EOF
-    exit 1    
-}
-
-
-###############
-# push files
-sofs_push() {
-    for f in $*; do
-       echo "Pushing $f"
-       if [ "${f:0:1}" = "/" ]; then
-           run_onnode all rsync $HOSTNAME:$f $f
-       else
-           run_onnode all rsync $HOSTNAME:$PWD/$f $PWD/$f
-       fi
-    done
-}
-
-
-############################
-# list all shares
-sofs_shares() {
-    (sofs_conf_show ftpexports | cut -d= -f1 ;
-    sofs_conf_show httpexports | egrep '^RewriteRule' | cut -d/ -f2 | cut -d\( -f1;
-    sofs_conf_show nfssharenames | egrep '^/' | cut -d= -f2 ; 
-    sofs_conf_show scpexports | cut -d= -f1 ;
-    net -d$netdebug conf listshares | egrep -v '^global$' ) | sort -u
-}
-
-
-############################
-# parse command line options
-
-netdebug=0
-
-temp=$(getopt -n "$prog" -o "xhe:d:f" -l help -- "$@")
-
-[ $? != 0 ] && usage
-
-eval set -- "$temp"
-
-while true ; do
-    case "$1" in
-       -x) set -x; shift ;;
-       -f) force=1; shift ;;
-       -e) EDITOR="$2"; shift; shift ;;
-       -d) netdebug="$2"; shift; shift ;;
-       --) shift ; break ;;
-       -h|--help|*) usage ;; # Shouldn't happen, so this is reasonable.
-    esac
-done
-
-[ $# -lt 1 ] && usage
-
-command="$1"
-shift
-
-case $command in
-    conf)
-       [ $# -lt 1 ] && sofs_conf_usage
-       type="$1"
-       shift
-       case $type in
-           list)
-               [ $# != 0 ] && sofs_conf_usage
-               sofs_conf_list
-               ;;
-
-           listall)
-               [ $# != 0 ] && sofs_conf_usage
-               sofs_conf_listall
-               ;;
-           
-           show)
-               [ $# != 1 ] && sofs_conf_usage
-               sofs_conf_show "$1"
-               ;;
-           
-           remove)
-               [ $# != 1 ] && sofs_conf_usage
-               sofs_conf_remove "$1"
-               ;;
-           
-           set)
-               [ $# != 2 ] && sofs_conf_usage
-               sofs_conf_set "$1" "$2"
-               ;;
-           
-           load)
-               [ $# != 2 ] && sofs_conf_usage
-               sofs_conf_load "$1" "$2"
-               ;;
-           
-           edit)
-               [ $# != 1 ] && sofs_conf_usage
-               sofs_conf_edit "$1"
-               ;;
-           
-           init)
-               [ $# != 0 ] && sofs_conf_usage
-               sofs_conf_init
-               echo "Config initialised"
-               ;;
-
-           backup)
-               [ $# != 1 ] && sofs_conf_usage
-               sofs_conf_backup "$1"
-               echo "Config backed up to $1"
-               ;;
-
-           restore)
-               [ $# != 1 ] && sofs_conf_usage
-               sofs_conf_restore "$1"
-               echo "Config restored from $1"
-               ;;
-
-           reload)
-               if [ $# = 0 ]; then
-                   sofs_conf_reload "all"
-               else
-                   sofs_conf_reload "$1"
-               fi
-               ;;
-
-           *)
-               sofs_conf_usage
-               ;;
-           esac
-       ;;
-
-    status)
-       [ $# != 0 ] && sofs_status_usage
-       sofs_status
-       ;;
-
-    push)
-       [ $# -lt 1 ] && sofs_push_usage
-       sofs_push "$@"
-       ;;
-
-    help)
-       if [ $# = 1 ]; then
-           sofs_$1_usage
-       else
-           usage;
-       fi
-       ;;
-    *)
-       usage;
-       ;;
-esac
-