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:
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
Hi eric, I can volunteer for this, any other example commands you would like to see?

I tried
# if ! 66-insys.sh tree-is-enabled virt; then 66-tree -D virt; fi

66-tree: info: Already disabled tree: virt

# if ! 66-insys.sh tree-is-enabled virt; then 66-tree -E virt; fi

66-tree: info: Enabled successfully tree: virt
 # if ! 66-insys.sh tree-is-enabled virt; then 66-tree -D virt; fi

# if 66-insys.sh service-is-up openntpd; tree=$(66-insys.sh service-find-tree openntpd) ; 66-start -t $tree -r openntpd; fi
zsh: parse error near `fi'
# if ! 66-insys.sh service-is-up openntpd; tree=$(66-insys.sh service-find-tree openntpd) ; 66-start -t $tree -r openntpd; fi
zsh: parse error near `fi'
% ./66-insys.sh list-frontend
/etc/66/service/
/etc/66/service/nohang
/etc/66/service/pulseaudio1
/usr/lib/66/service/
/usr/lib/66/service/tpacpi
/usr/lib/66/service/wpa_supplicant-wired@
/usr/lib/66/service/neofetch
/usr/lib/66/service/virtlogd
/usr/lib/66/service/boot-user@ orb
/usr/lib/66/service/boot@
/usr/lib/66/service/boot-user@ bro
/usr/lib/66/service/display-manager@
/usr/lib/66/service/avahi
/usr/lib/66/service/sddm
/usr/lib/66/service/dmraid
/usr/lib/66/service/dhcpcd
/usr/lib/66/service/libvirtd
/usr/lib/66/service/lxdm
/usr/lib/66/service/scandir@
/usr/lib/66/service/dbus
/usr/lib/66/service/alsa-daemon
/usr/lib/66/service/tty@
/usr/lib/66/service/cupsd
/usr/lib/66/service/console-tracker@
/usr/lib/66/service/networkmanager
/usr/lib/66/service/wpa_supplicant@
/usr/lib/66/service/tor
/usr/lib/66/service/boot@ system
/usr/lib/66/service/connmand
/usr/lib/66/service/adb
/usr/lib/66/service/pulseaudio
/usr/lib/66/service/consolekit
/usr/lib/66/service/scandir@ orb
/usr/lib/66/service/boot-user@
/usr/lib/66/service/wpa_supplicant
/usr/lib/66/service/dbus-session@
/usr/lib/66/service/xdg-user-dirs
/usr/lib/66/service/console-tracker@ consolekit
/usr/lib/66/service/acpid
/usr/lib/66/service/virtlockd-socket
/usr/lib/66/service/alsa-restore
/usr/lib/66/service/lighttpd
/usr/lib/66/service/wpa_supplicant-nl80211@
/usr/lib/66/service/uksmd
/usr/lib/66/service/openntpd
/usr/lib/66/service/display-manager@ sddm
/usr/lib/66/service/virtlockd
/home/orb/.66/service/
The examples of use was just .... an examples of use :).

I don't expect to see any particular output of command. I just want to know if user find this tool useful or not, practical or not, efficient or not, etc.

So just play with it when you need some kind of information from your system and come back here to express your experience and point of view about it :).
5 days later
Funny misunderstanding, :lol: it can seem pretty useful but I think for my use 66-tools in commandline are sufficient for my case. Thanks for your efforts in finding fresh ways to manage services
13 days later
I want to test this script but sorry I could not understand what are the contents of the script and will it enable trees and services if already not enabled ?
The script do not modify your system, it just collect information of your 66 eco-system.
create a file called /usr/bin/66-insys.sh and copy the contents below inside it
# !/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
make it executable
# chmod +x /usr/bin/66-insys.sh
call the help to know what you can do with it
# 66-insys.sh -h
enjoy :)

Powered by Obarun