#!/bin/sh # version 0.4.6.1 # very light script to reconfigure list of nodes # plz report bug to: clic-public-dev@mandrakesoft.com # setting config on it NODELIST="/etc/nodes_list" NODELIST_ORIG="/etc/nodes_list.orig" # if file exist a previous exit signal ocur if [ -f "$NODELIST.1" ]; then cp -f $NODELIST.1 $NODELIST ; rm -rf $NODELIST.1 ; fi trap "echo Catching interrupt Signal !!; cp -f $NODELIST $NODELIST.1 ; exit 1" 1 2 5 9 15 remove_workfile() { rm -rf /tmp/node_list.d $NODELIST.sorted /tmp/tre /tmp/diag_node_actif /tmp/diag_node_inactif /tmp/nodesina /tmp/nodes_list.tmp } # creating an original nodelistfile create_orig() { if [ ! -f "$NODELIST_ORIG" ]; then echo " - Creating $NODELIST_ORIG" cp -f $NODELIST $NODELIST_ORIG fi } # test if /etc/nodes_list=0 test_nodelist() { TEST_F=`file $NODELIST | grep empty` if [ ! -z "$TEST_F" ]; then dialog --msgbox "Node list Empty !!\n \nUsing nodes_list.orig as default node list" 0 0 cp -f $NODELIST_ORIG $NODELIST fi } # sort NODELIST sort_node() { cat $NODELIST | sort > $NODELIST.sorted cp -f $NODELIST.sorted $NODELIST } remove_quote() { # remove anoying " and space perl -pi -e "s/\"//g" $1 cp -f /dev/null /tmp/tre for i in `cat $1` ; do echo $i >> /tmp/tre ; done cat /tmp/tre > $1 } prepa_file() { cp -f /dev/null /tmp/diag_node_actif ; cp -f /dev/null /tmp/diag_node_inactif for i in `cat $NODELIST` ; do j=`echo $i | awk -F. '{print $1}'` ; echo -n "$i $j on " >> /tmp/diag_node_actif ; done cp -f $NODELIST_ORIG /tmp/nodes_list.tmp; cp -f /dev/null /tmp/nodesina for i in `cat $NODELIST` ; do grep -vx $i /tmp/nodes_list.tmp > /tmp/nodesina ; cp -f /tmp/nodesina /tmp/nodes_list.tmp ; done cp -f /tmp/nodesina /tmp/list_node_inactif # diff -B $NODELIST $NODELIST_ORIG | grep ">" | sed -e "s/> //" >/tmp/list_node_inactif #comm -3 $NODELIST_ORIG $NODELIST > /tmp/list_node_inactif for i in `cat /tmp/list_node_inactif` ; do j=`echo $i | awk -F. '{print $1}'` ; echo -n "$i $j off " >> /tmp/diag_node_inactif ; done } show_config() { dialog --backtitle "Content $NODELIST file" --title "$NODELIST" --textbox $NODELIST 15 25 } diag_complete() { prepa_file DIAG=`cat /tmp/diag_node_actif /tmp/diag_node_inactif` dialog --no-kill --backtitle "Set List of nodes to configure Clic Server" --no-cancel --title "Modify List Node" --checklist "Active Nodes followed by inactive Nodes" 0 0 10 $DIAG 2> /tmp/nodes_list.d # /tmp/nodes_list.d is the exact list of active node remove_quote /tmp/nodes_list.d cp -f /dev/null $NODELIST cat /tmp/nodes_list.d > $NODELIST } set_list() { dialog --no-kill --backtitle "Set List of nodes to configure Clic Server" --defaultno --yesno "If you answer Yes this will launch /usr/bin/set_list_node script.\nThis script reconfigure all services and Environement on Clic server, and Relaunch all dependent Services.\n \nAre You SURE ?" 0 0 if [ $? != "1" ]; then /usr/bin/set_list_node fi } ###################### # MAIN ###################### while true do remove_workfile create_orig test_nodelist sort_node dialog --no-cancel --backtitle "Active or DesActive a node easily" \ --title " Menu Of modif_list_node" \ --menu "Choose " 12 30 5 \ 1 "Modify list" \ 2 "Show $NODELIST file" \ 3 "Regenerate config file" \ 4 "Exit" 2> .tempfile output=`cat .tempfile` rm -f .tempfile if [ "$output" = "1" ]; then test_nodelist diag_complete fi if [ "$output" = "2" ]; then show_config fi if [ "$output" = "3" ]; then set_list fi #if [ "$output" = "4" ]; then # diag_desactive # exit 0 #fi if [ "$output" = "4" ]; then remove_workfile exit 0 fi done