Hi guys,
I need your help. I wrote a little script in pure sh (POSIX compliance) to find some information on the system(insys -> in system). The mainly purpose on this script is to provide an easy way to script operations like restart a service or a series of services after an upgrade.
The script is really simple an self-explained. I wrote it in sh to quickly made a real test from users and see if it useful or not. Depending of your feedback i will pass it in C or not.
This is the interface and the help of the script:
To disable a tree if it enabled
Please guys, test it and make feedback.
Note: the list-frontend, tree-find-current and 66-version operations rely on the /usr/include/66/config.h file.This file must be present on your system to be able to use these operations.
I need your help. I wrote a little script in pure sh (POSIX compliance) to find some information on the system(insys -> in system). The mainly purpose on this script is to provide an easy way to script operations like restart a service or a series of services after an upgrade.
The script is really simple an self-explained. I wrote it in sh to quickly made a real test from users and see if it useful or not. Depending of your feedback i will pass it in C or not.
This is the interface and the help of the script:
66-insys.sh [ -h ] [ -z ] <boolean|request> name
boolean operations:
A boolean operation return 0 for true and 1 for false
tree-is-enabled: return true if name is enabled.
service-is-enabled: return true if name is enabled.
tree-is-initialized: return true if name is initialized.
service-is-up: return true if name is up.
tree-is-current: return true if name is current.
request operations:
A request operation return a string(None if nothing is found)
list-frontend: list of available frontend file on the system.
tree-find-current: return the name of the current tree or None.
service-find-tree: return the tree's name of name.
66-version: return the current version of 66.
Some example of use:To disable a tree if it enabled
# if ! 66-insys.sh tree-is-enabled root; then 66-tree -D root; fi
To restart a service
# if 66-insys.sh service-is-up ntpd; then tree=$(66-insys.sh service-find-tree ntpd) ; 66-start -t $tree -r ntpd; fi
To list all available service on the system
% 66-insys.sh list-frontend
As any other 66 tool, this script can be launch with root or regular user.Please guys, test it and make feedback.
Note: the list-frontend, tree-find-current and 66-version operations rely on the /usr/include/66/config.h file.This file must be present on your system to be able to use these operations.
# !/bin/sh
export PROG="${0}"
export CLOCK_ENABLED=0
export COLOR_ENABLED=0
export VERBOSITY=1
INCLUDEDIR="/usr/include/66/config.h"
SYSTEMDIR=""
ADMDIR=""
SYSDIR=""
USERDIR=""
NAME=""
SSVERSION=""
tree_is_enabled=0
service_is_enabled=0
tree_is_initialized=0
service_is_up=0
tree_is_current=0
list_frontend=0
tree_find_current=0
service_find_tree=0
ss_version=0
usage(){
oblog -i "\
66-insys.sh [ -h ] [ -z ] <boolean|request> name
boolean operations:
A boolean operation return 0 for true and 1 for false
tree-is-enabled: return true if name is enabled.
service-is-enabled: return true if name is enabled.
tree-is-initialized: return true if name is initialized.
service-is-up: return true if name is up.
tree-is-current: return true if name is current.
request operations:
A request operation return a string(None if nothing is found)
list-frontend: list of available frontend file on the system.
tree-find-current: return the name of the current tree or None.
service-find-tree: return the tree's name of name.
66-version: return the current version of 66."
}
die(){
oblog -f "${@ }"
exit 111
}
check_valid_name(){
if [ "$1" = "tree" ]; then
if ! 66-intree "$NAME" 1>/dev/null 2>&1; then
die "unknown tree $NAME"
fi
elif [ "$1" = "service" ]; then
if ! 66-inservice "$NAME" 1>/dev/null 2>&1; then
die "unknown service $NAME"
fi
fi
}
parse_66_config(){
if ! execl-toc -X -e ${INCLUDEDIR}; then
die "this operation rely on ${INCLUDEDIR} -- please install it."
fi
c=0
res=$(grep SS_SERVICE_ADMDIR ${INCLUDEDIR})
for i in ${res}; do
c=$((c + 1))
if [ $c -gt 2 ]; then
i=$(66-echo "$i" | tr -d "\"")
ADMDIR=${i}
fi
done
c=0
res=$(grep SS_SERVICE_SYSDIR ${INCLUDEDIR})
for i in ${res}; do
c=$((c + 1))
if [ $c -gt 2 ]; then
i=$(66-echo "$i" | tr -d "\"")
SYSDIR=${i}
fi
done
c=0
res=$(grep SS_SYSTEM_DIR ${INCLUDEDIR})
for i in ${res}; do
c=$((c + 1))
if [ $c -gt 2 ]; then
i=$(66-echo "$i" | tr -d "\"")
SYSTEMDIR=${i}
fi
done
if [ "$(id -u)" -gt 0 ]; then
c=0
res=$(grep SS_SERVICE_USERDIR ${INCLUDEDIR})
for i in ${res}; do
c=$((c + 1))
if [ $c -gt 2 ]; then
i=$(66-echo "$i" | tr -d "\"")
USERDIR=$(homeof "$(whoami)")/${i}
fi
done
fi
c=0
res=$(grep SS_VERSION ${INCLUDEDIR})
for i in ${res}; do
c=$((c + 1))
if [ $c -gt 2 ]; then
i=$(66-echo "$i" | tr -d "\"")
SSVERSION=${i}
fi
done
}
for arg ; do
case "$arg" in
-h) usage ;;
-z) export COLOR_ENABLED=1 ;;
*) target=" ${target} $arg" ;;
esac
done
for bool in ${target}; do
case "${bool}" in
"tree-is-enabled")
if ! shift 2 1>/dev/null 2>&1 ;then
die "you must specify a tree name"
fi
tree_is_enabled=1
NAME="${target# *${bool}\ }" ;
break ;;
"service-is-enabled")
if ! shift 2 1>/dev/null 2>&1 ;then
die "you must specify a service name"
fi
service_is_enabled=1
NAME="${target# *${bool}\ }" ;
break ;;
"tree-is-initialized")
if ! shift 2 1>/dev/null 2>&1 ;then
die "you must specify a tree name"
fi
tree_is_initialized=1
NAME="${target# *${bool}\ }" ;
break ;;
"service-is-up")
if ! shift 2 1>/dev/null 2>&1 ;then
die "you must specify a service name"
fi
service_is_up=1
NAME="${target# *${bool}\ }" ;
break ;;
"tree-is-current")
if ! shift 2 1>/dev/null 2>&1 ;then
die "you must specify a tree name"
fi
tree_is_current=1
NAME="${target# *${bool}\ }" ;
break ;;
"list-frontend")
list_frontend=1
NAME="${target# *${bool}\ }" ;
break ;;
"tree-find-current")
tree_find_current=1
NAME="${target# *${bool}\ }" ;
break ;;
"service-find-tree")
if ! shift 2 1>/dev/null 2>&1 ;then
die "you must specify a service name"
fi
service_find_tree=1
NAME="${target# *${bool}\ }" ;
break ;;
"66-version")
ss_version=1
NAME="${target# *${bool}\ }" ;
break ;;
*) usage ; exit 110 ;;
esac
done
if [ "$tree_is_enabled" -eq 1 ]; then
check_valid_name "tree"
res=$(66-intree -no enabled "$NAME")
if [ "$res" = "yes" ]; then
exit 0
else
exit 1
fi
elif [ "$service_is_enabled" -eq 1 ]; then
if 66-inservice "$NAME" 1>/dev/null 2>&1; then
res=$(66-inservice -no status "$NAME")
res=${res%%,*}
if [ "$res" = "enabled" ]; then
exit 0
else
exit 1
fi
else
exit 1
fi
elif [ "$tree_is_initialized" -eq 1 ]; then
check_valid_name "tree"
res=$(66-intree -no init "$NAME")
if [ "$res" = yes ]; then
exit 0
else
exit 1
fi
elif [ "$service_is_up" -eq 1 ]; then
check_valid_name "service"
res=$(66-inservice -no status "$NAME")
res=${res# *,}
res=${res%%(*}
res=${res# *\ }
res=${res%\ *}
if [ "$res" = "up" ]; then
exit 0
else
exit 1
fi
elif [ "$tree_is_current" -eq 1 ]; then
check_valid_name "tree"
res=$(66-intree -no current "$NAME")
if [ "$res" = yes ]; then
exit 0
else
exit 1
fi
elif [ "$list_frontend" -eq 1 ]; then
parse_66_config
find "$ADMDIR" -maxdepth 1 || die "unable to read $ADMDIR"
find "$SYSDIR" -maxdepth 1 || die "unable to read $SYSDIR"
if [ "$(id -u)" -gt 0 ]; then
find "$USERDIR" -maxdepth 1 || die "unable to read $USERDIR"
fi
exit 0
elif [ "$tree_find_current" -eq 1 ]; then
parse_66_config
dir=""
if [ "$(whoami)" = "root" ]; then
dir="$SYSTEMDIR/system"
else
dir="$(homeof "$(whoami)")/.66/system"
fi
res=$(ls -1 "$dir")
for i in ${res};do
if [ "$i" = "backup" ] || [ "$i" = "state" ]; then
continue
else
r=$(66-intree -no current "$i")
if [ "$r" = "yes" ]; then
66-echo "$i"
exit 0
fi
fi
done
66-echo "None"
exit 0
elif [ "$service_find_tree" -eq 1 ]; then
check_valid_name "service"
res=$(66-inservice -no intree "$NAME")
66-echo "$res"
exit 0
elif [ "$ss_version" -eq 1 ]; then
parse_66_config
66-echo "$SSVERSION"
exit 0
fi
This script do not modify anything on your system. It only collects information