From 926241eafd01f864869574c4f7329ed4baeb1fe4 Mon Sep 17 00:00:00 2001 From: Compro Prasad Date: Thu, 26 Jan 2017 14:29:18 +0530 Subject: [PATCH] Opening support for both Mac and Linux in downloader.sh Closes issue #21 Display a message when a platform is not supported --- BASH/downloader.sh | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/BASH/downloader.sh b/BASH/downloader.sh index 3e9330c..fe2471f 100644 --- a/BASH/downloader.sh +++ b/BASH/downloader.sh @@ -1,6 +1,20 @@ -index(){ +index() { echo "$(echo $@ | grep -aob '"' | grep -oE '[0-9]+' | sed "${!#};d")" } + +issuesPage="https://github.com/NIT-dgp/manga/issues/new" + +os=$(uname) +if [ "$os" = "Linux" -o "$os" = "FreeBSD" ]; then + openWith="$(which xdg-open 2> /dev/null)" +elif [ "$os" = "Darwin" ]; then + openWith="$(which open 2> /dev/null)" +else + echo "Platform '$os' not listed" + echo "PDF will not be automatically opened for you" + echo "Please raise an issue on $issuesPage" +fi + a="$#" declare -i chaps=0,chape=0,t=0,c=0,end_loop=0,d1=0,d2=0 #checking for existence of -t , --chap in argument @@ -15,7 +29,6 @@ do if [ "${!i}" = "-fo" ]; then x=$i fi - done if [ "$t" -ne 0 ]; then if [ "$c" -gt "$t" ]; then @@ -71,7 +84,7 @@ do fi rm index.html declare -i i=1 - while true #an infinte while loop + while true #an infinite while loop do echo "Downloading page $i of chapter $chap....." wget -q -O $i.html -c www.mangareader.net/$manga/$chap/$i # Downloads the main webpage @@ -103,9 +116,11 @@ do echo -e "Your downloaded file is in this path:\n" $path cd .. if [ "$x" != "" ]; then - nautilus $path + nautilus $path else - gnome-open chap$chapno.pdf - rm -rf $chap + if [ -n "$openWith" ]; then + $openWith chap$chapno.pdf + fi + rm -rf $chap fi done