summaryrefslogtreecommitdiffstats
path: root/bin/fdpsh
blob: 6b11112f407491871406b7ae9635a49c1ce46544 (plain)
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
#!/bin/sh
########################################################################
# Fedora Documentation Project Interactive Shell
#
# Runs BASH after first sourcing the "docs-common/bin/fdp-functions"
# file.
#
# If the "-c cmd" switch is used, exactly one "cmd" is executed.
# Without a "-c" switch, any file given on the command line is executed.
# With neither a "-c" switch or command line arguments, commands are
# accepted from stdin.
########################################################################
ME=`basename $0`
USAGE="usage: ${ME} [-c cmd] [file [arg..]]"
# Figure out absolute pathname to where we live
FDPBINDIR=`dirname $0`
case "${FDPBINDIR}" in
/* )	;;
* )	FDPBINDIR=`/bin/pwd`/${FDPBINDIR};;
esac
#
PATH=${FDPBINDIR}:${PATH}				export PATH
FDPDIR=`cd ${FDPBINDIR}/../.. ; /bin/pwd`		export FDPDIR
REALSHELL="${SHELL}"					export REALSHELL
SHELL=${FDPBINDIR}/${ME}				export SHELL
#
FDPLOG=/tmp/fdpsh.log
#
. ${FDPBINDIR}/fdp-functions
#
CMD=
while getopts c: c
do
	case "${c}" in
		c) CMD="${OPTARG}";;
		*) echo "${USAGE}" >&2; exit 1;;
	esac
done
if [ "${CMD}" ]; then
	[ ! -f ${FDPLOG} ] || echo "${CMD}" >>${FDPLOG}
	eval "${CMD}"
	results=$?
elif [ $# -gt 0 ]; then
	[ ! -f ${FDPLOG} ] || echo "${CMD}" >>${FDPLOG}
	eval $@
	results=$?
else
	while :
	do
		read -e -p "${ME}> " cmd
		if [ "${cmd}" ]; then
			[ ! -f ${FDPLOG} ] || echo "${CMD}" >>${FDPLOG}
			eval ${cmd}
			results=$?
			if [ ${results} -gt 0 ]; then
				echo "Status = ${results}" >&2
			fi
		fi
	done
fi
exit ${results}