#!/bin/sh # # Script to export configuration files # Parameters: # $1: password used to encrypt the configuration file # $2: (optional) path where to save the configuration file. # If not gives it search for the first mounted SD card partition # set -u # Configuration EXPORTER=/home/tool/bin/7za #Exclude two files from backup FILE_LIST="-r /home/tool/config/* -x!.* -x!log -x!langs -x!ChanCfg.json -x!w1_backup -x!default -x!wlan/suppl" # check exporter if [ ! -e $EXPORTER ]; then echo "Exporter 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 "Export file name required" >&2 exit 1 fi EXPORTFNAME=$2 if [ "$EXPORTFNAME" = "" ]; then echo "Empty export file name given" >&2 exit 1 fi CFG_FILE=$EXPORTFNAME ### if [ $# -gt 2 ]; then # use provided path TARGET_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 TARGET_FILE=$SD_PATH/$CFG_FILE fi # remove previous archives DIR_NAME=`dirname $TARGET_FILE` CFG_FILES=`ls $DIR_NAME/*.nxcfg` rm -f $CFG_FILES $EXPORTER a -t7z -mx=1 $TARGET_FILE $FILE_LIST -p$PWD > /dev/null sync RETVAL=$? if [ $RETVAL -eq 0 ];then echo Success fi if [ $RETVAL -ne 0 ];then echo Failure fi exit $RETVAL