#!/bin/sh # --> 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 print_usage() { echo " $0 [options] Commands working with config file: -startjob run job based on --conf or --qpkg -stopjob stop job based on --conf or --qpkg Commands working with config file or standalone: -sendfile send specific file to server. -recvfile recv specific file from server. -senddir send specific dir to server. -recvdir recv specific dir from server. -sendlist send files listed in 'content_file' to server. -recvlist recv files listed in 'content_file' from server. Options: All options must be given in either a config file, or by keywords, All options have their own default value, if config file not exist or not given. * Given in config file: --qpkg use HBS QPKG's RR2 config, must be with job_id. --conf specify job's config file path, default is none (it means must be given by keywords) * Given by keywords (will overwrite the value in config file if given), the following are sorted by alphabet: --ip server ip address, default is 'localhhost', means local sync. --logdir specify log and statistics folder path, default will create 'logs' sub-dir under the current working dir. --port server port number. default is 8898. --pwd handler_login password (plain text), default is "". --uname handler_login user name. default is empty string, it means to use server's pwd, not NAS accout's pwd. --way run job by sequential/multi-threads/multi-proceses. it is only useful for folder-related operations. default is 'proc'. --waynum the number of threads or processes, If running by 'req', this value will be ignred. If running by 'thd', default value is 10. If running by 'proc', default avlue is -1, it means to auto-detect the number of processor. --debug print debug message on console Examples: Start a job with job_id: $0 -startjob --qpkg jid_001 Start a job with config: $0 -startjob --conf \"/share/Public/testrr2/job.json\" " exit 1 } # --> decide if print debug DEBUG=0 for arg in $* do if [ $arg == "--debug" ]; then DEBUG=1 echo "*** DEBUG MODE" echo "*** SCRIPT_DIR=$SCRIPT_DIR" break fi done # --> check if arguments are valid # if [ $# -eq 0 ]; then # print_usage # fi # --> decide target py file SCRIPT_ROOT="$SCRIPT_DIR/.." BIN_PY_FILE=rr2c_cli.py BIN_PY_PATH="$SCRIPT_ROOT/bin/{$BIN_PY_FILE}c" 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 } # --> reset BIN_PY_PATH set_script_bin if [ $DEBUG -eq 1 ]; then echo "*** SCRIPT_ROOT=$SCRIPT_ROOT" echo "*** BIN_PY_PATH=$BIN_PY_PATH" python3 --version echo "*** python3 $BIN_PY_PATH $@" fi # --> decide RR2_TOOL_PY python3 $BIN_PY_PATH "$@" exit 0