#!/bin/bash # --> get the dir of this script SOURCE="${BASH_SOURCE[0]}" # resolve $SOURCE until the file is no longer a symlink while [ -h "$SOURCE" ]; do DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )" SOURCE="$(readlink "$SOURCE")" [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it # relative to the path where the symlink file was located done SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )" # --> set python3 env . $SCRIPT_DIR/set_py3_env.sh > /dev/null 2>&1 function set_script_bin() { if [ -e "$HBS_INST_PATH/rr2/bin/${BIN_PY_FILE}c" ] || [ -e "$HBS_INST_PATH/rr2/bin/$BIN_PY_FILE" ]; then SCRIPT_ROOT="$HBS_INST_PATH/rr2" else SCRIPT_ROOT="$SCRIPT_DIR/.." fi if [ -e "$SCRIPT_ROOT/bin/${BIN_PY_FILE}c" ]; then BIN_PY_PATH="$SCRIPT_ROOT/bin/${BIN_PY_FILE}c" else BIN_PY_PATH="$SCRIPT_ROOT/bin/$BIN_PY_FILE" fi } # --> check if arguments are valid DEBUG=0 DEBUG_STR= for arg in $* do if [ $arg == "--debug" ]; then DEBUG=1 echo "*** DEBUG MODE" echo "*** SCRIPT_DIR=$SCRIPT_DIR" DEBUG_STR=--debug set -x break fi done if [ $DEBUG -eq 1 ]; then set -x fi # --> update HBS qpkg rr2 file if needed if [[ SCRIPT_DIR = *".qpkg/HybridBackup"* ]]; then : else if [ $DEBUG -eq 1 ]; then $SCRIPT_DIR/../test/common/update_src/update_local_qpkg.sh else $SCRIPT_DIR/../test/common/update_src/update_local_qpkg.sh > /dev/null 2>&1 fi fi # --> decide BIN_PY_PATH SCRIPT_ROOT="$SCRIPT_DIR/.." BIN_PY_FILE=rr2_tool.py BIN_PY_PATH="$SCRIPT_ROOT/bin/${BIN_PY_FILE}c" set_script_bin if [ $DEBUG -eq 1 ]; then python3 --version fi # --> for bug: https://qnap-jira.qnap.com.tw/browse/QTSHBS00-1355 # ArgParser cannot handle two values in an argument containing '-', # so we change two values to one value here (ignore the 2nd value since # it can be replaced with default value anyway). # --> check if arguments are valid RAN=0 for arg in $* do if [[ $arg == "-encstrfw" ]]; then python3 $BIN_PY_PATH -encstrfw="$2" --enctype="$3" $DEBUG_STR RAN=1 break fi if [[ $arg == "-decstrfw" ]]; then python3 $BIN_PY_PATH -decstrfw="$2" --enctype="$3" $DEBUG_STR RAN=1 break fi done # --> decide RR2_TOOL_PY if [ $RAN -eq 1 ]; then : else python3 $BIN_PY_PATH "$@" fi # case "$1" in # enc_pwd) # if [ $# -ne 2 ]; then # print_usage # fi # echo "python3 $BIN_PY_PATH -encb64 $2" # python3 $BIN_PY_PATH -encb64 $2 # ;; # dec_pwd) # if [ $# -ne 2 ]; then # print_usage # fi # echo "python3 $BIN_PY_PATH -decb64 $2" # python3 $BIN_PY_PATH -decb64 $2 # ;; # *) # print_usage # esac if [ $DEBUG -eq 1 ]; then set +x fi exit 0