source: server/bin/oglivecli @ 3a89d3d

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 3a89d3d was 82ed0eb, checked in by ramon <ramongomez@…>, 8 years ago

#768: Corregir errata que provocaba salida anticipada en el subcomando oglivecli set-default.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@5302 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 18.7 KB
Line 
1#!/bin/bash
2
3#/**
4#         oglivecli command [options ...]
5#@file    oglivecli
6#@brief   Command line tool to manage ogLive clients.
7#@param   $1 command  Command to execute.
8#@param   $2 options  Parameters and options.
9#@warning This script uses "jq" command.
10#@version 1.1.0 - Initial version.
11#@author  Ramón M. Gómez - ETSII Univ. Sevilla
12#@date    2016-12-05
13#*/ ##
14
15
16# Auxiliar functions.
17
18# Metafunction to check if JSON result exists.
19function jq() {
20    local OUTPUT
21    OUTPUT=$($JQ "$@") || return $?
22    [[ "$OUTPUT" = "null" ]] && return 1
23    echo "$OUTPUT"
24}
25
26# Create/edit JSON file about installed ogLive clients.
27function addToJson() {
28    local DATA OGLIVEDIST="$1" OGLIVEKRNL="$2" OGLIVEARCH="$3" OGLIVEREV="$4"
29    local OGLIVEDIR=$(basename $5 2>/dev/null) OGLIVEISO=$(basename $6 2>/dev/null)
30    # JSON data for installed ogLive.
31    DATA=$(cat << EOT | jq .
32{"distribution":"$OGLIVEDIST","kernel":"$OGLIVEKRNL","architecture":"$OGLIVEARCH","revision":"$OGLIVEREV","directory":"$OGLIVEDIR","iso":"$OGLIVEISO"}
33EOT
34    )
35    # Check JSON file consistency.
36    if [ "$(jq -c keys $INFOFILE 2>/dev/null)" == "[\"default\",\"oglive\"]" ]; then
37        # Check if ogLive is defined into JSON file.
38        n=$(jq ".oglive | length" $INFOFILE)
39        for ((i=0; i<n; i++)); do
40            [ "$(jq ".check=$DATA | .check==.oglive[$i]" $INFOFILE)" == "true" ] && INDEX=$i
41        done
42        # Check if it needs to insert data.
43        if [ -z "$INDEX" ]; then
44            INDEX=$n
45            jq ".oglive |= (. + [$DATA])" $INFOFILE | sponge $INFOFILE
46        fi
47        # Update dafault index.
48        jq ".default=$INDEX" $INFOFILE | sponge $INFOFILE
49        jq ".oglive[$INDEX]" $INFOFILE
50    else
51        # Create new JSON file.
52        cat << EOT | jq . | tee $INFOFILE
53{"oglive":[$DATA],"default":0}
54EOT
55    fi
56}
57
58# Show an error message.
59function raiseError() {
60    case "$1" in
61        usage)
62            echo "$PROG: Usage error: Type \"$PROG help\"" >&2
63            exit 1 ;;
64        notfound)
65            echo "$PROG: Resource not found: $2" >&2
66            exit 2 ;;
67        access)
68            echo "$PROG: Access error: $2" >&2
69            exit 3 ;;
70        download)
71            echo "$PROG: Download error: $2" >&2
72            exit 4 ;;
73        *)
74            echo "$PROG: Unknown error" >&2
75            exit 1 ;;
76    esac
77}
78
79# Command functions.
80
81# Show help message.
82function help() {
83    cat << EOT
84$PROG: manage ogLive cleints.
85Usage: $PROG command [options]
86Commands:
87  help                show this help
88  config              show configuration parameters
89  check               check system consistency
90  convert             convert old ogclient to new default ogLive client
91  list                list installed ogLive clients
92  show all            show JSON information about all installed ogLive clients
93  show default        show JSON information about ogLive client marked as default
94  show Index|Dir      show JSON information about an installed ogLive client
95  search Index|Dir    show corresponding index or directory
96  download            show a menu to download an ogLive ISO image from the OpenGnsys website
97  download Iso        download an specific ogLive ISO image from the OpenGnsys website
98  install Iso         install a new ogLive client from a downloaded ISO image
99  uninstall Iso       remove ISO image and uninstall its ogLive client
100  uninstall Index|Dir uninstall an ogLive client
101  get-default         get index value for default ogLive client
102  set-default Index   set default ogLive client
103  rebuild             rebuild a lost configuration file
104  assign Iso Index    assign an ISO file to a JSON entry
105Parameters:
106  Index   a number, starting by 0
107  Dir     directory (relative to installation directory)
108  Iso     ISO file name (relative to download URL or download directory)
109EOT
110}
111
112# Convert default ogclient to a new ogLive format.
113function convert() {
114    local OGCLIENT=ogclient OLDINFOFILE=$OPENGNSYS/doc/veroglive.txt
115    local OGLIVEKRNL OGLIVEDIR OGLIVEISO
116    [ $# -ne 0 ] && raiseError usage
117    [ ! -w $(dirname $INFOFILE) ] && raiseError access "Configuration file."
118    [ -n "$(stat -c "%N" $TFTPDIR/ogclient | awk '$3~/'$DEFOGLIVE'/ {print}')" ] && raiseError access "ogLive is already converted."
119    pushd $TFTPDIR >/dev/null || raiseError access "Installation directory."
120    [ ! -f $OGCLIENT/ogvmlinuz ] && raiseError notfound "ogclient"
121    # Add entry to JSON file using ogclient kernel version.
122    OGLIVEKRNL=$(file -bkr $OGCLIENT/ogvmlinuz | awk '/Linux/ {for(i=1;i<=NF;i++) if($i~/version/) {v=$(i+1);sub(/-.*/,"",v);print v}}')
123    OGLIVEDIR=$DEFOGLIVE-$OGLIVEKRNL
124    [ -r $OLDINFOFILE ] && OGLIVEISO=$(head -1 $OLDINFOFILE).iso
125    addToJson "$(echo $OGLIVEISO|cut -f2 -d-)" "$OGLIVEKRNL" "i386" "${OGLIVEISO##*-}" "$OGLIVEDIR" "$OGLIVEISO"
126    # Rename directory, link to default and clean old files.
127    mv -v $OGCLIENT $OGLIVEDIR
128    ln -vfs $OGLIVEDIR $DEFOGLIVE
129    rm -f $OGCLIENT
130    ln -vfs $DEFOGLIVE $OGCLIENT
131    mv -v $OGCLIENT.old $OGLIVEDIR.old 2>/dev/null
132    rm -fv {ogvmlinuz,oginitrd.img}{,.sum} $OLDINFOFILE
133    popd >/dev/null
134    # Delete old config file.
135    rm -f $OLDINFOFILE
136}
137
138# Show script configuration parameters.
139function config() {
140    case $# in
141        0)  # Show all parameters.
142            cat << EOT
143Configuration file:             $INFOFILE
144ogLive download URL:            $DOWNLOADURL
145ogLive download directory:      $DOWNLOADDIR
146ogLive installation directory:  $TFTPDIR
147Default ogLive name:            $DEFOGLIVE
148EOT
149            ;;
150        1)  # Show specified parameter.
151            case "$1" in
152                config-file)    echo "$INFOFILE" ;;
153                download-url)   echo "$DOWNLOADURL" ;;
154                download-dir)   echo "$DOWNLOADDIR" ;;
155                install-dir)    echo "$TFTPDIR" ;;
156                default-name)   echo "$DEFOGLIVE" ;;
157                *)              raiseError notfound "$1" ;;
158            esac
159            ;;
160        *)  # Usage error.
161            raiseError usage
162            ;;
163esac
164}
165
166# Check consistency, showing configuration problems.
167function check() {
168    local ERR=0 AUX INST DEF
169    [ $# -ne 0 ] && raiseError usage
170    # Check for old system that needs conversion.
171    if [ -z "$(stat -c "%N" $TFTPDIR/ogclient | awk '$3~/'$DEFOGLIVE'/ {print}')" ]; then
172         echo "This server uses old ogclient, please run \"$PROG convert\" to update."
173         let ERR++
174         [ ! -f $INFOFILE ] && return $ERR
175    fi
176    # Check for other problems.
177    [ ! -f $INFOFILE ] && echo "Configuration file does not exists: $INFOFILE" && let ERR++
178    [ -f $INFOFILE -a "$(jq -c keys $INFOFILE 2>/dev/null)" != "[\"default\",\"oglive\"]" ] && echo "Format error in configuration file: $INFOFILE" && let ERR++
179    [ ! -e $TFTPDIR ] && echo "TFTP directory does not exist: $TFTPDIR." && let ERR++
180    # Check for installed ogLives.
181    INST=( $(find $TFTPDIR/ -type d -name "$DEFOGLIVE-*" -a ! -name "*.old" -printf "%f\n" | sort) )
182    [[ ${#INST[@]} -eq 0 ]] && echo "No ogLive clients are installed." && let ERR++
183    DEF=( $(jq -r .oglive[].directory $INFOFILE 2>/dev/null | sort) )
184    # Compare installed and defined ogLive clients.
185    AUX=$(comm -23 <(printf "%s\n" ${INST[*]}) <(printf "%s\n" ${DEF[*]}))
186    [ -n "$AUX" ] && echo "Some ogLive are installed but not defined: ${AUX//$'\n'/, }" && let ERR++
187    AUX=$(comm -13 <(printf "%s\n" ${INST[*]}) <(printf "%s\n" ${DEF[*]}))
188    [ -n "$AUX" ] && echo "Some ogLive are defined but not installed: ${AUX//$'\n'/, }" && let ERR++
189    # Compare downloaded and defined ISO images.
190    INST=( $(find $DOWNLOADDIR/ -type f -name "$DEFOGLIVE-*.iso" -printf "%f\n" | sort) )
191    DEF=( $(jq -r .oglive[].iso $INFOFILE 2>/dev/null | sort) )
192    AUX=$(comm -23 <(printf "%s\n" ${INST[*]}) <(printf "%s\n" ${DEF[*]}))
193    [ -n "$AUX" ] && echo "Some ISOs are downloaded but not defined: ${AUX//$'\n'/, }" && let ERR++
194    AUX=$(comm -13 <(printf "%s\n" ${INST[*]}) <(printf "%s\n" ${DEF[*]}))
195    [ -n "$AUX" ] && echo "Some ISOs are defined but not downloaded: ${AUX//$'\n'/, }" && let ERR++
196    # Print result.
197    [ $ERR -eq 0 ] && echo "OK!" || echo "Problems detected: $ERR"
198    return $ERR
199}
200
201# List installed ogLive clients.
202function list() {
203    [ $# -ne 0 ] && raiseError usage
204    [ ! -r $INFOFILE ] && raiseError access "Configuration file."
205    # List all defined indexes, directories and check if missing.
206    jq -r .oglive[].directory $INFOFILE | nl -v 0 | \
207            awk '{system("echo -n "$0"; test -d '$TFTPDIR'/"$2" || echo -n \" (missing)\"; echo")}' | column -t
208}
209
210# Show information about an installed ogLive client.
211function show() {
212    local INDEX
213    [ $# -ne 1 ] && raiseError usage
214    [ ! -r $INFOFILE ] && raiseError access "Configuration file."
215    # Show JSON entries.
216    case "$1" in
217        default)    # Default index.
218            INDEX="[$(jq -r .default $INFOFILE)]" ;;
219        all)        # All intries.
220            ;;
221        [0-9]*)     # Index.
222            INDEX="[$1]" ;;
223        *)          # Directory.
224            INDEX="[$(search "$1" 2>/dev/null)]" || raiseError notfound "Directory \"$1\"."
225            ;;
226    esac
227    jq ".oglive$INDEX" $INFOFILE || raiseError notfound "Index \"$1\"."
228}
229
230# Show index or directory corresponding to searching parameter.
231function search() {
232    [ $# -ne 1 ] && raiseError usage
233    [ ! -r $INFOFILE ] && raiseError access "Configuration file."
234    # Show corresponding index or directory.
235    list | awk -v d="$1" '{if ($2==d) print $1; if ($1==d) print $2}' | grep . || raiseError notfound "Index/Directory \"$1\""
236}
237
238# Show a menu to select and download an ogLive ISO image from the OpenGnsys website.
239function download() {
240    local OGLIVE NISOS i SOURCELENGTH TARGETFILE
241    [ $# -gt 1 ] && raiseError usage
242    [ ! -d $DOWNLOADDIR ] && raiseError notfound "Download directory"
243    [ ! -w $DOWNLOADDIR ] && raiseError access "Download directory"
244    # Check parameter.
245    if [ -n "$1" ]; then
246        # ogLive to download.
247        OGLIVEFILE="$1"
248    else
249        # Show download menu.
250        OGLIVE=( $(wget $DOWNLOADURL -O - 2>/dev/null | grep $DEFOGLIVE.*iso) )
251        NISOS=${#OGLIVE[@]}
252        echo "Available downloads (+- = installed):"
253        for i in $(seq 1 $NISOS); do
254            [ -e $DOWNLOADDIR/${OGLIVE[i-1]} ] && OGLIVE[i-1]="+-${OGLIVE[i-1]}"
255        done
256        select opt in ${OGLIVE[@]}; do
257            [ -n "$opt" ] && OGLIVEFILE=${opt/+-/} && break
258        done
259    fi
260    # Get download size.
261    SOURCELENGTH=$(LANG=C wget --spider $DOWNLOADURL/$OGLIVEFILE 2>&1 | awk '/Length:/ {print $2}')
262    [ -n "$SOURCELENGTH" ] || raiseError download "$OGLIVEFILE"
263    # Download ogLive.
264    TARGETFILE=$DOWNLOADDIR/$OGLIVEFILE
265    trap "rm -f $TARGETFILE" 1 2 3 6 9 15
266    wget $DOWNLOADURL/$OGLIVEFILE -O $TARGETFILE || raiseError download "$OGLIVEFILE"
267}
268
269# Install an ogLive client from a previously downloaded ISO image.
270function install() {
271    local OGLIVEFILE OGLIVEDIST OGLIVEREV OGLIVEKRNL OGLIVEDIR OGINITRD OGSQFS OGCLIENT=ogclient
272    local SAMBAPASS TMPDIR RSYNCSERV RSYNCCLNT
273    [ $# -ne 1 ] && raiseError usage
274    OGLIVEFILE=$DOWNLOADDIR/"$1"
275    [ ! -f $OGLIVEFILE ] && raiseError notfound "Downloaded file: \"$1\"."
276    [ ! -r $OGLIVEFILE ] && raiseError access "Downloaded file: \"$1\"."
277    [ ! -w $(dirname $INFOFILE) ] && raiseError access "Configuration directory."
278    [ ! -w $TFTPDIR ] && raiseError access "Installation directory."
279    [ -z "$(file -b $OGLIVEFILE | grep "ISO.*ogClient")" ] && raiseError access "File is not an ogLive ISO image."
280    # Working directory (ogLive-Distribution-KernelVersion-CodeRevision).
281    OGLIVEDIST="$(echo $OGLIVEFILE|cut -f2 -d-)"
282    OGLIVEREV="${OGLIVEFILE##*-}"; OGLIVEREV="${OGLIVEREV%.*}"
283    OGLIVEKRNL="$(echo $OGLIVEFILE|cut -f3- -d-)"; OGLIVEKRNL="${OGLIVEKRNL%-$OGLIVEREV.*}"
284    OGLIVEARCH="$(echo $OGLIVEFILE|awk -F- '{print $(NF-1)}')"
285    case "$OGLIVEARCH" in
286        i386|amd64)
287            OGLIVEKRNL="${OGLIVEKRNL%-$OGLIVEARCH}" ;;
288        *)
289            OGLIVEARCH="i386" ;;
290    esac
291    OGLIVEDIR="$TFTPDIR/$DEFOGLIVE-$OGLIVEDIST-${OGLIVEKRNL%%-*}-$OGLIVEARCH-$OGLIVEREV"
292    # Get current or default Samba key.
293    OGINITRD=$OGLIVEDIR/oginitrd.img
294    [ ! -r $OGINITRD ] && OGINITRD=$TFTPDIR/$DEFOGLIVE/oginitrd.img
295    if [ -r $OGINITRD ]; then
296    SAMBAPASS=$(gzip -dc $OGINITRD | \
297    cpio -i --to-stdout scripts/ogfunctions 2>&1 | \
298            grep "^[    ].*OPTIONS=" | \
299            sed 's/\(.*\)pass=\(\w*\)\(.*\)/\2/')
300    fi
301    # Make ogLive backup.
302    rm -fr ${OGLIVEDIR}.old
303    mv -fv $OGLIVEDIR ${OGLIVEDIR}.old 2>/dev/null
304    # Mount ogLive ISO image, update its files, unmount it and set as default.
305    TMPDIR=/tmp/${OGLIVEFILE%.iso}
306    mkdir -p $OGLIVEDIR $TMPDIR
307    trap "umount $TMPDIR; rm -fr $TMPDIR" 1 2 3 6 9 15
308    mount -o loop,ro $OGLIVEFILE $TMPDIR
309    cp -va $TMPDIR/ogclient/* $OGLIVEDIR || raiseError access "Cannot copy files to ogLive directory."
310    umount $TMPDIR
311    rm -f $TFTPDIR/$DEFOGLIVE
312    ln -vfs $(basename $OGLIVEDIR) $TFTPDIR/$DEFOGLIVE
313    ln -vfs $DEFOGLIVE $TFTPDIR/$OGCLIENT
314    # Recover or ask for a new Samba access key.
315    if [ -n "$SAMBAPASS" ]; then
316        echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | $OPENGNSYS/bin/setsmbpass
317    else
318        $OPENGNSYS/bin/setsmbpass
319    fi
320    # Set permissions.
321    find -L $OGLIVEDIR -type d -exec chmod 755 {} \;
322    find -L $OGLIVEDIR -type f -exec chmod 644 {} \;
323    chown -R :opengnsys $OGLIVEDIR
324    # Mount SquashFS and check Rsync version.
325    OGSQFS=$OGLIVEDIR/ogclient.sqfs
326    mount -o loop,ro $OGSQFS $TMPDIR
327    # If Rsync server version > client version, link to compiled file.
328    RSYNCSERV=$(rsync --version 2>/dev/null | awk '/protocol/ {print $6}')
329    RSYNCCLNT=$(chroot $TMPDIR /usr/bin/rsync --version 2>/dev/null | awk '/protocol/ {print $6}')
330    if [ -z "$RSYNCSERV" -o ${RSYNCSERV:-0} -gt ${RSYNCCLNT:-1} ]; then
331        [ -e $OPENGNSYS/client/bin/rsync-$RSYNCSERV ] && mv -f $OPENGNSYS/client/bin/rsync-$RSYNCSERV $OPENGNSYS/client/bin/rsync
332    else
333        # Else, rename compiled file using Rsync protocol number.
334        [ -e $OPENGNSYS/client/bin/rsync ] && mv -f $OPENGNSYS/client/bin/rsync $OPENGNSYS/client/bin/rsync-$($OPENGNSYS/client/bin/rsync --version 2>/dev/null | awk '/protocol/ {print $6}')
335    fi
336    # Unmount SquashFS.
337    umount $TMPDIR
338    rmdir $TMPDIR
339    # Update JSON file.
340    addToJson "$OGLIVEDIST" "$OGLIVEKRNL" "$OGLIVEARCH" "$OGLIVEREV" "$OGLIVEDIR" "$OGLIVEFILE"
341}
342
343# Uninstall an ogLive client.
344function uninstall() {
345    local ISO DIR INDEX DEFINDEX
346    [ $# -ne 1 ] && raiseError usage
347    [ ! -r $INFOFILE ] && raiseError access "Configuration file."
348    [ ! -w $TFTPDIR ] && raiseError access "Installation directory."
349    # Get index and directory for the entry.
350    case "$1" in
351        */*)    # Error (access to other directory).
352            raiseError access "Cannot access outside installation directory."
353            ;;
354        $DEFOGLIVE-*.iso)  # ISO file.
355            ISO="$1"
356            # Working directory (ogLive-Distribution-KernelVersion-CodeRevision).
357            DIR="$(echo $ISO|cut -f1,3 -d-)-${ISO##*-}"; DIR=${DIR%.*}
358            INDEX=$(search $DIR 2>/dev/null)
359            ;;
360        [0-9]*) # Index.
361            INDEX=$1; DIR=$(search $INDEX 2>/dev/null)
362            ;;
363        *)      # Directory.
364            DIR="$1"; INDEX=$(search $DIR 2>/dev/null)
365            ;;
366    esac
367    DEFINDEX=$(getdefault)
368    [[ $INDEX = $DEFINDEX ]] && raiseError access "Cannot uninstall default ogLive."
369    # Remove files and delete index entry.
370    rm -vfr ${ISO:+$DOWNLOADDIR/$ISO} ${DIR:+$TFTPDIR/$DIR}    ### Remove $TFTPDIR/$DIR.old ?
371    if [ -n "$INDEX" ]; then
372        jq "del(.oglive[$INDEX])" $INFOFILE | sponge $INFOFILE
373        # Decrement default index if needed (removed < default).
374        [[ $INDEX < $DEFINDEX ]] && jq ".default=$[DEFINDEX-1]" $INFOFILE | sponge $INFOFILE
375    fi
376}
377
378# Get default ogLive index.
379function getdefault() {
380    [ $# -ne 0 ] && raiseError usage
381    [ ! -r $INFOFILE ] && raiseError access "Configuration file."
382    # Read default parameter.
383    jq -r .default $INFOFILE || raiseError notfound "Undefined default index."
384}
385
386# Set default ogLive index.
387function setdefault() {
388    local INDEX OGLIVEDIR
389    [ $# -ne 1 ] && raiseError usage
390    [ ! -w $INFOFILE ] && raiseError access "Configuration file."
391    INDEX=$1
392    # Check if index entry exists.
393    jq ".oglive[$INDEX]" $INFOFILE || raiseError notfound "Index \"$INDEX\"."
394    # Get ogLive directory.
395    OGLIVEDIR=$(jq -r ".oglive[$INDEX].directory" $INFOFILE) || raiseError notfound "Directory for index \"$INDEX\"."
396    # Update default parameter.
397    jq ".default=$INDEX" $INFOFILE | sponge $INFOFILE
398    # Link to default directory.
399    rm -f $TFTPDIR/$DEFOGLIVE
400    ln -vfs $(basename $OGLIVEDIR) $TFTPDIR/$DEFOGLIVE
401}
402
403# Rebuild a lost configuration file.
404function rebuild() {
405    local INST i NF DEF
406    [ $# -ne 0 ] && raiseError usage
407    [ -f $INFOFILE ] && raiseError access "Configuration file exists."
408    INST=$(find $TFTPDIR/ -type d -name "$DEFOGLIVE-*" -a ! -name "*.old" -printf "%f\n" | sort)
409    for i in $INST; do
410        NF=$(echo $i | awk -F- '{print NF-1}')
411        case $NF in
412            1)  addToJson "" "$(echo $i|cut -f2 -d-)" "i386" "" "$i" "" ;;
413            4)  addToJson $(echo $i | awk -F- '{printf "%s %s i386 %s %s '""'",$2,$3,$4,$0}') ;;
414            5)  addToJson $(echo $i | awk -F- '{printf "%s %s %s %s %s '""'",$2,$3,$4,$5,$0}') ;;
415        esac
416        # Check for is default oglive.
417        [ -n "$(stat -c "%N" $TFTPDIR/$DEFOGLIVE | awk '$3~/'$i'/ {print}')" ] && DEF="$i"
418    done
419    # Set default ogLive.
420    [ -n "$DEF" ] && setdefault $(search $DEF)
421}
422
423# Assign an ISO file to a JSON entry.
424function assign() {
425local ISOFILE DIR
426    [ $# -ne 2 ] && raiseError usage
427    [ ! -w $INFOFILE ] && raiseError access "Configuration file."
428    # Check if exist ISO file and index directory.
429    ISOFILE=$DOWNLOADFILE/$1
430    [ ! -f $DOWNLOADDIR/$ISOFILE ] && raiseError notfound "ISO file \"$1\"."
431    DIR=$(search $2 2>/dev/null)
432    [ ! -d $TFTPDIR/$DIR ] && raiseError notfound "Directory for index \"$2\"."
433    # Assign ISO file to JSON entry.
434    jq ".oglive[$2].iso=\"$1\"" $INFOFILE | sponge $INFOFILE && jq ".oglive[$2]" $INFOFILE
435}
436
437
438# Main progrram.
439
440# Global constants definition.
441PROG=$(basename $(realpath "$0"))
442OPENGNSYS=/opt/opengnsys
443DOWNLOADDIR=$OPENGNSYS/lib
444DOWNLOADURL="http://opengnsys.es/downloads"
445TFTPDIR=$OPENGNSYS/tftpboot
446DEFOGLIVE=ogLive
447INFOFILE=$OPENGNSYS/etc/ogliveinfo.json
448
449# Access control.
450[ "$USER" = "root" ] || raiseError access "Need to be root."
451# Check dependencies.
452JQ=$(which jq 2>/dev/null) || raiseError notfound "Need to install \"jq\"."
453which sponge &>/dev/null || raiseError notfound "Need to install \"moreutils\"."
454# Commands control.
455case "$1" in
456    help|convert|config|check|list|show|search|download|install|uninstall|get-default|set-default|rebuild|assign)
457        COMMAND="${1/-/}"; shift; $COMMAND "$@" ;;
458    *)  raiseError usage ;;
459esac
460
461exit $?
462
Note: See TracBrowser for help on using the repository browser.