#!/bin/bash # Calibre Auto Updater - The Skript automatically updates your Calibre (http://calibre-ebook.com/) # Installation # Copyright (C) 2013-2014 Leon Gaultier # # 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 # 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 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see # #################################### #################################### # # Versionsverlauf # # V0.1 Body des Skriptes erstellt # Abfrage neuste Version vorhanden # Abfrage welche Version installiert # Funktion Versionsvergleich # Download und installation der neusten Version # Desktopmeldungen hinzugefügt # # V0.2 Verbesserungen bei den Desktopmeldungen # # V0.3 Funktion Check Verfügbarkeit der Downloadseiten hinzugefügt # # V0.4 Check Verfügbarkeit auf Test Netzwerk vorhanden und Auswertung erweitert # diverse Kommentare hinzugefügt # # V0.5 Funktion Check läuft noch eine Calibre Instanz mit Counter # Ausgabe Texte verbessert und erweitert # URL Statuscodes holen ins main verlagert. !TODO Soll eigene Funktion werden # # V0.6 Verbesserungen in der Terminalausgabe, Startausgabe ist eine eigene Funktion # URL Status Code ist nun eine eigene Funktion # # V0.7 Der Updateprozes wurde in eine Prozedure geschrieben und die main Prozedure gibt, # nur noch Hilfe und Verion aus oder startet sofort die Update Prozedure # # TODO auslesen der Download URL von der Download Seite # kontrolle ob alle benötigten programme für das skript vorhanden sind # # ###################################### ###################################### ################################# ######### CONFIGURATION ######### # Diese Version funktioniert für alle Linuxsysteme nur so lange # bis Veränderungen auf der Internetseite durchgeführt wurden ################################# # Die Download Seiten URL. export CALIBRE_DOWNLOAD_PAGE=http://calibre-ebook.com/download_linux # The location of the installed application. 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 ##### 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-autoupdater" 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 Calibre! autoupdater v$version" echo "Copyright (C) Leon Gaultier 2013-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 fi local IFS=. local i ver1=($1) ver2=($2) # fill empty fields in ver1 with zeros for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) do ver1[i]=0 done for ((i=0; i<${#ver1[@]}; i++)) do if [[ -z ${ver2[i]} ]] then # fill empty fields in ver2 with zeros ver2[i]=0 fi if ((10#${ver1[i]} > 10#${ver2[i]})) then return 1 fi if ((10#${ver1[i]} < 10#${ver2[i]})) then return 2 fi done return 0 } 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); do if [[ $(cat /sys/class/net/$INTERFACE/carrier) = 1 ]]; then ONLINE=1 fi done if [ $ONLINE ]; then echo -e "\033[32m Oh Wunder! Habe ein Netzwerk gefunden. Verbinde über Interface $INTERFACE, was nicht heißt das es geht :-P"; if [[ $stat_1 -eq 200 && $stat_2 -eq 200 ]]; then return 1 elif [[ $stat_1 -eq !200 ]]; then return 2 else return 3 fi else echo -e "\033[31m Fehler!!! Sieh Dir die verdammte Desktop Benachrichtigung an!"; return 4 fi } func_check_run_calibre () { CALIBRE_PID=`ps ax | grep /opt/calibre/bin/calibre | grep -v grep | awk '{printf $1}'` while [ $CALIBRE_PID ]; do $NOTIFY "Um das Update installieren zu können, muss Calibre beendet werden. Calibre wird in einer Minute vom Update Service beendet. !!!Bitte speichere alle wichtigen Daten!!!" sleep 3 for (( i=60; i>0; i-- )); do echo -e "\033[31m noch \033[32m>>$i<< \033[31m Sekunden bis zum Calibre Programmende" sleep 1 clear funct_term_output done kill -15 $CALIBRE_PID return 0 done return 0 } 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"; echo -e "\033[1;34m Hole Status Code von \"$CHECK_DOWNLOAD_URL\". Bitte warten."; stat_2=$(curl -o /dev/null --silent --head --write-out '%{http_code}' $CHECK_DOWNLOAD_URL) echo -e "\033[32m Status Codes von \"$CHECK_DOWNLOAD_URL\" erhalten"; return 0 } func_term_output () { ## Beginne mit der Ausgbe ## tty -s && clear echo -e "\033[44m \033[0m\033[1m $progname Version $version\033[0m\n\033[44m \033[0m 2013-2014 by Leon Gaultier\n"; return 0 } func_check_version () { #Ermitteln der letzten aktuell verfügbaren Version LATEST_VERSION=`curl -s $CALIBRE_DOWNLOAD_PAGE | grep 'latest release of calibre' | sed 's/[^0-9.]*\([1-9]*[0-9]\.[1-9]*[0-9]\).*/\1/'` #Ermitteln der aktuell installierten Version. CURRENT_VERSION=`calibre --version | sed 's/[^0-9.]*\([0-9.]*\).*/\1/'` 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" func_term_output func_http_status_code # Funktion hole einen http-status code func_check_stat # Funktion check Status Netzwerk und Downloadadressen case $? in 1) func_check_version func_vercomp $CURRENT_VERSION $LATEST_VERSION # Funktion Versionvergleich case $? in 0) $NOTIFY "Deine Calibre Version ist auf dem aktuellsten Stand ($CURRENT_VERSION).";; 1) $NOTIFY "Uh Oh! Deine Calibre Version ist aktueller wie die letzte Verfügbare! (Installiert: \"$CURRENT_VERSION\", Letzte Verfügbare: \"$LATEST_VERSION\")";; 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 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')" # $NOTIFY "Calibre wurde upgedatet." ;; esac ;; 2) $NOTIFY "Versionsvergleich fehlgeschlagen!!! Die Calibre Homepage \"$CHECK_CALIBRE_DOWNLOAD_PAGE\" ist nicht verfügbar!" ;; 3) $NOTIFY "Update fehlgeschlagen!!! Die Download Seite \"$CHECK_DOWNLOAD_URL\" ist nicht verfügbar!" ;; 4) $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