Funktionen in Headerfiles ausgelagert

This commit is contained in:
Leon Gaultier 2014-03-31 18:32:46 +02:00
parent e711220d21
commit 2b4aaedd58
4 changed files with 177 additions and 151 deletions

View File

@ -51,6 +51,8 @@
# Unterschiedliche Installationsart und -dialog je nach dem ob man Schreibrechte
# auf im Calibre Installationspfad hat oder nicht.
#
# v0.9 einbinden eines Konfigurationsfiles, auslagern einiger Funktionen in Headerfiles
#
# TODO auslesen der Download URL von der Download Seite
# kontrolle ob alle benötigten programme für das skript vorhanden sind
#
@ -58,6 +60,11 @@
######################################
######################################
# Programmversion
PROGNAME=`basename $0`
VERSION="0.8.99"
QUIET=0
#################################
@ -65,137 +72,19 @@
# 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
# externe Programme welche benötigt werden
CURL=/usr/bin/curl
NOTIFY=/usr/bin/notify-send
AWK=/usr/bin/awk
# Programmversion
PROGNAME=`basename $0`
VERSION="0.8"
QUIET=0
# Einlesen des Configfiles mit den Constanten für die Calibre Downloadseite und Hauptseite
source ./calibre-autoupdate.conf
#################################
##### Zusätzliche Funktionen #####
func_usage ()
{
echo "Usage: $PROGNAME [OPTION...]"
echo "Try '$PROGNAME --help' or '$PROGNAME -h' for more information."
}
./calibre-autoupdate.h
./calibre-autoupdate_checks.h
func_help ()
{
func_term_output
echo "Usage: $PROGNAME [OPTION...]"
echo "$PROGNAME -- the Calibre! Linux Edition calibre-autoupdater"
echo ""
echo "Options:"
echo " -q, --quiet ohne Konsolenausgabe"
echo " -h, --help zeigt die Hilfe an"
echo " -V, --version gibt die Programmversion aus"
echo " -c, --check checkt ob benötigte Programme vorhanden sind"
echo ""
echo -e "Report bugs to <leongaultier@gmail.com>.\n";
}
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.";
@ -214,36 +103,7 @@ func_term_output () {
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_prog () {
func_term_output
if test ! -f $CURL ; then
echo -e "\033[31mDu hast Curl nich installiert, es wird aber für die Updatefunktion benötigt\n"; >&2
exit 1
fi
if test ! -f $AWK ; then
echo -e "\033[31mDu hast AWK nich installiert, es wird aber für die Updatefunktion benötigt\n"; >&2
exit 1
if test ! -f $NOTIFY ; then
echo -e "\e[0;33mDu hast Notify-Send nich installiert, das Programm ist optional und wird"; >&2
echo -e "für die Upatefunktion nicht unbedingt benötigt\n"; >&2
sleep 10
fi
fi
echo -e "\033[32mAlle benötigten Programme sind installiert. Starte $PROGNAME ohne Optionen und"
echo -e "es wird nach einer aktuellen Calibre Version geschaut\n";
}
#######################################################
#######################################################
## main vom Script --- Start des Updater Skripts

21
calibre-autoupdate.conf Normal file
View File

@ -0,0 +1,21 @@
# Calibre Auto Updater Configfile
# Copyright (C) 2013-2014 Leon Gaultier
#
# Calibre Download Seite 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
# Calibre Hauptseite und Downloadseite
CHECK_CALIBRE_DOWNLOAD_PAGE=http://calibre-ebook.com
CHECK_DOWNLOAD_URL=https://github.com
# externe Programme welche benötigt werden
CURL=/usr/bin/curl
NOTIFY=/usr/bin/notify-send
AWK=/usr/bin/awk

65
calibre-autoupdate.h Normal file
View File

@ -0,0 +1,65 @@
# Calibre Auto Updater Configfile
# Copyright (C) 2013-2014 Leon Gaultier
#
func_usage ()
{
echo "Usage: $PROGNAME [OPTION...]"
echo "Try '$PROGNAME --help' or '$PROGNAME -h' for more information."
}
func_help ()
{
func_term_output
echo "Usage: $PROGNAME [OPTION...]"
echo "$PROGNAME -- the Calibre! Linux Edition calibre-autoupdater"
echo ""
echo "Options:"
echo " -q, --quiet ohne Konsolenausgabe"
echo " -h, --help zeigt die Hilfe an"
echo " -V, --version gibt die Programmversion aus"
echo " -c, --check checkt ob benötigte Programme vorhanden sind"
echo ""
echo -e "Report bugs to <leongaultier@gmail.com>.\n";
}
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
}

View File

@ -0,0 +1,80 @@
# Calibre Auto Updater Configfile
# Copyright (C) 2013-2014 Leon Gaultier
#
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_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_prog () {
func_term_output
if test ! -f $CURL ; then
echo -e "\033[31mDu hast Curl nich installiert, es wird aber für die Updatefunktion benötigt\n"; >&2
exit 1
fi
if test ! -f $AWK ; then
echo -e "\033[31mDu hast AWK nich installiert, es wird aber für die Updatefunktion benötigt\n"; >&2
exit 1
if test ! -f $NOTIFY ; then
echo -e "\e[0;33mDu hast Notify-Send nich installiert, das Programm ist optional und wird"; >&2
echo -e "für die Upatefunktion nicht unbedingt benötigt\n"; >&2
sleep 10
fi
fi
echo -e "\033[32mAlle benötigten Programme sind installiert. Starte $PROGNAME ohne Optionen und"
echo -e "es wird nach einer aktuellen Calibre Version geschaut\n";
}