summaryrefslogtreecommitdiffstats
path: root/src/usr/local/sbin
diff options
context:
space:
mode:
authorStephen Beaver <sbeaver@netgate.com>2015-10-08 14:15:19 -0400
committerStephen Beaver <sbeaver@netgate.com>2015-10-08 14:15:19 -0400
commit42cf0f48181c4b6d1edd870d3905c94c9f1f485b (patch)
tree0d7691de01ef5a8aa73bc34bcac3750135228f2c /src/usr/local/sbin
parent55e73a5650d685982bd8adbd88ac13d672e1c323 (diff)
downloadpfsense-42cf0f48181c4b6d1edd870d3905c94c9f1f485b.zip
pfsense-42cf0f48181c4b6d1edd870d3905c94c9f1f485b.tar.gz
Script to set up pfSense-upgrade when called from web GUI
Diffstat (limited to 'src/usr/local/sbin')
-rwxr-xr-xsrc/usr/local/sbin/pfSense-upgrade-GUI.sh89
1 files changed, 78 insertions, 11 deletions
diff --git a/src/usr/local/sbin/pfSense-upgrade-GUI.sh b/src/usr/local/sbin/pfSense-upgrade-GUI.sh
index f008d23..25086dd 100755
--- a/src/usr/local/sbin/pfSense-upgrade-GUI.sh
+++ b/src/usr/local/sbin/pfSense-upgrade-GUI.sh
@@ -50,27 +50,89 @@
# Script is a simple wrapper around pfSense-upgrade. It is called from pkg_install.php to perform an
# installation or remval.
# FIFO is set up, log files named
+
+message () {
+if ( $VERBOSE ) ; then
+ echo "$1"
+fi
+}
+
+usage () {
+ echo "pfSense-upgrade-GUI.sh [flags] [-i || -r] PACKAGE_NAME"
+ echo "Allows the web GUI to invoke the package installation script"
+ echo " -f : Force (Ignore lockfile)"
+ echo " -h : This help"
+ echo " -r : Install package"
+ echo " -i : Remove package"
+ echo " -v : Verbose"
+}
+
if [ $# -lt 2 ] ; then
echo "Usage: inst.sh [-i || -r] PACKAGE"
echo "e.g.: inst.sh -i pfSense-pkg-sudo"
fi
-if [ "$1" == "-i" ] ; then
- echo "Installing $2"
-elif [ "$1" == "-r" ] ; then
- echo "Removing $2"
-else
- echo "Error: Unsupported option $1"
- exit
+VERBOSE=false
+FORCE=false
+
+while getopts fhirv opt; do
+ case ${opt} in
+ f)
+ FORCE=true
+ ;;
+ h)
+ usage
+ exit 0
+ ;;
+ i)
+ ACTION="-i"
+ ;;
+ r)
+ ACTION="-r"
+ ;;
+ v)
+ VERBOSE=true
+ ;;
+ *)
+ echo "Error: Unsupported option $(opt)"
+ usage
+ exit 1
+ ;;
+ esac
+done
+
+shift $((OPTIND-1))
+PKG=$1
+
+if [ $ACTION == "-i" ] ; then
+ message "Installing $PKG"
+elif [ $ACTION == "-r" ] ; then
+ message "Removing $PKG"
fi
-PKG="$2"
-ACTION="$2"
+UPDATEINPROGRESS=2
+LOCKFILE=/tmp/pkg-upgate_GUI.lck
LOGFILE="webgui-log.txt"
FIFO=/tmp/upgr.fifo
JSONFILE="/cf/conf/webgui-log.json"
-if [ -a $FIFO ] ; then
+if [ -e $LOCKFILE ] ; then
+ eval $(stat -s $LOCKFILE)
+ NOW=`date +%s`
+ let AGE="$NOW-$st_ctime" >/dev/null
+
+ if [ $AGE -lt 300 ] && ( ! $FORCE ) ; then
+ message "Update in progress!"
+ exit $UPDATEINPROGRESS
+ else
+ message "Removing stale lockfile $INPROGRESS"
+ rm -f $INPROGRESS
+ fi
+fi
+
+touch $LOCKFILE
+
+if [ -e $FIFO ] ; then
rm $FIFO 2>/dev/null
fi
@@ -80,7 +142,12 @@ mkfifo $FIFO
tail -f $FIFO >$JSONFILE &
TAILPID=$!
+message "Calling pfSense-upgrade with -l $LOGFILE -p $FIFO $ACTION $PKG"
+
/usr/local/sbin/pfSense-upgrade -l $LOGFILE -p $FIFO $ACTION $PKG >/dev/null
kill $TAILPID
-rm $FIFO 2>/dev/null \ No newline at end of file
+rm $FIFO 2>/dev/null
+rm $LOCKFILE
+
+exit 0
OpenPOWER on IntegriCloud