File: pkgheader.sh

package info (click to toggle)
libsmbios 2.0.3.dfsg-1.1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 3,768 kB
  • ctags: 2,016
  • sloc: cpp: 14,292; sh: 9,408; xml: 3,820; makefile: 454; ansic: 402; python: 157
file content (147 lines) | stat: -rw-r--r-- 3,327 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/sh

# BIOS update BASH script

_NAME_VER="Dell Libsmbios-based BIOS Update installer v1.0"
_COPYRIGHT="Copyright 2008 Dell Inc. All Rights Reserved."
_BNAME=`basename $0`
_PRG=dellBiosUpdate
_DEPS="mktemp tail tar awk rm"
_DIR=$(cd $(dirname $0); pwd)
_THIS_BIN=$_DIR/$( basename $0 )

set -e

#Functions

ShowHelp()
{
        echo "Usage: $_BNAME [options]"
        echo
        echo $_NAME_VER
        echo $_COPYRIGHT
        echo
        echo "Options:"
        echo "  --help                  Print this text."
        echo "  --version               Print package versions."
        echo "  --update                Update the bios."
        echo "  --extract PATH          Extract the package to PATH"
        echo
}

Extract()
{
    END=$(awk '/^__ARC__/ { print NR + 1; exit 0; }' $_THIS_BIN )
    tail -n +$END $_THIS_BIN | tar xzf - -C $tmpdir
    [ $? = 0 ] || \
    {
        echo "$0: The archive cannot be extracted."
        exit 1
    }
}

Update()
{
    echo 
    echo "Loading OS-provided 'dell_rbu' driver."
    if ! /sbin/modprobe dell_rbu; then
        echo "Could not load OS dell_rbu driver."
        exit 1
    fi
    echo
    pushd $tmpdir >/dev/null 2>&1
    echo "Running BIOS Update:"
    if ! ./$_PRG -u -f ./bios.hdr "$@"; then
        echo
        echo "BIOS Update Failed."
        echo
    else
        echo "You must now reboot your system!"
        echo
    fi
    popd >/dev/null 2>&1
}

checkroot()
{
    if [ $(id -u) -ne 0 ]; then
        echo "Cannot run update as non-root user."
        exit 1
    fi
}

#Main()

#Handle signals
tmpdir=
trap 'rm -rf $tmpdir; exit 99' HUP INT QUIT EXIT BUS SEGV PIPE TERM #1 2 3 10 11 13 15

#Ensure dependencies are available
type $_DEPS >/dev/null
[ $? = 0 ] || \
{
        echo "$0: Cannot find utilities on the system to execute package." >&2
        echo "Make sure the following utilities are in the path: $DEPS" >&2
        exit 1
}

#Check options
while [ $# -gt 0 ];
do
    case $1 in
        --debug)
                set -x
                shift
                ;;
        --version)
                echo $_NAME_VER
                echo $_COPYRIGHT
                tmpdir=$(mktemp -d /tmp/biosupdate-XXXXXX)
                export LD_LIBRARY_PATH=$tmpdir
                Extract 
                $tmpdir/$_PRG --version
                exit 0 
                ;;
        --help)
                ShowHelp
                exit 0
                ;;

        --extract)
                if [ -n "$2" ]; then
                    mkdir -p $2
                    tmpdir=$2
                else
                    tmpdir=$(mktemp -d ./UpdatePackage-XXXXXX)
                fi
                trap - HUP INT QUIT EXIT BUS SEGV PIPE TERM #1 2 3 10 11 13 15
                Extract
                exit 0
                ;;

        --update)
                checkroot
                shift
                tmpdir=$(mktemp -d /tmp/biosupdate-XXXXXX)
                export LD_LIBRARY_PATH=$tmpdir
                Extract 
                Update "$@"
                exit 0
                ;;

        '')
                ShowHelp
                exit 0
                ;;

        *) 
                echo "invalid command line option: $1"
                ShowHelp
                exit 0
                ;;
    esac
done

ShowHelp
exit 0
__ARC__