Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame^] | 1 | #!/bin/bash |
Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 2 | |
| 3 | help=$'Generate SquashFS image Script |
| 4 | |
| 5 | Generates a SquashFS image from the PNOR image |
| 6 | |
| 7 | usage: generate-squashfs [OPTION] |
| 8 | |
| 9 | Options: |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 10 | -f, --file <file> Specify destination file. Defaults to |
| 11 | `pwd`/pnor.xz.squashfs if unspecified. |
Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 12 | -h, --help Display this help text and exit. |
| 13 | ' |
| 14 | |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 15 | outfile=`pwd`"/pnor.xz.squashfs" |
Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame^] | 16 | declare -a partitions=() |
| 17 | tocfile="pnor.toc" |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 18 | |
Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 19 | while [[ $# -gt 0 ]]; do |
| 20 | key="$1" |
| 21 | case $key in |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 22 | -f|--file) |
| 23 | outfile="$2" |
| 24 | shift 2 |
| 25 | ;; |
Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 26 | -h|--help) |
| 27 | echo "$help" |
| 28 | exit |
| 29 | ;; |
| 30 | *) |
| 31 | echo "Unknown option $1. Display available options with -h or --help" |
| 32 | exit |
| 33 | ;; |
| 34 | esac |
| 35 | done |
Gunnar Mills | 18f7cdb | 2017-02-07 16:44:19 -0600 | [diff] [blame] | 36 | |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 37 | scratch_dir=`mktemp -d` || exit 1 |
Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame^] | 38 | |
| 39 | echo "Parsing PNOR TOC..." |
| 40 | { |
| 41 | while read line; do |
| 42 | if [[ $line == "ID="* ]]; then |
| 43 | # This line looks like "ID=05 MVPD 000d9000..00169000 (actual=00090000)" |
| 44 | read -r -a fields <<< "$line" |
| 45 | # Need the partition ID, name, start location, and end location |
| 46 | echo "partition${fields[0]##*=}=${fields[1]},${fields[2]/../,}" |
| 47 | # Save the partition name |
| 48 | partitions+=(${fields[1]}) |
| 49 | fi |
| 50 | done < <(pflash --info) |
| 51 | } > ${scratch_dir}/${tocfile} |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 52 | |
Gunnar Mills | 18f7cdb | 2017-02-07 16:44:19 -0600 | [diff] [blame] | 53 | for partition in "${partitions[@]}"; do |
| 54 | echo "Reading ${partition}..." |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 55 | pflash_cmd="pflash --partition=${partition} --read=${scratch_dir}/${partition}" |
Gunnar Mills | 18f7cdb | 2017-02-07 16:44:19 -0600 | [diff] [blame] | 56 | ${pflash_cmd} || exit 1 |
| 57 | done |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 58 | |
| 59 | echo "Creating SquashFS image..." |
| 60 | |
| 61 | cd "${scratch_dir}" |
Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame^] | 62 | squashfs_cmd="mksquashfs ${tocfile} ${partitions[*]} ${outfile}" |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 63 | ${squashfs_cmd} || exit 1 |
| 64 | |
| 65 | echo "SquashFS Image at ${outfile}" |
| 66 | rm -r "${scratch_dir}" |