#!/bin/sh # # Script to extract configuration archive files # Parameters: # $1: password. # $2: import file name. # $3: (optional) path where the configuration file is located, # when missing, path is the SD card. # Configuration 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 ###we have no parameters at all if [ $# -eq 0 ]; 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 INPUT_FILE=$SD_PATH/$CFG_FILE 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 $IMPORTER l $INPUT_FILE sync RETVAL=$? if [ $RETVAL -eq 0 ];then echo Success fi if [ $RETVAL -ne 0 ];then echo Failure fi exit $RETVAL