Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 172 lines (146 sloc) 2.927 kb
a55954f @hxw [scripts] various scripts
hxw authored
1 #!/bin/sh
2 # create an SD card image
3
4 USAGE()
5 {
6 [ -z "$1" ] || echo error: $*
6331bb6 @hxw [scripts] option to copy root files
hxw authored
7 echo usage: $(basename "$0") '<options> <languages|ROOT>'
a55954f @hxw [scripts] various scripts
hxw authored
8 echo ' --help -h this message'
9 echo ' --verbose -v more messages'
ef2083a @hxw [scripts] add force option
hxw authored
10 echo ' --force -f ignore already copied check'
a55954f @hxw [scripts] various scripts
hxw authored
11 echo ' --image=<dir> -i <dir> image source directory [image]'
12 echo ' --card=<dir> -c <dir> image destination directory (no-default)'
13 exit 1
14 }
15
16
17 verbose=no
ef2083a @hxw [scripts] add force option
hxw authored
18 force=no
a55954f @hxw [scripts] various scripts
hxw authored
19 image=image
20 card=
21 suffix=pedia
22
23 debug=no
24
25 getopt=/usr/local/bin/getopt
26 [ -x "${getopt}" ] || getopt=getopt
ef2083a @hxw [scripts] add force option
hxw authored
27 args=$(${getopt} -o hvfi:c: --long=help,verbose,force,image:,card:,debug -- "$@") ||exit 1
a55954f @hxw [scripts] various scripts
hxw authored
28
29 # replace the arguments with the parsed values
30 eval set -- "${args}"
31
32 while :
33 do
34 case "$1" in
35 -v|--verbose)
36 verbose=yes
37 shift
38 ;;
39
ef2083a @hxw [scripts] add force option
hxw authored
40 -f|--force)
41 force=yes
42 shift
43 ;;
44
a55954f @hxw [scripts] various scripts
hxw authored
45 -i|--image)
46 image="$2"
47 shift 2
48 ;;
49
50 -c|--card)
51 card="$2"
52 shift 2
53 ;;
54
55 --debug)
56 debug=yes
57 shift
58 ;;
59
60 --)
61 shift
62 break
63 ;;
64
65 -h|--help)
66 USAGE
67 ;;
68
69 *)
70 USAGE invalid option: $1
71 ;;
72 esac
73 done
74
75 # verify arguments
76 [ -z "${card}" ] && USAGE card is not set
77 [ -z "${image}" ] && USAGE image is not set
78 [ $# -eq 0 ] && USAGE at least one language must be specified
79
80 [ -d "${card}" ] || USAGE card: ${card} is not a directory
ef2083a @hxw [scripts] add force option
hxw authored
81
82 case "${force}" in
83 [yY]|[yY][eE][sS])
84 ;;
85 *)
86 [ -f "${card}/kernel.elf" ] && USAGE already copied
87 ;;
88 esac
89
a55954f @hxw [scripts] various scripts
hxw authored
90
378e081 @hxw [scripts] couple of small fixes
hxw authored
91 COPY()
92 {
93 local file dest name
94 file="$1"; shift
95 dest="$1"; shift
96 name="$(basename "${file}" | tr a-z A-Z)"
97 dest="${dest}/${name}"
98 printf "copying: ${name}\033[0K\r"
99 cp -p "${file}" "${dest}"
100 }
101
102 COPY_DIR()
103 {
104 local dir dest name file
105 dir="$1"; shift
106 dest="$1"; shift
107 name="$(basename "${dir}" | tr a-z A-Z)"
108 dest="${dest}/${name}"
109 mkdir -p "${dest}"
110 for file in "${dir}/"*
111 do
112 if [ ! -d "${file}" ]
113 then
114 COPY "${file}" "${dest}"
115 fi
116 done
117 echo
118 }
119
6331bb6 @hxw [scripts] option to copy root files
hxw authored
120 [ X"ROOT" = X"$1" ] && shift
121
a55954f @hxw [scripts] various scripts
hxw authored
122 for d in $@
123 do
124 flag=NO
125 for i in ${image}
126 do
127 dir="${i}/${d}${suffix}"
128 if [ -d "${dir}" -o -d "${i}/${d}" ]
129 then
130 flag=YES
131 break
132 fi
133 done
134 [ X"YES" = X"${flag}" ] || USAGE language ${d} not found
135 done
136
137 for d in $@
138 do
139 for i in ${image}
140 do
141 dir="${i}/${d}${suffix}"
142 if [ -d "${dir}" ]
143 then
144 echo copying language: ${d}
378e081 @hxw [scripts] couple of small fixes
hxw authored
145 echo cp -pr "${dir}" "${card}"
146 COPY_DIR "${dir}" "${card}"
a55954f @hxw [scripts] various scripts
hxw authored
147 break
148 fi
149 dir="${i}/${d}"
150 if [ -d "${dir}" ]
151 then
152 echo copying directory: ${d}
378e081 @hxw [scripts] couple of small fixes
hxw authored
153 echo cp -pr "${dir}" "${card}"
154 COPY_DIR "${dir}" "${card}"
a55954f @hxw [scripts] various scripts
hxw authored
155 break
156 fi
157 done
158 done
159
160 echo copying base files
161 for f in "${image}/"*
162 do
378e081 @hxw [scripts] couple of small fixes
hxw authored
163 if [ ! -d "${f}" ]
164 then
165 COPY "${f}" "${card}"
f33fe7e @hxw [scripts] prevent OS/X adding unwanted files to SD images
hxw authored
166 touch "${card}/.metadata_never_index"
378e081 @hxw [scripts] couple of small fixes
hxw authored
167 fi
a55954f @hxw [scripts] various scripts
hxw authored
168 done
378e081 @hxw [scripts] couple of small fixes
hxw authored
169 echo
a55954f @hxw [scripts] various scripts
hxw authored
170
171 echo completed
Something went wrong with that request. Please try again.