From 7d4c1015d58b9038a49ce926b55b80ac35721e34 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 22 May 2018 01:30:35 +0200 Subject: [PATCH 1/4] switch checks --- src/func/iso_extract | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/func/iso_extract b/src/func/iso_extract index ab6c6df..e5100f7 100755 --- a/src/func/iso_extract +++ b/src/func/iso_extract @@ -15,17 +15,18 @@ function iso_extract() { return 10 } + iso_extr_dir="$2" + [ -d "$iso_extr_dir" ] || { + echo "### ERROR ### iso_extract: aim directory not exist!" + return 12 + } + iso_source="$1" [ -f "$iso_source" ] || { echo "### ERROR ### iso_extract: ISO \"$iso_source\" not exist!" return 11 } - iso_extr_dir="$2" - [ -d "$iso_extr_dir" ] || { - echo "### ERROR ### iso_extract: aim directory not exist!" - return 12 - } #mace tmp mountpoint tmpdir="`mktemp -d`" From 2a081ad5175e835ef079cc90043297b8de3950f0 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 22 May 2018 01:34:32 +0200 Subject: [PATCH 2/4] add logic --- src/func/iso_extract | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/func/iso_extract b/src/func/iso_extract index e5100f7..46a8432 100755 --- a/src/func/iso_extract +++ b/src/func/iso_extract @@ -21,10 +21,17 @@ function iso_extract() { return 12 } + iso_source_is_url=false iso_source="$1" [ -f "$iso_source" ] || { - echo "### ERROR ### iso_extract: ISO \"$iso_source\" not exist!" - return 11 + #if it is an url... + if [ url-exist ]; then + iso_source_is_url=true + #dl to tmp + set iso_source + else + echo "### ERROR ### iso_extract: ISO \"$iso_source\" not exist!" + return 11 + fi } @@ -42,6 +49,7 @@ function iso_extract() { #clear tmp mountpoint umount "$iso_source" rm -r "$tmpdir" + [ "$iso_source_is_url" == "true" ] && rm "$iso_source" tmpdir= echo "done" From 05bf2a4cdf6d0abfeac3043b73bf081f37cca164 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 22 May 2018 01:38:30 +0200 Subject: [PATCH 3/4] add new sub func --- src/func/check_url | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/func/check_url diff --git a/src/func/check_url b/src/func/check_url new file mode 100644 index 0000000..53b23e0 --- /dev/null +++ b/src/func/check_url @@ -0,0 +1,20 @@ +#!/bin/bash +#remaster lib +[ -d "" ] || { echo "LIBDIR not exist"; exit 1; } + +#check_url [URL] +function check_url() { + URL="$1" + if [[ `wget -S --spider "$URL" 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then + echo "true" + return 0 + else + echo "false" + return 1 + fi +} + +#this func is standalone executable +[ -n "$1" ] && { + check_url $@ +} From 32cfb2a7a43381d1ba45a106e95a2b62ea357f60 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 22 May 2018 01:47:10 +0200 Subject: [PATCH 4/4] finish --- src/func/iso_extract | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/func/iso_extract b/src/func/iso_extract index 46a8432..d89ff28 100755 --- a/src/func/iso_extract +++ b/src/func/iso_extract @@ -21,13 +21,13 @@ function iso_extract() { return 12 } - iso_source_is_url=false iso_source="$1" [ -f "$iso_source" ] || { #if it is an url... - if [ url-exist ]; then - iso_source_is_url=true + if [ "`check_url $iso_source`" == "true" ]; then #dl to tmp + set iso_source + iso_tmp="`mktemp --suffix=.iso`"; rm "$iso_tmp" + wget -O "$iso_tmp" "$iso_source" else echo "### ERROR ### iso_extract: ISO \"$iso_source\" not exist!" return 11 @@ -49,7 +49,7 @@ function iso_extract() { #clear tmp mountpoint umount "$iso_source" rm -r "$tmpdir" - [ "$iso_source_is_url" == "true" ] && rm "$iso_source" + [ -n "$iso_tmp" ] && rm "$iso_tmp" tmpdir= echo "done"