finish renaming script names
[debian6500.git] / master / opt / script / change_lgcore
diff --git a/master/opt/script/change_lgcore b/master/opt/script/change_lgcore
new file mode 100755 (executable)
index 0000000..24c2da8
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/bash
+# ============================================================================
+#
+# Copyright (C) THALES. All rights reserved
+# Author: Laurent Mazet
+#
+# Date : 17/12/2014
+# ============================================================================
+
+# Install new lgcore delivery
+
+# TODO
+# *
+
+MODE=
+PROGNAME=$(basename $0)
+REPOSITORY="/opt/trc6500/debian-rep"
+TMPLOG=/tmp/$PROGNAME-$$.log
+VER=1.0
+
+# help function
+
+function usage () {
+  echo "usage: $PROGNAME [-h] [-r dir] [-v] <mode>"
+  echo "  install new version from lgcore delivery from"
+  echo "  - usb: usb key slotted on master blade"
+  echo "  - file: file stored in a special repository"
+  echo
+  echo " options are:"
+  echo " -h: help message"
+  echo " -r: change repository (default is $REPOSITORY)"
+  echo " -v: version"
+  exit $@
+}
+
+# formating functions
+
+function title () { echo -e "\033[0;1m$*\033[0;0m"; }
+function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
+function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
+function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
+
+# check command
+
+function check () {
+  echo -n "$@: "
+  $@ 2>$TMPLOG && pass OK || { fail KO; cat $TMPLOG; exit 1; }
+  rm -f $TMPLOG
+}
+
+# argument processing
+
+while [ $# -gt 0 ]; do
+    case "$1" in
+    -h) usage 0;;
+    -r) shift; REPOSITORY=$1;;
+    -v) echo "$PROGNAME version $VER"; exit 0;;
+    file|usb) MODE=$1;;
+    *) usage 1;;
+    esac
+    shift
+done
+
+# check mode
+
+[ "$MODE" ] || { fail "need mode (file or usb)"; exit 1; }
+
+# check repository
+
+DIR=
+case "$MODE" in
+file) DIR=$REPOSITORY;;
+usb)
+    DIR=/media/floppy0
+    check mount /dev/sdb1 $DIR
+    trap "umount $DIR;" 0 1 2 15
+esac
+
+# look for file
+
+echo -n "look for delivery file: "
+LIV=$(find $DIR -name liv\*.sfx 2>$TMPLOG | sort | tail -1)
+[ -f "$LIV" ] && pass OK || { fail KO; cat $TMPLOG; exit 1; }
+rm -f $TMPLOG
+
+# install lgcore delivery
+
+check bash $LIV
+
+# vim:set tabstop=4 expandtab shiftwidth=4: