aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkatherine <shmibs@shmibbles.me>2017-03-24 01:51:49 -0700
committerkatherine <shmibs@shmibbles.me>2017-03-24 01:51:49 -0700
commit6cabff51c86d045fc0c9125671919b292c87d92f (patch)
treeec88ea64fbb298388dbb79cd2185cd1d5d030415
parentb189b570267d1b6c057c4b4121c191d6f988fad8 (diff)
downloadmake-gif-6cabff51c86d045fc0c9125671919b292c87d92f.tar.gz
handle signal termination
-rwxr-xr-xmake-gif33
1 files changed, 19 insertions, 14 deletions
diff --git a/make-gif b/make-gif
index 320a4a0..2c33718 100755
--- a/make-gif
+++ b/make-gif
@@ -17,8 +17,7 @@ usage() {
echo " length in seconds -t <num> full length"
echo " gif fps -f <num> 10"
echo " gif pixel width -w <num> 480"
- echo " use subtitles -b"
- echo " use subtitle track -n <int> 0"
+ echo " use subtitle track -b <int> none"
[[ $hasgsic ]] && echo "optimise with gifsicle -g"
echo " print this help -h"
exit 1
@@ -28,8 +27,10 @@ usage() {
local tmp_pref
rm_tmps() {
- rm -f ${tmp_pref}-palette.png
- rm -f ${tmp_pref}-in
+ if [[ ${tmp_pref} ]]; then
+ rm -f ${tmp_pref}-palette.png
+ rm -f ${tmp_pref}-in
+ fi
}
abort() {
@@ -38,6 +39,8 @@ abort() {
exit 1
}
+trap 'abort' SIGABRT SIGHUP SIGINT SIGQUIT SIGTERM
+
local start="00:00:00"
local length=""
local fps=10
@@ -79,11 +82,11 @@ if [[ $hasgsic ]]; then
&& usage "width must be a positive integer"
width=$OPTARG
;;
- b) subs=true ;;
- n)
+ b)
[[ ! $(echo $OPTARG | grep -oE "$zintpat") ]] \
&& usage "sub track index must be a non-negative integer"
strack=$OPTARG
+ subs=true
;;
g) gsic=true ;;
h) usage ;;
@@ -114,11 +117,11 @@ else
&& usage "width must be a positive integer"
width=$OPTARG
;;
- b) subs=true ;;
- n)
+ b)
[[ ! $(echo $OPTARG | grep -oE "$zintpat") ]] \
&& usage "sub track index must be a non-negative integer"
strack=$OPTARG
+ subs=true
;;
h) usage ;;
[?]) usage "unrecognised option" ;;
@@ -137,15 +140,17 @@ shift $OPTIND-1
[[ "$1" != "%d.png" ]] && [[ ! -f "$1" ]] && usage "input file not found"
# make links
-tmp_pref="make-gif"
-tmp_pref="${2:h}/$tmp_pref"
-
-echo $tmp_pref
+local tmp_pref_i
+tmp_pref_i="make-gif"
+tmp_pref_i="${2:h}/${tmp_pref_i}"
-while [[ -f "${tmp_pref}-palette.png" ]] || [[ -f "${tmp_pref}-in" ]]; do
- tmp_pref="${tmp_pref}-1"
+while [[ -f "${tmp_pref_i}-palette.png" ]] || [[ -f "${tmp_pref_i}-in" ]]; do
+ tmp_pref_i="${tmp_pref_i}-1"
done
+tmp_pref="${tmp_pref_i}"
+
+
ln -s "${1:a}" "${tmp_pref}-in" \
|| abort "could not write to output dir"