Das eigentliche Update in eine eigene Funktion geschrieben. Die Mainfunktion komplett geändert. Optionsschalter beim starten des Scripts hinzugefügt. --version --help

This commit is contained in:
Leon Gaultier 2014-03-27 20:58:36 +01:00
parent 20497c502d
commit 11361c4844

View File

@ -6,7 +6,7 @@
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. # any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -17,9 +17,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/> # along with this program. If not, see <http://www.gnu.org/licenses/>
# #
scriptVersion=0.6
#################################### ####################################
#################################### ####################################
@ -69,15 +66,47 @@ export CALIBRE_INSTALL_LOCATION=/opt
# The download URL # The download URL
DOWNLOAD_URL=https://github.com/kovidgoyal/calibre/raw/master/setup/linux-installer.py DOWNLOAD_URL=https://github.com/kovidgoyal/calibre/raw/master/setup/linux-installer.py
############################
# Variablen für den Verfügbarkeitscheck # Variablen für den Verfügbarkeitscheck
CHECK_CALIBRE_DOWNLOAD_PAGE=http://calibre-ebook.com CHECK_CALIBRE_DOWNLOAD_PAGE=http://calibre-ebook.com
CHECK_DOWNLOAD_URL=https://github.com CHECK_DOWNLOAD_URL=https://github.com
# Programmversion
progname=`basename $0`
version="0.7"
quiet=0
################################# #################################
##### Zusätzliche Funktionen ##### ##### Zusätzliche Funktionen #####
funct_vercomp () { # Funktion zum Versionsvergleich func_usage ()
{
echo "Usage: $progname [OPTION...]"
echo "Try '$progname --help' or '$progname -h' for more information."
}
func_help ()
{
echo "Usage: $progname [OPTION...]"
echo "$progname -- the Calibre! Linux Edition calibre updater"
echo ""
echo "Options:"
echo " -q, --quiet Disable output"
echo " -h, --help Give this help list"
echo " -V, --version Print program version"
echo ""
echo "Report bugs to <leongaultier@gmail.com>."
}
func_version ()
{
echo "$progname: the avast! workstation VPS file updater v$version"
echo "Copyright (C) Leon Gaultier 2014. This program is distributed"
echo "in the hope that it will be useful, but WITHOUT ANY WARRANTY"
}
func_vercomp () { # Funktion zum Versionsvergleich
if [[ $1 == $2 ]] if [[ $1 == $2 ]]
then then
return 0 return 0
@ -108,7 +137,7 @@ funct_vercomp () { # Funktion zum Versionsvergleich
return 0 return 0
} }
funct_check_stat () { # Funktion zum Check Verfügbarkeit der Downloadseiten und der Internetverbindung func_check_stat () { # Funktion zum Check Verfügbarkeit der Downloadseiten und der Internetverbindung
# Test for network conection # Test for network conection
echo -e "\033[1;34m Ich schau dann mal ob Dein Computer überhaupt ein Netzwerk hat :-)"; echo -e "\033[1;34m Ich schau dann mal ob Dein Computer überhaupt ein Netzwerk hat :-)";
for INTERFACE in $(ls /sys/class/net/ | grep -v lo); for INTERFACE in $(ls /sys/class/net/ | grep -v lo);
@ -134,7 +163,7 @@ else
fi fi
} }
funct_check_run_calibre () { func_check_run_calibre () {
CALIBRE_PID=`ps ax | grep /opt/calibre/bin/calibre | grep -v grep | awk '{printf $1}'` CALIBRE_PID=`ps ax | grep /opt/calibre/bin/calibre | grep -v grep | awk '{printf $1}'`
while [ $CALIBRE_PID ]; while [ $CALIBRE_PID ];
@ -154,7 +183,7 @@ funct_check_run_calibre () {
return 0 return 0
} }
funct_http_status_code () { func_http_status_code () {
echo -e "\033[1;34m Hole Status Code von \"$CHECK_CALIBRE_DOWNLOAD_PAGE\". Bitte warten."; echo -e "\033[1;34m Hole Status Code von \"$CHECK_CALIBRE_DOWNLOAD_PAGE\". Bitte warten.";
stat_1=$(curl -o /dev/null --silent --head --write-out '%{http_code}' $CHECK_CALIBRE_DOWNLOAD_PAGE) stat_1=$(curl -o /dev/null --silent --head --write-out '%{http_code}' $CHECK_CALIBRE_DOWNLOAD_PAGE)
echo -e "\033[32m Status Codes von \"$CHECK_CALIBRE_DOWNLOAD_PAGE\" erhalten"; echo -e "\033[32m Status Codes von \"$CHECK_CALIBRE_DOWNLOAD_PAGE\" erhalten";
@ -164,26 +193,33 @@ funct_http_status_code () {
return 0 return 0
} }
funct_term_output () { func_term_output () {
## Beginne mit der Ausgbe ## ## Beginne mit der Ausgbe ##
tty -s && clear tty -s && clear
echo -e "\033[44m \033[0m\033[1m Calibre AutoUpdate Version $scriptVersion\033[0m\n\033[44m \033[0m 2014 by Marko Oldenburg\n"; echo -e "\033[44m \033[0m\033[1m Calibre AutoUpdate Version $version\033[0m\n\033[44m \033[0m 2014 by Marko Oldenburg\n";
return 0 return 0
} }
func_check_progs () {
}
####################################################### #######################################################
####################################################### #######################################################
## main vom Script --- Start des Updater Skripts ## main vom Script --- Start des Updater Skripts
func_update () {
# Wenn eine grafische Oberfläche vorhanden ist, wird u.a. "notify-send" für Benachrichtigungen verwendet, ansonsten immer "echo" # Wenn eine grafische Oberfläche vorhanden ist, wird u.a. "notify-send" für Benachrichtigungen verwendet, ansonsten immer "echo"
NOTIFY="echo" NOTIFY="echo"
[ -n "$DISPLAY" ] && NOTIFY="notify-send -t 10000 -i /usr/share/icons/hicolor/256x256/apps/calibre-gui.png Calibre-Auto-Updater" [ -n "$DISPLAY" ] && NOTIFY="notify-send -t 10000 -i /usr/share/icons/hicolor/256x256/apps/calibre-gui.png Calibre-Auto-Updater"
funct_term_output func_term_output
funct_http_status_code # Funktion hole einen http-status code func_http_status_code # Funktion hole einen http-status code
func_check_stat # Funktion check Status Netzwerk und Downloadadressen
funct_check_stat # Funktion check Status Netzwerk und Downloadadressen
case $? in case $? in
1) 1)
#Ermitteln der letzten aktuell verfügbaren Version #Ermitteln der letzten aktuell verfügbaren Version
@ -191,7 +227,7 @@ case $? in
#Ermitteln der aktuell installierten Version. #Ermitteln der aktuell installierten Version.
CURRENT_VERSION=`calibre --version | sed 's/[^0-9.]*\([0-9.]*\).*/\1/'` CURRENT_VERSION=`calibre --version | sed 's/[^0-9.]*\([0-9.]*\).*/\1/'`
funct_vercomp $CURRENT_VERSION $LATEST_VERSION # Funktion Versionvergleich func_vercomp $CURRENT_VERSION $LATEST_VERSION # Funktion Versionvergleich
case $? in case $? in
0) 0)
$NOTIFY "Deine Calibre Version ist auf dem aktuellsten Stand ($CURRENT_VERSION).";; $NOTIFY "Deine Calibre Version ist auf dem aktuellsten Stand ($CURRENT_VERSION).";;
@ -200,7 +236,7 @@ case $? in
2) 2)
$NOTIFY "Ein Calibre Update ist verfügbar. (Installiert: \"$CURRENT_VERSION\", letzte Verfügbare: \"$LATEST_VERSION\")" $NOTIFY "Ein Calibre Update ist verfügbar. (Installiert: \"$CURRENT_VERSION\", letzte Verfügbare: \"$LATEST_VERSION\")"
# Installiert die aktuellste verfügbare Version von der Calibre Homepage # Installiert die aktuellste verfügbare Version von der Calibre Homepage
funct_check_run_calibre # Aufruf der Funktion ob Calibre gestartet ist func_check_run_calibre # Aufruf der Funktion ob Calibre gestartet ist
$NOTIFY "Das Update wird nun installiert. Bitte gib hierzu Dein Userpasswort im Terminalfenster ein..." $NOTIFY "Das Update wird nun installiert. Bitte gib hierzu Dein Userpasswort im Terminalfenster ein..."
echo -e "\033[1;34m" echo -e "\033[1;34m"
sudo -v && wget -nv -O- $DOWNLOAD_URL | sudo python -c "import sys; main=lambda x:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main('$CALIBRE_INSTALL_LOCATION')" sudo -v && wget -nv -O- $DOWNLOAD_URL | sudo python -c "import sys; main=lambda x:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main('$CALIBRE_INSTALL_LOCATION')"
@ -220,3 +256,28 @@ case $? in
$NOTIFY "Update und Versionsvergleich fehlgeschlagen!!! Kann kein Netzwerkinterface finden!" $NOTIFY "Update und Versionsvergleich fehlgeschlagen!!! Kann kein Netzwerkinterface finden!"
;; ;;
esac esac
}
while test "$#" -gt 0
do
arg="$1"
shift
case $arg in
-*=*) optarg=`echo "$arg" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case "$arg" in
--quiet | -q )
quiet=1 ;;
--help | -h )
func_help; exit 0 ;;
--version | -V | -v )
func_version; exit 0 ;;
esac
done
func_update
exit 0