-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathonie_pack.sh
executable file
·57 lines (50 loc) · 1.32 KB
/
onie_pack.sh
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
#!/bin/sh
#
# Copyright (C) 2018 Alexander Petrovskiy <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0
#
# Script to pack Linux OS image file (ISO, IMG, etc.) into ONIE installer
#
INSTDIR=./installers
DEFINST=ubuntu18xx-iso
DATE=`date +%Y%m%d`
ONIEIMG="onie-installer-x86_64-${DATE}.bin"
usage() {
echo "Usage: $0 [-i installer] os_image"
echo " Supported installers:"
for file in ./installers/*; do
inst=`basename $file`
if [ "$inst" = "$DEFINST" ]; then
echo " - `basename $file` [default]"
else
echo " - `basename $file`"
fi
done
exit
}
fail() {
[ "$1" != "" ] && echo $1
exit 1
}
[ -d $INSTDIR ] || fail "Installers dir not found: $INSTDIR"
if [ $# -lt 1 ]; then
usage
elif [ $# -eq 1 ]; then
INSTALLER=$DEFINST
OSIMG=$1
elif [ $# -eq 3 ] && [ "$1" = "-i" ]; then
INSTALLER=$2
OSIMG=$3
else
usage
fi
INSTPATH="$INSTDIR/$INSTALLER"
[ -f $INSTPATH ] || fail "Unsupported installer: $INSTALLER"
[ -f $OSIMG ] || fail "OS image is not available: $OSIMG"
echo "== Installer selected: $INSTALLER"
echo "== Packing OS image: $OSIMG"
cp -f $INSTPATH $ONIEIMG
echo >> $ONIEIMG
cat "$OSIMG" >> $ONIEIMG
echo "== ONIE installer is ready: $ONIEIMG (`du -sh $ONIEIMG | awk '{ print $1 }'`)"