#!/bin/sh # # Script to export configuration files # Parameters: # $1: password used to decrypt the configuration file # $2: (optional) path where the configuration file is located. # If not gives it search for the first mounted SD card partition # Configuration HOME_TOOL=/home/tool IMPORTER=$HOME_TOOL/bin/7za TARGET_DIR=$HOME_TOOL/config # check importer if [ ! -e $IMPORTER ]; then echo "Importer not found" >&2 exit 1 fi # password check if [ $# -eq 0 ]; then echo "Password required" >&2 exit 1 fi PWD=$1 if [ "$PWD" = "" ]; then echo "No empty password" >&2 exit 1 fi ### if [ $# -eq 1 ]; then echo "Import file name required" >&2 exit 1 fi IMPORTFNAME=$2 if [ "$IMPORTFNAME" = "" ]; then echo "Empty import file name given" >&2 exit 1 fi CFG_FILE=$IMPORTFNAME ### if [ $# -gt 2 ]; then # use provided path INPUT_FILE=$3/$CFG_FILE else # use SD card # check SD BLOCK_LIST=$(find /sys/class/block/mmcblk* -maxdepth 0 2>/dev/null) if [ ! $? -eq 0 ]; then echo "No SD card" >&2 exit 1 fi # get SD mount path PART_LIST=$(find /sys/class/block/mmcblk*p* -maxdepth 0 2>/dev/null) if [ ! $? -eq 0 ]; then # No partitions DEV_PATH=$(find /sys/class/block/mmcblk* -maxdepth 0 | head -n 1) else # Partitions. get the first DEV_PATH=$(find /sys/class/block/mmcblk*p* -maxdepth 0 | head -n 1) fi SD_PATH=/mnt/mmc/$(basename $DEV_PATH) if [ ! -e $SD_PATH ];then echo "SD card not mounted" >&2 exit 1 fi if [ $IMPORTFNAME = "config.cfg" ]; then filenumber=`ls $SD_PATH/config/*.nxcfg | wc -l` if [ ! $filenumber -eq 1 ]; then echo "No or more than one *.nxcfg file found" >&2 exit 1 else CFG_FILE=`ls $SD_PATH/config/*.nxcfg` CFG_FILE=/config/`basename $CFG_FILE` fi fi INPUT_FILE=$SD_PATH/$CFG_FILE #BASE_INPUT_FILE=`basename $INPUT_FILE` #VERSION=`cat /etc/version` #if [[ 'false' == `/usr/local/bin/python -c "import sys, re; version = sys.argv[1]; filename = sys.argv[2]; p = re.compile('(.*)(-[0-9]{14,14}\.cfg)'); m = p.match(filename); print 'false' if m == None else 'true' if m.groups(0)[0] == version else 'false'" $VERSION $BASE_INPUT_FILE` ]]; then # echo "Wrong configuration version" >&2 # exit 1 #fi fi # check input file if [ ! -e $INPUT_FILE ]; then echo "Configuration file not found" >&2 exit 1 fi $IMPORTER t $INPUT_FILE -p$PWD > /dev/null RETVAL=$? if [ $RETVAL -eq 2 ];then echo "Wrong configuration version" >&2 exit 1 fi if [ $RETVAL -ne 0 ];then echo Failure exit $RETVAL fi #rdy system wegnehmen dbus-send --system --print-reply --dest=com.rexroth.akku.SysService /SysObj com.rexroth.akku.SysInterface.frdyflagreset int32:3 # CR12714: we do not want to delete any config files. #find $HOME_TOOL/config/* ! -path $HOME_TOOL/config/default/\* ! -name ChanCfg.json ! -name w1_backup -delete $IMPORTER x $INPUT_FILE -p$PWD -o$TARGET_DIR -x\!wlan/suppl -x\!default -x\!langs -x\!log -y > /tmp/sd_card_importer sync RETVAL=$? if [ $RETVAL -eq 0 ];then echo Success fi if [ $RETVAL -ne 0 ];then echo Failure fi exit $RETVAL