mirror of https://bitbucket.org/ausocean/av.git
48 lines
1.3 KiB
Bash
48 lines
1.3 KiB
Bash
|
#!/bin/bash -e
|
||
|
# This script launches vidforward. This is used by the service file.
|
||
|
|
||
|
# Check that we have the correct number of arguments passed.
|
||
|
if [ $# -ne 2 ]; then
|
||
|
echo "incorrect number of arguments, expected gopath user and binary directory"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# This is the user in the GOPATH e.g. for /home/foo/go the user is foo.
|
||
|
gopath_user=$1
|
||
|
|
||
|
# This is the dir of the binary from the GOPATH e.g. /src/bitbucket.org/ausocean/av/cmd/vidforward.
|
||
|
bin_dir=$2
|
||
|
|
||
|
# We'll get the bin name from the bin dir (assuming this is same as the bin dir name).
|
||
|
bin_name=$(basename $bin_dir)
|
||
|
|
||
|
# the following required directories _should_ already exist
|
||
|
if [ ! -d /var/log/vidforward ]; then
|
||
|
sudo mkdir /var/log/vidforward
|
||
|
chmod guo+rwx /var/log/vidforward
|
||
|
fi
|
||
|
|
||
|
# show IP addresses
|
||
|
echo Our IP addresses:
|
||
|
sudo ip addr show | grep inet
|
||
|
|
||
|
# capture stdout and stderr to a secondary log file (just in case)
|
||
|
exec 2> /var/log/vidforward/stream.log
|
||
|
exec 1>&2
|
||
|
|
||
|
# Now set all required variables.
|
||
|
HOME=/home/$gopath_user
|
||
|
GOPATH=$HOME/go
|
||
|
VIDFORWARD_PATH=$GOPATH$bin_dir
|
||
|
PATH=$PATH:/usr/local/go/bin:$VIDFORWARD_PATH
|
||
|
cd $VIDFORWARD_PATH
|
||
|
sudo -u $gopath_user HOME=$HOME GOPATH=$GOPATH PATH=$PATH ./$bin_name
|
||
|
if [ $? -eq 0 ]
|
||
|
then
|
||
|
echo "Successfully exited vidforward"
|
||
|
exit 0
|
||
|
else
|
||
|
echo "vidforward exited with code: $?" >&2
|
||
|
exit 1
|
||
|
fi
|