Changeset 422


Ignore:
Timestamp:
Mar 26, 2007 2:20:43 AM (6 years ago)
Author:
jrollins
Message:

cereal: Major work on new 0.3 release. See debian/changelog.

Unfortunately, I seem to have broken it and can't figure how.
The sessions are somehow not created properly, so that the session
owner can not attach to the session. I can't work on it any more right
now, though, so I'll have to come back to it.
Any suggestions would be much appreciated.

Location:
trunk/cereal
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/cereal/TODO

    r400 r422  
    1212shared access to screen sessions? 
    1313 
    14 include cereal log reader 
    15 - maybe as part of 'cereal' script 
    16  
    17 add flags (change "tags" to "flags") 
    18 - state flag (sflag) 
    19 - permission flag (pflag) 
    20  
    21 add functionality to 'cereal' script 
    22 - list cereal sessions based on user flag check 
    23 - log reader 
    24  
    2514make sure all scripts run with dash instead of bash for lighter-weight systems. 
    2615 
    27 why not have default GROUP be dialout? 
    28   
    29 need to figure out correct way to do packaging. 
    30 - ** build-pkg script not currently working ** 
    31  
    32 work on documentation 
    33  
    3416bash completion 
  • trunk/cereal/debian/changelog

    r411 r422  
     1cereal (0.3-1) unstable; urgency=low 
     2 
     3  * New upstream version 
     4  * fixed broken path to common file. 
     5  * removed unnecessary specification of GROUP and LOGUSER 
     6  * added flags in session display 
     7  * added subcommands to cereal script, including primitive log reader 
     8  * tried to clean up/simplify a lot of the code 
     9  * FIXME: need postinst script to create cereal user 
     10  * FIXME: screen sessions do not get properly created (proper user unable to attach) 
     11  * NOT FOR RELEASE 
     12 
     13 -- Jameson Rollins <jrollins@fifthhorseman.net>  Mon, 26 Mar 2007 02:11:26 -0400 
     14 
    115cereal (0.2-2) unstable; urgency=low 
    216 
  • trunk/cereal/fs/usr/bin/cereal

    r391 r422  
    1111# or later. 
    1212 
     13################################################## 
     14CMD=$(basename $0) 
     15 
     16SHAREDIR=${SHAREDIR:-"/usr/share/cereal"} 
     17export SHAREDIR 
     18source "$SHAREDIR/common" 
     19################################################## 
     20 
    1321function usage { 
    1422cat <<EOF 
    15 Usage: $(basename $0) [SESSION] 
    16 Connect to running cereal screen session attached to SESSION. 
    17 If SESSION not specified, list available hosts and exit. 
     23Usage: $CMD <subcommand> [arg] 
     24Cereal client program. 
     25 
     26subcommands: 
     27  attach SESSION                           attach to session 
     28  follow SESSION                           follow session log 
     29  list                                     list all sessions 
     30 
    1831EOF 
    1932} 
    2033 
    21 export SHAREDIR="/usr/local/share/cereal" 
     34attach() { 
     35    screen -r -S "cereal:$SESSION" || failure "Are you the correct user?" 
     36} 
    2237 
    23 . "$SHAREDIR/common" 
     38follow() { 
     39    tail -n 100 -F "$SERVICE.$SESSION/log/main/current" 
     40} 
    2441 
    25 if [[ $# < 1 ]] ; then 
    26     echo "Specify session to connect to:" 
    27     list_enabled "$USER" 
    28     exit 0 
    29 fi 
     42############################################################### 
     43### MAIN 
    3044 
    31 if [ "$1" = '-h' -o "$1" = '--help' ] ; then 
    32     usage 
    33     exit 0 
    34 else 
    35     SESSION="$1" 
    36 fi 
     45COMMAND="$1" 
     46[ "$COMMAND" ] || failure "Type '$CMD help' for usage." 
     47shift 
    3748 
    38 if [ -d "$SESSIONDIR/$SESSION" ] ; then 
    39     screen -r -S "cereal:$SESSION" || failure "Are you the correct user?  Type 'cereal' for more info." 
    40 else 
    41     failure "Host '$SESSION' not found." 
    42 fi 
     49case $COMMAND in 
     50    'attach'|'follow') 
     51        SESSION="$1" 
     52        [ "$SESSION" ] || failure "Not enough input arguments.  Type '$CMD help' for more info." 
     53        check_session "$SESSION" || failure "Session '$SESSION' not found. 
     54Type 'cereal list' to list sessions." 
     55        check_enabled "$SESSION" || failure "Session '$SESSION' not enabled. 
     56Type 'cereal list' to list sessions." 
     57 
     58        "$COMMAND" 
     59        ;; 
     60    'list') 
     61        list 
     62        ;; 
     63    'help') 
     64        usage 
     65        ;; 
     66    *) 
     67        failure "Unknown command: '$COMMAND' 
     68Type '$CMD help' for usage." 
     69        ;; 
     70esac 
  • trunk/cereal/fs/usr/sbin/cereal-admin

    r391 r422  
    1212# or later. 
    1313 
     14################################################## 
     15CMD=$(basename $0) 
     16 
     17SHAREDIR=${SHAREDIR:-"/usr/share/cereal"} 
     18export SHAREDIR 
     19source "$SHAREDIR/common" 
     20################################################## 
     21 
    1422function usage { 
    1523cat <<EOF 
    16 Usage: $(basename $0) <subcommand> [arg] 
     24Usage: $CMD <subcommand> [arg] 
     25Cereal session management program. 
    1726 
    1827subcommands: 
    19   create SESSION TTY BAUD USER GROUP [LOGUSER [LOGGROUP]] 
    20                                       create cereal session 
    21   enable SESSION [SESSION]...         enable cereal sessions 
    22   disable SESSION [SESSION]...        disable cereal sessions 
    23   remove SESSION [SESSION]...         remove cereal sessions 
    24   list                                list all sessions 
     28  create SESSION TTY BAUD USER LOGGROUP    create cereal session 
     29  enable SESSION [SESSION]...              enable cereal sessions 
     30  disable SESSION [SESSION]...             disable cereal sessions 
     31  remove SESSION [SESSION]...              remove cereal sessions 
     32  list [USER]                              list all sessions [with USER] 
    2533 
    2634EOF 
    27  
    28 } 
    29  
    30 export SHAREDIR="/usr/local/share/cereal" 
    31 . "$SHAREDIR/common" 
    32  
     35} 
     36 
     37# create session 
    3338function create { 
    34     if (( $# < 5 )) ; then 
    35         failure "Not enough input arguments. 
    36 Usage: $(basename $0) create SESSION TTY BAUD USER GROUP [LOGUSER]" 
    37     fi 
     39    (( $# < 5 )) && failure "Not enough input arguments.  Type '$CMD help' for more info." 
    3840 
    3941    SESSION="$1" 
    4042    TTY="$2" 
    4143    BAUD="$3" 
    42     USER="$4" 
    43     GROUP="$5" 
    44     if [ $6 ] ; then 
    45         LOGUSER="$6" 
    46     else 
    47         LOGUSER="$USER" 
    48     fi 
    49     if [ $7 ] ; then 
    50         LOGGROUP="$7" 
    51     else 
    52         LOGGROUP="adm" 
    53     fi 
     44    SUSER="$4" 
     45    SGROUP=$(ls -l "$TTY" | awk '{ print $4 }') 
     46    LOGUSER='cereal' 
     47    LOGGROUP="$5" 
    5448 
    5549    if [ -d "$SESSIONDIR/$SESSION" ] ; then 
     
    5751    fi 
    5852 
    59     if ! check_istty "$TTY" ; then 
    60         failure "'$TTY' is not a valid tty." 
    61     elif ! check_user "$USER" ; then 
    62         failure "'$USER' is not a valid user." 
    63     elif ! check_group "$GROUP" ; then 
    64         failure "'$GROUP' is not a valid group." 
    65     elif ! check_user "$LOGUSER" ; then 
    66         failure "'$LOGUSER' is not a valid user." 
    67     elif ! check_group "$LOGGROUP" ; then 
    68         failure "'$LOGGROUP' is not a valid group." 
    69     elif ! check_tty_rw "$USER" "$GROUP" "$TTY" ; then 
    70         failure "User '$USER' does not have read/write access to '$TTY' while in group '$GROUP'." 
    71     fi 
    72  
     53    check_istty "$TTY" 
     54    check_user "$SUSER" 
     55    check_group "$SGROUP" 
     56    check_user "$LOGUSER" 
     57    check_group "$LOGGROUP" 
     58    check_chpst "$SUSER" "$SGROUP" 
     59    check_tty_rw "$SUSER" "$SGROUP" "$TTY" 
     60         
    7361    mkdir -p "$SESSIONDIR/$SESSION" 
    7462 
     
    8169    echo "$TTY" > "$SESSIONDIR/$SESSION/env/TTY" 
    8270    echo "$BAUD" > "$SESSIONDIR/$SESSION/env/BAUD"  
    83     echo "$USER" > "$SESSIONDIR/$SESSION/env/USER" 
    84     echo "$GROUP" > "$SESSIONDIR/$SESSION/env/GROUP" 
     71    echo "$SUSER" > "$SESSIONDIR/$SESSION/env/USER" 
     72    echo "$SGROUP" > "$SESSIONDIR/$SESSION/env/GROUP" 
    8573    echo "$LOGUSER" > "$SESSIONDIR/$SESSION/env/LOGUSER" 
    8674    echo "$LOGGROUP" > "$SESSIONDIR/$SESSION/env/LOGGROUP" 
     
    9482 
    9583    mkfifo "$SESSIONDIR/$SESSION/socket" 
    96     chown "$USER" "$SESSIONDIR/$SESSION/socket" 
     84    chown "$SUSER" "$SESSIONDIR/$SESSION/socket" 
    9785    ln -s "$SHAREDIR/logrun" "$SESSIONDIR/$SESSION/log/run"  
    9886     
     
    10290 
    10391function enable_check { 
    104     if ! check_tty_rw "$USER" "$GROUP" "$TTY" ; then 
    105         failure "User '$USER' does not have read/write access to '$TTY' while in group '$GROUP'." 
    106     fi 
     92    check_tty_rw "$USER" "$GROUP" "$TTY" 
    10793} 
    10894export -f enable_check 
    10995 
     96# enable session 
    11097function enable { 
    11198    local ERR=0 
    11299 
    113     if [ -z "$1" ] ; then 
    114         failure "Not enough input arguments. 
    115 Usage: $(basename $0) enable SESSION [SESSION]..." 
    116     fi 
     100    [ "$1" ] || failure "Not enough input arguments.  Type '$CMD help' for more info." 
    117101 
    118102    for SESSION ; do 
    119         if [ ! -d "$SESSIONDIR/$SESSION" ] ; then 
     103        if ! check_session "$SESSION" ; then 
    120104            echo "Session '$SESSION' not found." 
    121105            ((ERR++)) 
    122106            continue 
    123107        fi 
    124         if [ -L "$SERVICE.$SESSION" ] ; then 
    125             echo "Session '$SESSION' appears to already be enabled." 
     108        if check_enabled "$SESSION" ; then 
     109            echo "Session '$SESSION' already be enabled." 
    126110            ((ERR++)) 
    127111            continue 
    128112        fi 
    129113        if ! chpst -e "$SESSIONDIR/$SESSION/env/" sh -c enable_check ; then 
    130             echo "User for session '$SESSION' does not have read/write access to session TTY." 
    131114            ((ERR++)) 
    132115            continue 
     
    141124} 
    142125 
     126# disable session 
    143127function disable { 
    144128    local ERR=0 
    145129 
    146     if [ -z "$1" ] ; then 
    147         failure "Not enough input arguments. 
    148 Usage: $(basename $0) disable SESSION [SESSION]..." 
    149     fi 
     130    [ "$1" ] || failure "Not enough input arguments.  Type '$CMD help' for more info." 
    150131     
    151132    for SESSION ; do 
    152         if [ ! -d "$SESSIONDIR/$SESSION" ] ; then 
     133        if ! check_session "$SESSION" ] ; then 
    153134            echo "Session '$SESSION' not found." 
    154135            ((ERR++)) 
    155136            continue 
    156137        fi 
    157         if [ ! -L "$SERVICE.$SESSION" ] ; then 
    158             echo "Session '$SESSION' does not appear to be enabled." 
     138        if ! check_enabled "$SESSION" ] ; then 
     139            echo "Session '$SESSION' not enabled." 
    159140            ((ERR++)) 
    160141            continue 
     
    170151} 
    171152 
     153# remove session 
    172154function remove { 
    173155    local ERR=0 
    174156 
    175     if [ -z "$1" ] ; then 
    176         failure "Not enough input arguments. 
    177 Usage: $(basename $0) remove SESSION [SESSION]..." 
    178     fi 
     157    [ "$1" ] || failure "Not enough input arguments.  Type '$CMD help' for more info." 
    179158 
    180159    for SESSION ; do 
    181         if [ ! -d "$SESSIONDIR/$SESSION" ] ; then 
     160        if ! check_session "$SESSION" ; then 
    182161            echo "Session '$SESSION' not found." 
    183162            ((ERR++)) 
    184163            continue 
    185164        fi 
    186         if [ -L "$SERVICE.$SESSION" ] ; then 
    187             echo "Session '$SESSION' is currently enabled.  Please disable first." 
    188             ((ERR++)) 
    189             continue 
    190         fi 
    191  
     165        if check_enabled "$SESSION" ; then 
     166            echo "Session '$SESSION' is currently enabled." 
     167            read -p "Disable session '$SESSION' first? [Y|n]: " -n 1 OK ; [ -z $OK ] || echo 
     168            if [ -z "$OK" -o "${OK/y/Y}" = 'Y' ] ; then 
     169                disable "$SESSION" 
     170            else 
     171                ((ERR++)) 
     172                continue 
     173            fi 
     174        fi 
    192175        read -p "Really remove session '$SESSION'? [Y|n]: " -n 1 OK ; [ -z $OK ] || echo 
    193176        if [ -z "$OK" -o "${OK/y/Y}" = 'Y' ] ; then 
     
    202185} 
    203186 
     187############################################################### 
     188### MAIN 
    204189 
    205190COMMAND="$1" 
    206 if [ -z "$COMMAND" ] ; then 
    207     usage 
    208     exit 0 
    209 fi 
     191[ "$COMMAND" ] || failure "Type '$CMD help' for usage." 
    210192shift 
    211193 
    212194case $COMMAND in 
    213195    'create'|'enable'|'disable'|'remove'|'list') 
    214         $COMMAND "$@" 
     196        "$COMMAND" "$@" 
     197        ;; 
     198    'help') 
     199        usage 
    215200        ;; 
    216201    *) 
    217         usage 
    218         exit 0 
     202        failure "Unknown command: '$COMMAND' 
     203Type '$CMD help' for usage." 
    219204        ;; 
    220205esac 
  • trunk/cereal/fs/usr/share/cereal/common

    r396 r422  
    99# or later. 
    1010 
     11################################################## 
    1112# managed directories 
    1213export ETC="/etc/cereal" 
    13 export SESSIONDIR="/var/local/lib/cereal" 
     14export SESSIONDIR="/var/lib/cereal" 
    1415export SERVICEDIR="/var/service" 
    1516export SERVICE="$SERVICEDIR/cereal" 
    16  
    17 # check if the user can read/write to a TTY 
    18 # check_tty_rw USER GROUP TTY 
    19 function check_tty_rw { 
    20     chpst -u "$1:$2" bash -c "test -r $3 && test -w $3" 
    21 } 
    22 export -f check_tty_rw 
    23  
    24 # check if TTY is valid tty 
    25 # check_istty TTY 
    26 function check_istty { 
    27     [ -c "$1" ] 
    28 } 
    29 export -f check_istty 
    30  
    31 function check_user { 
    32     getent passwd "$1" > /dev/null 
    33 } 
    34 export -f check_user 
    35  
    36 function check_group { 
    37     getent group "$1" > /dev/null 
    38 } 
    39 export -f check_group 
     17################################################## 
    4018 
    4119function failure { 
     
    4523export -f failure 
    4624 
    47 function display_session { 
     25# check if TTY is valid tty 
     26# check_istty TTY 
     27function check_istty { 
     28    [ -c "$1" ] || failure "'$1' is not a valid tty." 
     29} 
     30export -f check_istty 
     31 
     32# check if USER is valid 
     33# check_user USER 
     34function check_user { 
     35    getent passwd "$1" > /dev/null || failure "'$1' is not a valid user." 
     36} 
     37export -f check_user 
     38 
     39# check if GROUP is valid 
     40# check_group GROUP 
     41function check_group { 
     42    getent group "$1" > /dev/null || failure "'$1' is not a valid group." 
     43} 
     44export -f check_group 
     45 
     46# check session creation privileges 
     47# check_chpst USER GROUP 
     48function check_chpst { 
     49    chpst -u "$1:$2" true 
     50} 
     51export -f check_chpst 
     52 
     53# check if the user can read/write to a TTY 
     54# check_tty_rw USER GROUP TTY 
     55function check_tty_rw { 
     56    chpst -u "$1:$2" bash -c "test -r $3 && test -w $3" || failure "User '$1' does not have read/write access to tty '$3', or tty is not g+rw." 
     57} 
     58export -f check_tty_rw 
     59 
     60# check if session exists 
     61# check_session SESSION 
     62check_session() { 
     63    ls "$SESSIONDIR" | grep -q "$1" 
     64} 
     65export -f check_session 
     66 
     67# check_enabled SESSION 
     68check_enabled() { 
     69    [ -L "$SERVICE.$1" ] 
     70} 
     71export -f check_enabled 
     72 
     73# check_can_attach SESSION USER 
     74check_can_attach() { 
     75    [ "$2" = $(cat "$SESSIONDIR/$1/env/USER") ] 
     76} 
     77export -f check_can_attach 
     78 
     79# check_can_follow SESSION USER 
     80check_can_follow() { 
     81    local LOGUSER=$(cat "$SESSIONDIR/$1/env/LOGUSER") 
     82    local LOGGROUP=$(cat "$SESSIONDIR/$1/env/LOGGROUP") 
     83    [ "$2" = "$LOGUSER" ] || groups "$2" | grep -q "$LOGGROUP" || [ $(id -u "$USER") = '0' ] 
     84 
     85} 
     86export -f check_can_follow 
     87 
     88# display_session SESSION [USER] 
     89display_session() { 
    4890    local SESSION="$1" 
    49     if [ -L "$SERVICE.$SESSION" ] ; then 
     91    USER=${2:-"$USER"} 
     92 
     93    check_user "$USER" 
     94    check_session "$SESSION" || failure "Session '$SESSION' does not exist." 
     95 
     96    # set state flag ('+' enabled, '-' disabled) 
     97    local SFLAG='-' 
     98    if check_enabled "$SESSION" ; then 
    5099        local SFLAG='+' 
    51     else 
    52         local SFLAG='-' 
    53100    fi 
    54      
     101    # set attach flag 
     102    local AFLAG='-' 
     103    if check_can_attach "$SESSION" "$USER" ; then 
     104        local AFLAG='a' 
     105    fi 
     106    # set follow flag 
     107    local FFLAG='-' 
     108    if check_can_follow "$SESSION" "$USER" ; then 
     109        local FFLAG='f' 
     110    fi 
     111 
    55112    cd "$SESSIONDIR/$SESSION/env" 
    56     echo "$SFLAG $SESSION $(cat TTY) $(cat BAUD) $(cat USER) $(cat GROUP) $(cat LOGUSER) $(cat LOGGROUP)" 
     113    echo "$SFLAG$AFLAG$FFLAG $SESSION $(cat TTY) $(cat BAUD) $(cat USER) $(cat LOGGROUP)" 
    57114} 
    58115export -f display_session 
    59116 
     117# list SESSION [USER] 
    60118function list { 
     119    local SESSION 
    61120    local SESSIONS=$(ls -1 "$SESSIONDIR" 2> /dev/null) 
     121    USER=${1:-"$USER"} 
     122 
    62123    if [ -z "$SESSIONS" ] ; then 
    63         echo "There do not appear to be any sessions." 
     124        echo "There are no sessions." 
    64125        exit 0 
    65126    fi 
    66     local SESSION 
    67     #echo "(state SESSION tty baud USER group loguser loggroup)" 
     127 
    68128    for SESSION in $SESSIONS ; do 
    69         display_session "$SESSION" 
     129        display_session "$SESSION" "$USER" 
    70130    done 
    71131} 
    72132export -f list 
    73  
    74 function list_enabled { 
    75     local CHECK_USER="$1" 
    76     local SESSIONS=$(ls -1 "$SERVICEDIR" 2> /dev/null | sed s/cereal.//) 
    77     if [ -z "$SESSIONS" ] ; then 
    78         echo "There do not appear to be any enabled sessions." 
    79         exit 0 
    80     fi 
    81     local SESSION 
    82     #echo "(state SESSION tty baud USER group loguser loggroup)" 
    83     for SESSION in $SESSIONS ; do 
    84         display_session "$SESSION" 
    85     done 
    86 } 
    87 export -f list_enabled 
  • trunk/cereal/fs/usr/share/cereal/logrun

    r391 r422  
    1 #!/bin/bash 
     1#!/bin/bash -e 
    22 
    33# The cereal scripts were written by 
     
    1111exec 2>&1 
    1212 
    13 export SHAREDIR="/usr/local/share/cereal" 
    14 . "$SHAREDIR/common" 
     13export SHAREDIR="/usr/share/cereal" 
     14source "$SHAREDIR/common" 
    1515 
    1616LOGUSER="$(cat ../env/LOGUSER)" 
    1717 
    18 if ! check_group "$LOGUSER" ; then 
    19     failure "'$LOGUSER' is not a valid user." 
    20 fi 
     18check_group "$LOGUSER" 
    2119     
    2220exec chpst -u "$LOGUSER" svlogd -tt ./main <../socket 
  • trunk/cereal/fs/usr/share/cereal/mainrun

    r391 r422  
    1 #!/bin/bash 
     1#!/bin/bash -e 
    22 
    33# The cereal scripts were written by 
     
    1111exec 2>&1 
    1212 
    13 export SHAREDIR="/usr/local/share/cereal" 
    14 . "$SHAREDIR/common" 
     13export SHAREDIR="/usr/share/cereal" 
     14source "$SHAREDIR/common" 
    1515 
    1616# ensure that the socket is available 
     
    2020 
    2121mainrun() { 
    22     if ! check_user "$USER" ; then 
    23         failure "'$USER' not a valid user." 
    24     elif ! check_group "$GROUP" ; then 
    25         failure "'$GROUP' not a valid group." 
    26     elif ! check_tty_rw "$USER" "$GROUP" "$TTY" ; then 
    27         failure "$USER cannot open $TTY while in group $GROUP.  Not starting screen." 
    28     elif ! chown "$USER" ./socket ; then 
    29         failure "Can not properly set ownership of socket." 
    30     elif ! chmod 0600 ./socket ; then 
    31         failure "Can not properly set permissions on socket." 
    32     fi 
     22    check_user "$USER" 
     23    check_group "$GROUP" 
     24    check_tty_rw "$USER" "$GROUP" "$TTY" 
     25    chown "$USER" ./socket || failure "Can not properly set ownership of socket." 
     26    chmod 0600 ./socket || failure "Can not properly set permissions on socket." 
    3327     
    34     echo "starting up cereal for host '$HOST'..." 
    35     exec  chpst -u "$USER:$GROUP" /usr/bin/screen -D -m -L -c "$SCREENRC" -S "cereal:$HOST" "$TTY" "$BAUD" 
     28    echo "starting up cereal session '$SESSION'..." 
     29    exec  chpst -u "$USER:$GROUP" /usr/bin/screen -D -m -L -c "$SCREENRC" -S "cereal:$SESSION" "$TTY" "$BAUD" 
    3630} 
    3731export -f mainrun 
Note: See TracChangeset for help on using the changeset viewer.