-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.sh
executable file
·58 lines (50 loc) · 1.26 KB
/
misc.sh
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
#!/bin/bash
PREFIX=$(dirname $0)
source $PREFIX'/sdi.conf'
if test $? != 0; then
echo "ERROR: failed to load $PREFIX/sdi.conf file (mish.sh)"
exit 1
fi
# Function to update the sdi log.
# The log message contains the seconds since
# 1970 and the contents of $1 parameter
LOG()
{
echo "$(date +%s) $1" >> $LOG
}
# Write $1 (string) into $2 (file) with the seconds since 1970
PRINT()
{
if [ -e "$2" ]; then
echo "$(date +%s) $1" >> "$2"
else
echo "$(date +%s) $1" > "$2"
fi
}
# Create a directory and ensure that it is accessible, or exit SDI
SDIMKDIR()
{
dir=$1
if ! (mkdir -p $dir &&
test -O $dir &&
test -r $dir &&
test -w $dir &&
test -x $dir); then
printf "Unable to create directory \"$dir\".\n"
printf "Check if you are the owner of \"$dir\" and have r/w/x "
printf "permissions to access it and then try to run SDI again.\n"
return 1
else
return 0
fi
}
# $1 - PID of process that is listening the fifo
# $2 - Name of fifo file. closefifo() will look for this file in $FIFODIR
closefifo()
{
PIDFIFO=$1
FIFO=$2
test -d /proc/$PIDFIFO && echo "exit exit exit" >> $FIFODIR/$FIFO &&
waitend $PIDFIFO
rm -f $FIFODIR/$FIFO
}