I made this BASH script to read manga/comic directly from .zip/.rar file:
Code:
#!/bin/bash
#iManga-reader-advanced i.e. with error checking.
#You can use the normal one without error checking.
#You must have gnome (zenity), gqview, unrar and unzip
#programs installed on your system.
#chii-chan 2005
var1=gqview
var2=`ps h -C gqview | awk '{print $5}'`
var3=~/.iManga-reader-tmp
#check if another gqview is running
if [ "$var1" = "$var2" ]; then
number=`ps h -C $var1 | awk '{print $1}'`
kill -9 $number
else
echo "gqview not running"
fi
mkdir $var3
if [ $? == 0 ]; then
echo "Success"
else
echo "Directory exists!"
#remove the temporary folder
rm -rf $var3
#It is important to remove and recreate the directory
#since there are possibly some files inside the directory
#from script crash.
mkdir $var3
fi
#check for file types
if [ `echo "$1" | cut -d. -f2- | grep zip` ]; then
echo "I find zip file!"
unzip -t "$1"
if [ $? == 0 ]; then
(
unzip "$1" -d $var3
echo "100"; sleep 0.5
) |
zenity --progress --pulsate --auto-close --text="Extracting..." --title="Please wait for a while."
echo "success"
else
echo "I'm broken"
zenity --error --text="Sorry. I can't open this file." --title="Error" --width=200 --height=100
#remove the temporary folder
rm -rf $var3
exit 1
fi
elif [ `echo "$1" | cut -d. -f2- | grep rar` ]; then
echo "I find rar file!"
unrar t "$1"
if [ $? == 0 ]; then
(
unrar x "$1" -d $var3
echo "100"; sleep 0.5
) |
zenity --progress --pulsate --auto-close --text="Extracting..." --title="Please wait for a while."
echo "success"
else
echo "I'm broken"
zenity --error --text="Sorry. I can't open this file." --title="Error" --width=200 --height=100
#remove the temporary folder
rm -rf $var3
exit 1
fi
else
echo "I'm broken badly!!!"
zenity --error --text="Sorry. I can't recognize this file. May be you need to rename the file to something that I can recognize. :)" --title="Error" --width=200 --height=100
#remove the temporary folder
rm -rf $var3
exit 1
fi
#open files with gqview
gqview $var3
#remove the temporary folder
rm -rf $var3
exit 0
Which means with this script I just need to right click in Nautilus and open it automatically. But my problem is with this part:
Code:
if [ `echo "$1" | cut -d. -f2- | grep zip` ]; then
echo "I find zip file!"
unzip -t "$1"
if [ $? == 0 ]; then
(
unzip "$1" -d $var3
echo "100"; sleep 0.5
) |
zenity --progress --pulsate --auto-close --text="Extracting..." --title="Please wait for a while."
echo "success"
else
echo "I'm broken"
zenity --error --text="Sorry. I can't open this file." --title="Error" --width=200 --height=100
#remove the temporary folder
rm -rf $var3
exit 1
fi
...
...
...
fi
I want to do something like this:
Code:
if [ `echo "$1" | cut -d. -f2- | grep zip` ]; then
echo "I find zip file!"
(
unzip "$1" -d $var3
if [ $? == 0 ]; then
echo "Success"
echo "100"; sleep 0.5
else
echo "I'm broken"
echo "100"; sleep 0.5
zenity --error --text="Sorry. I can't open this file." --title="Error" --width=200 --height=100
#remove the temporary folder
rm -rf $var3
exit 1
fi
) |
zenity --progress --pulsate --auto-close --text="Extracting..." --title="Please wait for a while."
echo "success"
...
...
...
fi
My problems are:
1) The 'exit 1' in between ( ) won't work. It will not exit the script. Instead it will continue running 'gqview' even if the outcome is error from .zip file extraction.
2) '( ) | zenity --progress' contruct (in the documentation) is the only way to send "100" percent to zenity --progress so that I can let it autoclose with '--auto-close'.
3) Even if I put 'exit 1' inside there. The script will return 0 since 'zenity --progress' is successfully executed.
4) Having 'unzip -t "$1" solved the problem. But the progress does not show from 'unzip -t "$1", but from 'unzip "$1" -d $var3' instead. So the progress bar is not really correct.
What I want to do with the part are:
1) I want to run 'unzip'.
2) If it returns "0" then, then close 'zenity --progress'.
3) Then continue to the end of the script.
4) Improves the script (for sure).
I'm using zenity version 1.6. Any help would be (really) appreciated.