annotate util.sh @ 2:ce6db18f5fd3 draft

Uploaded
author bcclaywell
date Thu, 26 Feb 2015 19:31:20 -0500
parents d4690e65afcd
children b6ece07bec6a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
1 #!/bin/bash
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
2
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
3 extify() {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
4 local REQ_EXT=$1
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
5 shift
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
6
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
7 local OUTPUT=""
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
8 local FILE
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
9 for FILE in $*; do
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
10 local BASENAME=$(basename ${FILE})
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
11 local EXT=${BASENAME##*.}
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
12 if [[ ${EXT} != ${REQ_EXT} ]]; then
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
13 local LINK="${BASENAME%%.*}.${REQ_EXT}"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
14 if [[ ! -f ${LINK} ]]; then
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
15 ln -s ${FILE} ${LINK}
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
16 fi
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
17 FILE="${LINK}"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
18 fi
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
19 OUTPUT="${OUTPUT} ${FILE}"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
20 done
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
21
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
22 echo ${OUTPUT}
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
23 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
24
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
25 # from http://www.linuxjournal.com/content/use-date-command-measure-elapsed-time
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
26 timer() {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
27 if [[ $# -eq 0 ]]; then
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
28 echo $(date '+%s')
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
29 else
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
30 local stime=$1
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
31 etime=$(date '+%s')
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
32
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
33 if [[ -z "$stime" ]]; then stime=$etime; fi
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
34
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
35 dt=$((etime - stime))
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
36 ds=$((dt % 60))
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
37 dm=$(((dt / 60) % 60))
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
38 dh=$((dt / 3600))
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
39 printf '%d:%02d:%02d' $dh $dm $ds
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
40 fi
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
41 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
42
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
43 on_exit() {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
44 echo "Elapsed time: $(timer ${START_TIME})"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
45 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
46
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
47 set -eux
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
48
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
49 xargs -n 1 -0 < /proc/self/environ > env.log
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
50
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
51 START_TIME=$(timer)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
52 trap on_exit EXIT