diff --git a/calibre-autoupdate b/calibre-autoupdate index 2454144..0f4266a 100755 --- a/calibre-autoupdate +++ b/calibre-autoupdate @@ -6,7 +6,7 @@ # 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 # 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, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -17,9 +17,6 @@ # along with this program. If not, see # -scriptVersion=0.6 - - #################################### #################################### @@ -69,15 +66,47 @@ export CALIBRE_INSTALL_LOCATION=/opt # The download URL DOWNLOAD_URL=https://github.com/kovidgoyal/calibre/raw/master/setup/linux-installer.py -############################ # Variablen für den Verfügbarkeitscheck CHECK_CALIBRE_DOWNLOAD_PAGE=http://calibre-ebook.com CHECK_DOWNLOAD_URL=https://github.com +# Programmversion +progname=`basename $0` +version="0.7" +quiet=0 + + ################################# ##### 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 ." +} + +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 ]] then return 0 @@ -108,7 +137,7 @@ funct_vercomp () { # Funktion zum Versionsvergleich 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 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); @@ -134,7 +163,7 @@ else fi } -funct_check_run_calibre () { +func_check_run_calibre () { CALIBRE_PID=`ps ax | grep /opt/calibre/bin/calibre | grep -v grep | awk '{printf $1}'` while [ $CALIBRE_PID ]; @@ -154,7 +183,7 @@ funct_check_run_calibre () { 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."; 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"; @@ -164,26 +193,33 @@ funct_http_status_code () { return 0 } -funct_term_output () { +func_term_output () { ## Beginne mit der Ausgbe ## 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 } +func_check_progs () { + + + +} ####################################################### ####################################################### ## 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" NOTIFY="echo" [ -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 1) #Ermitteln der letzten aktuell verfügbaren Version @@ -191,7 +227,7 @@ case $? in #Ermitteln der aktuell installierten Version. 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 0) $NOTIFY "Deine Calibre Version ist auf dem aktuellsten Stand ($CURRENT_VERSION).";; @@ -200,7 +236,7 @@ case $? in 2) $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 - 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..." 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')" @@ -220,3 +256,28 @@ case $? in $NOTIFY "Update und Versionsvergleich fehlgeschlagen!!! Kann kein Netzwerkinterface finden!" ;; 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 \ No newline at end of file