This file is indexed.

/usr/bin/cereal is in cereal 0.24-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/sh

# cereal: command line interface to cereal screen serial loggers
#
# The cereal scripts were written by
# Jameson Graef Rollins <jrollins@finestructure.net>
# and
# Daniel Kahn Gillmor <dkg@fifthhorseman.net>.
#
# They are Copyright 2007, and are all released under the GPL, version 3
# or later.

##################################################
SHAREDIR=${SHAREDIR:-"/usr/share/cereal"}
export SHAREDIR
. "$SHAREDIR/common"
##################################################

usage() {
cat <<EOF
Usage: cereal <subcommand> [options] [args]
Cereal client program.

subcommands:
  attach (a) SESSION                      attach to session
  follow (f) [options] SESSION            follow session log
    -c (--cat)                              cat log instead of follow
    -p (--path)                             output just log file path
  list (l) [options] [SESSION]...         list session(s)
    -n (--names)                            list just session names
  help (h,?)                              this help

EOF
}

attach() {
    SESSION="$1"

    if [ -z "$SESSION" ] ; then
	failure "Not enough input arguments.
Type 'cereal help' for more info."
    elif ! is_session "$SESSION" ; then
	failure "Session '$SESSION' not found.
Type 'cereal list' to list sessions."
    elif ! can_attach "$SESSION" "$USER" ; then
	failure "You do not have permission to attach to session '$SESSION'."
    fi

    is_running "$SESSION"
    case $? in
	0|2) # also attempt to start if session is unknown (return code 2)
	    log_write "$SESSION" "user '$USER' attaching to session from `tty`..."
	    screen -x -S "cereal:$SESSION" || failure "Could not reattach screen."
	    log_write "$SESSION" "user '$USER' on `tty` detached from session."
	    ;;
	1)
	    failure "Session '$SESSION' not running."
	    ;;
    esac
}

log_follow() {
    tail -n 100 -F "$LOG"
}

log_cat() {
    cat "$LOG"
}

log_pwd() {
    echo "$LOG"
}

follow() {
    local SESSION
    local TEMP
    local OUTPUT
    OUTPUT="log_follow"

    TEMP=$(getopt -o cp --long cat,path -n "cereal follow" -- "$@")
    if [ $? -ne 0 ] ; then
	failure "Invalid options."
    fi

    # Note the quotes around `$TEMP': they are essential!
    eval set -- "$TEMP"

    while true ; do
        case "$1" in
	    -c|--cat) OUTPUT="log_cat" ; shift 1 ;;
	    -p|--path) OUTPUT="log_pwd" ; shift 1 ;;
	    --) shift ;;
	    *)
		SESSION="$1"
		break
		;;
        esac
    done

    if [ -z "$SESSION" ] ; then
	failure "Not enough input arguments.
Type 'cereal help' for more info."
    elif ! is_session "$SESSION" ; then
	failure "Session '$SESSION' not found.
Type 'cereal list' to list sessions."
    elif ! can_follow "$SESSION" "$USER" ; then
	failure "You do not have permission to follow session '$SESSION'."
    fi

    LOG="$SESSIONDIR/$SESSION/log/main/current"
    if [ "$OUTPUT" = 'log_follow' -o "$OUTPUT" = 'log_cat' ] ; then
	echo "############################################################"
	echo "### cereal log: $SESSION"
	printf "### "
	list "$SESSION"
	echo "### log file: $LOG"
	echo "############################################################"
    fi
    $OUTPUT
}

###############################################################
### MAIN

handle_command() {

    COMMAND="$1"

    [ "$COMMAND" ] || failure "Type 'cereal help' for usage."
    shift

    case $COMMAND in
	'attach'|'a')
	    attach "$@"
	    ;;
	'follow'|'f')
	    follow "$@"
	    ;;
	'list'|'l')
	    list "$@" || failure "There are no sessions." 1
	    ;;
	'help'|'h'|'?')
	    usage
	    ;;
	*)
	    failure "Unknown command: '$COMMAND'
Type '$CMD help' for usage."
	    ;;
    esac

    exit "$ERR"
}

handle_command "$@"