#!/bin/sh # # Script to import configuration files with exclude list # Parameters: # $1: password used to decrypt the configuration file # $2: list of files to be excluded when expanded. # $3: (optional) path where the configuration file is located. # If not gives it search for the first mounted SD card partition # Configuration # set -x -u IMPORTER=/home/tool/bin/7za TARGET_DIR=/home/tool/config # check importer if [ ! -e $IMPORTER ]; then echo "Importer not found" >&2 exit 1 fi echo $# # 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 [ $# -lt 2 ]; then echo "Exclude list required" >&2 exit 1 fi XFILELIST=$2 if [ $# -lt 3 ]; then echo "Import file name required" >&2 exit 1 fi IMPORTFNAME=$3 if [ "$IMPORTFNAME" = "" ]; then echo "Empty import file name given" >&2 exit 1 fi CFG_FILE=$IMPORTFNAME ### if [ $# -gt 3 ]; then # use provided path INPUT_FILE=$4/$CFG_FILE XFILELIST_PATH=$4/$XFILELIST 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 XFILELIST_PATH=$XFILELIST 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 echo $TARGET_DIR echo $INPUT_FILE echo $XFILELIST_PATH echo "--now run...." $IMPORTER x $INPUT_FILE -p"$PWD" -o$TARGET_DIR -x@$XFILELIST_PATH -x\!wlan/suppl -x\!default -x\!langs -x\!log -y > /dev/null sync RETVAL=$? if [ $RETVAL -eq 0 ];then echo Success fi if [ $RETVAL -ne 0 ];then echo Failure fi exit $RETVAL