1*6a3e4e45SGunnar Mills#!/bin/bash
2*6a3e4e45SGunnar Millsset -eo pipefail
3*6a3e4e45SGunnar Mills
4*6a3e4e45SGunnar Millshelp=$'Generate PNOR UBI image from a PNOR SquashFS Tarball
5*6a3e4e45SGunnar Mills
6*6a3e4e45SGunnar MillsGenerates a UBI, Unsorted Block Images, PNOR image from a PNOR SquashFS Tarball.
7*6a3e4e45SGunnar MillsThe PNOR SquashFS Tarball is generated from the generate-squashfs script.
8*6a3e4e45SGunnar Mills
9*6a3e4e45SGunnar Millsusage: generate-ubi [OPTION] <PNOR SquashFS Tarball>...
10*6a3e4e45SGunnar Mills
11*6a3e4e45SGunnar MillsOptions:
12*6a3e4e45SGunnar Mills   -f, --file <file>      Specify destination file. Defaults to
13*6a3e4e45SGunnar Mills                          `pwd`/<PNOR Tarball FILE, removing .squashfs.tar>.ubi.mtd
14*6a3e4e45SGunnar Mills                          (For example, "generate-ubi my.pnor.squashfs.tar"
15*6a3e4e45SGunnar Mills                          would generate `pwd`/my.pnor.ubi.mtd output.)
16*6a3e4e45SGunnar Mills   -h, --help             Display this help text and exit.
17*6a3e4e45SGunnar Mills'
18*6a3e4e45SGunnar Mills
19*6a3e4e45SGunnar Millswhile [[ $# -gt 0 ]]; do
20*6a3e4e45SGunnar Mills  key="$1"
21*6a3e4e45SGunnar Mills  case $key in
22*6a3e4e45SGunnar Mills    -f|--file)
23*6a3e4e45SGunnar Mills      outfile="$2"
24*6a3e4e45SGunnar Mills      shift 2
25*6a3e4e45SGunnar Mills      ;;
26*6a3e4e45SGunnar Mills    -h|--help)
27*6a3e4e45SGunnar Mills      echo "$help"
28*6a3e4e45SGunnar Mills      exit
29*6a3e4e45SGunnar Mills      ;;
30*6a3e4e45SGunnar Mills    *)
31*6a3e4e45SGunnar Mills      tarball="$1"
32*6a3e4e45SGunnar Mills      shift 1
33*6a3e4e45SGunnar Mills      ;;
34*6a3e4e45SGunnar Mills  esac
35*6a3e4e45SGunnar Millsdone
36*6a3e4e45SGunnar Mills
37*6a3e4e45SGunnar Millsif [ ! -f "${tarball}" ]; then
38*6a3e4e45SGunnar Mills  echo "Please enter a PNOR SquashFS Tarball."
39*6a3e4e45SGunnar Mills  echo "To generate PNOR SquashFS Tarball see generate-squashfs"
40*6a3e4e45SGunnar Mills  echo "$help"
41*6a3e4e45SGunnar Mills  exit 1
42*6a3e4e45SGunnar Millsfi
43*6a3e4e45SGunnar Mills
44*6a3e4e45SGunnar Millsif [[ -z $outfile ]]; then
45*6a3e4e45SGunnar Mills    # Remove .squashfs.tar from end if present and add .ubi.mtd
46*6a3e4e45SGunnar Mills    outfile=`pwd`/${tarball%".squashfs.tar"}.ubi.mtd
47*6a3e4e45SGunnar Millselse
48*6a3e4e45SGunnar Mills  if [[ $outfile != /* ]]; then
49*6a3e4e45SGunnar Mills    outfile=`pwd`/$outfile
50*6a3e4e45SGunnar Mills  fi
51*6a3e4e45SGunnar Millsfi
52*6a3e4e45SGunnar Mills
53