restore default ip configuration
[debian6500.git] / master / opt / script / change_lgcore
1 #!/bin/bash
2 # ============================================================================
3 #
4 # Copyright (C) THALES. All rights reserved
5 # Author: Laurent Mazet
6 #
7 # Date : 17/12/2014
8 # ============================================================================
9
10 # Install new lgcore delivery
11
12 # TODO
13 # *
14
15 MODE=
16 PROGNAME=$(basename $0)
17 REPOSITORY="/opt/trc6500/debian-rep"
18 TMPLOG=/tmp/$PROGNAME-$$.log
19 VER=1.0
20
21 # help function
22
23 function usage () {
24 echo "usage: $PROGNAME [-h] [-r dir] [-v] <mode>"
25 echo " install new version from lgcore delivery from"
26 echo " - usb: usb key slotted on master blade"
27 echo " - file: file stored in a special repository"
28 echo
29 echo " options are:"
30 echo " -h: help message"
31 echo " -r: change repository (default is $REPOSITORY)"
32 echo " -v: version"
33 exit $@
34 }
35
36 # formating functions
37
38 function title () { echo -e "\033[0;1m$*\033[0;0m"; }
39 function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
40 function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
41 function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
42
43 # check command
44
45 function check () {
46 echo -n "$@: "
47 $@ 2>$TMPLOG && pass OK || { fail KO; cat $TMPLOG; exit 1; }
48 rm -f $TMPLOG
49 }
50
51 # argument processing
52
53 while [ $# -gt 0 ]; do
54 case "$1" in
55 -h) usage 0;;
56 -r) shift; REPOSITORY=$1;;
57 -v) echo "$PROGNAME version $VER"; exit 0;;
58 file|usb) MODE=$1;;
59 *) usage 1;;
60 esac
61 shift
62 done
63
64 # check mode
65
66 [ "$MODE" ] || { fail "need mode (file or usb)"; exit 1; }
67
68 # check repository
69
70 DIR=
71 case "$MODE" in
72 file) DIR=$REPOSITORY;;
73 usb)
74 DIR=/media/floppy0
75 check mount /dev/sdb1 $DIR
76 trap "umount $DIR;" 0 1 2 15
77 esac
78
79 # look for file
80
81 echo -n "look for delivery file: "
82 LIV=$(find $DIR -name liv\*.sfx 2>$TMPLOG | sort | tail -1)
83 [ -f "$LIV" ] && pass OK || { fail KO; cat $TMPLOG; exit 1; }
84 rm -f $TMPLOG
85
86 # install lgcore delivery
87
88 check bash $LIV
89
90 # vim:set tabstop=4 expandtab shiftwidth=4: