#!/bin/sh #------------------------------------------------------------------------------ # /var/install/bin/carddav2fb-force-update - force update of FRITZ!Box # address book # # Copyright (c) 2015-2020 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2015-04-11 jed # Last Update: $Id$ # # Usage: # # 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 2 of the License, or # (at your option) any later version. #------------------------------------------------------------------------------ # read eislib . /var/install/include/eislib pgmname=`basename $0` module_name="`echo "${pgmname}" | cut -d- -f1 | cut -d. -f1`" # debug mode true/false #debug=true if ${debug:-false} then exec 2> /tmp/${pgmname}-trace$$.log set -x ask_debug=true export ask_debug fi #============================================================================== # main #============================================================================== configfile=/etc/config.d/${module_name} carddav2fb_runpath=/var/lib/${module_name} carddav2fb_bin=/usr/lib/${module_name}/${module_name} carddav2fb_config="${carddav2fb_runpath}/config`echo "${module_name}" | sed -r 's/^.{7}//'`.php" logfile=/var/log/${module_name}-force-output-trace.log title_str='Force manual FRITZ!Box update' cmd='' noconfirm=false tmp_vcf_file='' tmp_xml_file='' if [ $# -gt 0 ] then # read parameter(s) while [ $# -gt 0 ] do case $1 in *-noconfirm ) noconfirm=true shift ;; *-vcffile ) if [ ! -f "$2" ] then tmp_vcf_file="$2" fi shift; shift ;; *-xmlfile ) if [ ! -f "$2" ] then tmp_xml_file="$2" fi shift; shift ;; background-image|download|convert|upload|run ) cmd="$1" shift ;; *-help|*-?|/? ) echo echo "Usage:" echo " ${pgmname} CMD [--noconfirm][--quiet|--verbose] [--vcffile FILE][--xmlfile FILE]" echo echo ' Commands (CMD):' echo ' background-image - generate/upload of background image from quick dial numbers' echo ' download - load data from CardDAV server and save it as vCard file (VCF)' echo ' convert - convert vCard file (VCF) to file in FritzBox format (XML)' echo ' upload - upload file in FritzBox format (XML) to FRITZ!Box' echo ' run - download, convert and upload - all in one go' echo echo ' Options:' echo ' --noconfirm - disable all interaction' echo ' --vcffile FILE - custom VCF file in which downloaded data will be stored.' echo ' --xmlfile FILE - custom XML file which will be upload to FRITZ!Box' echo exit 0 ;; * ) shift ;; esac done fi if [ -f ${configfile} ] then . ${configfile} if [ "${START_CARDDAV2FB}" = 'yes' ] then # be verbose by default carddav2fb_options='-vvv' if [ "${noconfirm}" = 'true' ] then # set interaction mode carddav2fb_options="${carddav2fb_options} --no-interaction" fi # check if custom vcf files exist which should be imported too for VCF in `find ${carddav2fb_runpath} -maxdepth 1 -name "*\.vcf" | grep "^${carddav2fb_runpath}/custom-"` do if [ -s ${VCF} ] then carddav2fb_options="${carddav2fb_options} --local=${VCF}" fi done # bgimage - generate an upload of a background image from quick dial numbers # download - load data from CardDAV server and save it as vCard file (VCF) # convert - convert vCard file (VCF) to file in FritzBox format (XML) # upload - upload file in FritzBox format (XML) to FRITZ!Box # run - download, convert and upload - all in one go if [ -z "${cmd}" ] then # set default command cmd='run' fi if [ "${cmd}" = 'download' -o "${cmd}" = 'convert' -o "${cmd}" = 'run' ] then carddav2fb_options="${carddav2fb_options} --image" fi if [ "${cmd}" = 'download' -o "${cmd}" = 'convert' ] then if [ -n "${tmp_vcf_file}" ] then carddav2fb_options="${carddav2fb_options} ${tmp_vcf_file}" else carddav2fb_options="${carddav2fb_options} ${carddav2fb_runpath}/${module_name}-download.vcf" fi fi if [ "${cmd}" = 'convert' -o "${cmd}" = 'upload' ] then if [ -n "${tmp_xml_file}" ] then carddav2fb_options="${carddav2fb_options} ${tmp_xml_file}" else carddav2fb_options="${carddav2fb_options} ${carddav2fb_runpath}/${module_name}-convert.xml" fi fi # create empty output file echo > ${logfile} echo "command: ${carddav2fb_bin} ${cmd} --config=${carddav2fb_config} ${carddav2fb_options}" >> ${logfile} echo >> ${logfile} ### run command ### ${carddav2fb_bin} ${cmd} --config=${carddav2fb_config} ${carddav2fb_options} 2>> ${logfile} >> ${logfile} & # show output if [ -s ${logfile} ] then # check if show-doc.cui supports colors color='' frame='' if $(grep -qE "^MENU=['\"]/var/install/bin/show-menu['\"]" /etc/config.d/setup) then color='--nocolor' frame='--noframe' fi /var/install/bin/show-doc.cui ${color} ${frame} --follow --title "${title_str}" ${logfile} fi rm -f ${logfile} else mecho --error "Configuration file '${configfile}' doesn't exist!" fi fi exit 0