Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

executable file 118 lines (99 sloc) 2.047 kb
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
#!/bin/sh
# create an SD card image

USAGE()
{
  [ -z "$1" ] || echo error: $*
  echo usage: $(basename "$0") '<options> <languages>'
  echo ' --help -h this message'
  echo ' --verbose -v more messages'
  echo ' --image=<dir> -i <dir> image source directory [image]'
  echo ' --card=<dir> -c <dir> image destination directory (no-default)'
  exit 1
}


verbose=no
image=image
card=
suffix=pedia

debug=no

getopt=/usr/local/bin/getopt
[ -x "${getopt}" ] || getopt=getopt
args=$(${getopt} -o hvi:c: --long=help,verbose,image:,card:,debug -- "$@") ||exit 1

# replace the arguments with the parsed values
eval set -- "${args}"

while :
do
  case "$1" in
    -v|--verbose)
      verbose=yes
      shift
      ;;

    -i|--image)
      image="$2"
      shift 2
      ;;

    -c|--card)
      card="$2"
      shift 2
      ;;

    --debug)
      debug=yes
      shift
      ;;

    --)
      shift
break
      ;;

    -h|--help)
      USAGE
      ;;

    *)
      USAGE invalid option: $1
      ;;
  esac
done

# verify arguments
[ -z "${card}" ] && USAGE card is not set
[ -z "${image}" ] && USAGE image is not set
[ $# -eq 0 ] && USAGE at least one language must be specified

[ -d "${card}" ] || USAGE card: ${card} is not a directory
[ -f "${card}/kernel.elf" ] && USAGE already copied

for d in $@
do
  flag=NO
  for i in ${image}
  do
    dir="${i}/${d}${suffix}"
    if [ -d "${dir}" -o -d "${i}/${d}" ]
    then
      flag=YES
      break
fi
  done
  [ X"YES" = X"${flag}" ] || USAGE language ${d} not found
done

for d in $@
do
  for i in ${image}
  do
    dir="${i}/${d}${suffix}"
    if [ -d "${dir}" ]
    then
      echo copying language: ${d}
      cp -pr "${dir}" "${card}"
      break
fi
    dir="${i}/${d}"
    if [ -d "${dir}" ]
    then
      echo copying directory: ${d}
      cp -pr "${dir}" "${card}"
      break
fi
  done
done

echo copying base files
for f in "${image}/"*
do
  [ ! -d "${f}" ] && cp -p "${f}" "${card}"
done

echo completed
Something went wrong with that request. Please try again.