Changeset 422
- Timestamp:
- Mar 26, 2007 2:20:43 AM (6 years ago)
- Location:
- trunk/cereal
- Files:
-
- 7 edited
-
TODO (modified) (1 diff)
-
debian/changelog (modified) (1 diff)
-
fs/usr/bin/cereal (modified) (1 diff)
-
fs/usr/sbin/cereal-admin (modified) (8 diffs)
-
fs/usr/share/cereal/common (modified) (2 diffs)
-
fs/usr/share/cereal/logrun (modified) (2 diffs)
-
fs/usr/share/cereal/mainrun (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/cereal/TODO
r400 r422 12 12 shared access to screen sessions? 13 13 14 include cereal log reader15 - maybe as part of 'cereal' script16 17 add flags (change "tags" to "flags")18 - state flag (sflag)19 - permission flag (pflag)20 21 add functionality to 'cereal' script22 - list cereal sessions based on user flag check23 - log reader24 25 14 make sure all scripts run with dash instead of bash for lighter-weight systems. 26 15 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 documentation33 34 16 bash completion -
trunk/cereal/debian/changelog
r411 r422 1 cereal (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 1 15 cereal (0.2-2) unstable; urgency=low 2 16 -
trunk/cereal/fs/usr/bin/cereal
r391 r422 11 11 # or later. 12 12 13 ################################################## 14 CMD=$(basename $0) 15 16 SHAREDIR=${SHAREDIR:-"/usr/share/cereal"} 17 export SHAREDIR 18 source "$SHAREDIR/common" 19 ################################################## 20 13 21 function usage { 14 22 cat <<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. 23 Usage: $CMD <subcommand> [arg] 24 Cereal client program. 25 26 subcommands: 27 attach SESSION attach to session 28 follow SESSION follow session log 29 list list all sessions 30 18 31 EOF 19 32 } 20 33 21 export SHAREDIR="/usr/local/share/cereal" 34 attach() { 35 screen -r -S "cereal:$SESSION" || failure "Are you the correct user?" 36 } 22 37 23 . "$SHAREDIR/common" 38 follow() { 39 tail -n 100 -F "$SERVICE.$SESSION/log/main/current" 40 } 24 41 25 if [[ $# < 1 ]] ; then 26 echo "Specify session to connect to:" 27 list_enabled "$USER" 28 exit 0 29 fi 42 ############################################################### 43 ### MAIN 30 44 31 if [ "$1" = '-h' -o "$1" = '--help' ] ; then 32 usage 33 exit 0 34 else 35 SESSION="$1" 36 fi 45 COMMAND="$1" 46 [ "$COMMAND" ] || failure "Type '$CMD help' for usage." 47 shift 37 48 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 49 case $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. 54 Type 'cereal list' to list sessions." 55 check_enabled "$SESSION" || failure "Session '$SESSION' not enabled. 56 Type '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' 68 Type '$CMD help' for usage." 69 ;; 70 esac -
trunk/cereal/fs/usr/sbin/cereal-admin
r391 r422 12 12 # or later. 13 13 14 ################################################## 15 CMD=$(basename $0) 16 17 SHAREDIR=${SHAREDIR:-"/usr/share/cereal"} 18 export SHAREDIR 19 source "$SHAREDIR/common" 20 ################################################## 21 14 22 function usage { 15 23 cat <<EOF 16 Usage: $(basename $0) <subcommand> [arg] 24 Usage: $CMD <subcommand> [arg] 25 Cereal session management program. 17 26 18 27 subcommands: 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] 25 33 26 34 EOF 27 28 } 29 30 export SHAREDIR="/usr/local/share/cereal" 31 . "$SHAREDIR/common" 32 35 } 36 37 # create session 33 38 function 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." 38 40 39 41 SESSION="$1" 40 42 TTY="$2" 41 43 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" 54 48 55 49 if [ -d "$SESSIONDIR/$SESSION" ] ; then … … 57 51 fi 58 52 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 73 61 mkdir -p "$SESSIONDIR/$SESSION" 74 62 … … 81 69 echo "$TTY" > "$SESSIONDIR/$SESSION/env/TTY" 82 70 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" 85 73 echo "$LOGUSER" > "$SESSIONDIR/$SESSION/env/LOGUSER" 86 74 echo "$LOGGROUP" > "$SESSIONDIR/$SESSION/env/LOGGROUP" … … 94 82 95 83 mkfifo "$SESSIONDIR/$SESSION/socket" 96 chown "$ USER" "$SESSIONDIR/$SESSION/socket"84 chown "$SUSER" "$SESSIONDIR/$SESSION/socket" 97 85 ln -s "$SHAREDIR/logrun" "$SESSIONDIR/$SESSION/log/run" 98 86 … … 102 90 103 91 function 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" 107 93 } 108 94 export -f enable_check 109 95 96 # enable session 110 97 function enable { 111 98 local ERR=0 112 99 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." 117 101 118 102 for SESSION ; do 119 if [ ! -d "$SESSIONDIR/$SESSION" ]; then103 if ! check_session "$SESSION" ; then 120 104 echo "Session '$SESSION' not found." 121 105 ((ERR++)) 122 106 continue 123 107 fi 124 if [ -L "$SERVICE.$SESSION" ]; then125 echo "Session '$SESSION' a ppears to already be enabled."108 if check_enabled "$SESSION" ; then 109 echo "Session '$SESSION' already be enabled." 126 110 ((ERR++)) 127 111 continue 128 112 fi 129 113 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."131 114 ((ERR++)) 132 115 continue … … 141 124 } 142 125 126 # disable session 143 127 function disable { 144 128 local ERR=0 145 129 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." 150 131 151 132 for SESSION ; do 152 if [ ! -d "$SESSIONDIR/$SESSION" ] ; then133 if ! check_session "$SESSION" ] ; then 153 134 echo "Session '$SESSION' not found." 154 135 ((ERR++)) 155 136 continue 156 137 fi 157 if [ ! -L "$SERVICE.$SESSION" ] ; then158 echo "Session '$SESSION' does not appear to beenabled."138 if ! check_enabled "$SESSION" ] ; then 139 echo "Session '$SESSION' not enabled." 159 140 ((ERR++)) 160 141 continue … … 170 151 } 171 152 153 # remove session 172 154 function remove { 173 155 local ERR=0 174 156 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." 179 158 180 159 for SESSION ; do 181 if [ ! -d "$SESSIONDIR/$SESSION" ]; then160 if ! check_session "$SESSION" ; then 182 161 echo "Session '$SESSION' not found." 183 162 ((ERR++)) 184 163 continue 185 164 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 192 175 read -p "Really remove session '$SESSION'? [Y|n]: " -n 1 OK ; [ -z $OK ] || echo 193 176 if [ -z "$OK" -o "${OK/y/Y}" = 'Y' ] ; then … … 202 185 } 203 186 187 ############################################################### 188 ### MAIN 204 189 205 190 COMMAND="$1" 206 if [ -z "$COMMAND" ] ; then 207 usage 208 exit 0 209 fi 191 [ "$COMMAND" ] || failure "Type '$CMD help' for usage." 210 192 shift 211 193 212 194 case $COMMAND in 213 195 'create'|'enable'|'disable'|'remove'|'list') 214 $COMMAND "$@" 196 "$COMMAND" "$@" 197 ;; 198 'help') 199 usage 215 200 ;; 216 201 *) 217 usage218 exit 0 202 failure "Unknown command: '$COMMAND' 203 Type '$CMD help' for usage." 219 204 ;; 220 205 esac -
trunk/cereal/fs/usr/share/cereal/common
r396 r422 9 9 # or later. 10 10 11 ################################################## 11 12 # managed directories 12 13 export ETC="/etc/cereal" 13 export SESSIONDIR="/var/l ocal/lib/cereal"14 export SESSIONDIR="/var/lib/cereal" 14 15 export SERVICEDIR="/var/service" 15 16 export 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 ################################################## 40 18 41 19 function failure { … … 45 23 export -f failure 46 24 47 function display_session { 25 # check if TTY is valid tty 26 # check_istty TTY 27 function check_istty { 28 [ -c "$1" ] || failure "'$1' is not a valid tty." 29 } 30 export -f check_istty 31 32 # check if USER is valid 33 # check_user USER 34 function check_user { 35 getent passwd "$1" > /dev/null || failure "'$1' is not a valid user." 36 } 37 export -f check_user 38 39 # check if GROUP is valid 40 # check_group GROUP 41 function check_group { 42 getent group "$1" > /dev/null || failure "'$1' is not a valid group." 43 } 44 export -f check_group 45 46 # check session creation privileges 47 # check_chpst USER GROUP 48 function check_chpst { 49 chpst -u "$1:$2" true 50 } 51 export -f check_chpst 52 53 # check if the user can read/write to a TTY 54 # check_tty_rw USER GROUP TTY 55 function 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 } 58 export -f check_tty_rw 59 60 # check if session exists 61 # check_session SESSION 62 check_session() { 63 ls "$SESSIONDIR" | grep -q "$1" 64 } 65 export -f check_session 66 67 # check_enabled SESSION 68 check_enabled() { 69 [ -L "$SERVICE.$1" ] 70 } 71 export -f check_enabled 72 73 # check_can_attach SESSION USER 74 check_can_attach() { 75 [ "$2" = $(cat "$SESSIONDIR/$1/env/USER") ] 76 } 77 export -f check_can_attach 78 79 # check_can_follow SESSION USER 80 check_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 } 86 export -f check_can_follow 87 88 # display_session SESSION [USER] 89 display_session() { 48 90 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 50 99 local SFLAG='+' 51 else52 local SFLAG='-'53 100 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 55 112 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)" 57 114 } 58 115 export -f display_session 59 116 117 # list SESSION [USER] 60 118 function list { 119 local SESSION 61 120 local SESSIONS=$(ls -1 "$SESSIONDIR" 2> /dev/null) 121 USER=${1:-"$USER"} 122 62 123 if [ -z "$SESSIONS" ] ; then 63 echo "There do not appear to be anysessions."124 echo "There are no sessions." 64 125 exit 0 65 126 fi 66 local SESSION 67 #echo "(state SESSION tty baud USER group loguser loggroup)" 127 68 128 for SESSION in $SESSIONS ; do 69 display_session "$SESSION" 129 display_session "$SESSION" "$USER" 70 130 done 71 131 } 72 132 export -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" ] ; then78 echo "There do not appear to be any enabled sessions."79 exit 080 fi81 local SESSION82 #echo "(state SESSION tty baud USER group loguser loggroup)"83 for SESSION in $SESSIONS ; do84 display_session "$SESSION"85 done86 }87 export -f list_enabled -
trunk/cereal/fs/usr/share/cereal/logrun
r391 r422 1 #!/bin/bash 1 #!/bin/bash -e 2 2 3 3 # The cereal scripts were written by … … 11 11 exec 2>&1 12 12 13 export SHAREDIR="/usr/ local/share/cereal"14 ."$SHAREDIR/common"13 export SHAREDIR="/usr/share/cereal" 14 source "$SHAREDIR/common" 15 15 16 16 LOGUSER="$(cat ../env/LOGUSER)" 17 17 18 if ! check_group "$LOGUSER" ; then 19 failure "'$LOGUSER' is not a valid user." 20 fi 18 check_group "$LOGUSER" 21 19 22 20 exec chpst -u "$LOGUSER" svlogd -tt ./main <../socket -
trunk/cereal/fs/usr/share/cereal/mainrun
r391 r422 1 #!/bin/bash 1 #!/bin/bash -e 2 2 3 3 # The cereal scripts were written by … … 11 11 exec 2>&1 12 12 13 export SHAREDIR="/usr/ local/share/cereal"14 ."$SHAREDIR/common"13 export SHAREDIR="/usr/share/cereal" 14 source "$SHAREDIR/common" 15 15 16 16 # ensure that the socket is available … … 20 20 21 21 mainrun() { 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." 33 27 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" 36 30 } 37 31 export -f mainrun
Note: See TracChangeset
for help on using the changeset viewer.

