From 33c4b9a7c0db933fc33aa877a59991390051b57e Mon Sep 17 00:00:00 2001 From: agibert Date: Sat, 11 Apr 2009 22:57:02 +0000 Subject: [PATCH] - Add -i (--repo_in), -o (--repo_out), -j (--jobs) and -c (--compressor) options, - Add initial info print out, - slight code cleanup. --- nds2rm | 295 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 158 insertions(+), 137 deletions(-) diff --git a/nds2rm b/nds2rm index be86512..97fcb24 100644 --- a/nds2rm +++ b/nds2rm @@ -5,9 +5,9 @@ # (C) 2009 Arnaud G. Gibert #----------------------------------------------------------------------------------------------------------------------------------- # $RCSfile: nds2rm,v $ -# $Revision: 1.13 $ +# $Revision: 1.14 $ # $Name: $ -# $Date: 2009/04/11 21:12:28 $ +# $Date: 2009/04/11 22:57:02 $ # $Author: agibert $ #----------------------------------------------------------------------------------------------------------------------------------- @@ -31,33 +31,6 @@ -# User Config -#----------------------------------------------------------------------------------------------------------------------------------- - -# Path Config -#NDS_REPOSITORY_IN=/opt/public/nds -NDS_REPOSITORY_IN=/opt/public/nds.new -#NDS_REPOSITORY_IN=/opt/public/nds.new/nds.old -#NDS_REPOSITORY_IN=/opt/public/nds.new/nds.new -NDS_REPOSITORY_OUT=/opt/public/nds.new -#NDS_REPOSITORY_OUT=/opt/public/nds.new/nds.new -NDS_ROMS_IN=${NDS_REPOSITORY_IN}/roms -NDS_ROMS_OUT=${NDS_REPOSITORY_OUT}/roms -NDS_XML=${NDS_REPOSITORY_IN}/misc/dsrom.xml - -# Job Parallelisation -JOB_NB=8 - -# Compressor (zip, rar or 7z) -#COMPRESSOR=zip -#COMPRESSOR=rar -COMPRESSOR=7z - - - - - - # System Constants #----------------------------------------------------------------------------------------------------------------------------------- @@ -65,30 +38,9 @@ STATS_FILE="stats.txt" TMP_DIR=$(mktemp -d) -case "${COMPRESSOR}" -in - (zip) - CSFX=zip - ;; - - (rar) - CSFX=rar - ;; - - (7z) - CSFX=7z - ;; - - (*) - echo "Error: unsuported compressor: ${COMPRESSOR} !" - exit 1 - ;; -esac - NDS_VERSION="$Name: $" -RNFH_REGEX=".... - .* \(.*:.*\) \[..\] \{........} <....>[-]*[0-9]*\.${CSFX}$" - +# Region Table reg_tab[0]="E"; # Europe reg_tab[1]="U"; # USA reg_tab[2]="G"; # Germany @@ -119,6 +71,7 @@ RNFH_REGEX=".... - .* \(.*:.*\) \[..\] \{........} <....>[-]*[0-9]*\.${CSFX}$" reg_tab[27]="R"; # Russia reg_tab[28]="Gr"; # Greece +# Language Table lang_tab[1]="Fr"; # French lang_tab[2]="En"; # English lang_tab[4]="Zh"; # Chinese @@ -162,19 +115,30 @@ function version_print() function help_print() { - echo "-C|--correct: output repository will be corrected" - echo "-T|--test: input repository will be tested (default)" - echo "-D|--dsrom: dsrom.lst will be dumped" - echo "-h|--help: print this help and exit" - echo "-V|--version: print the version and exit" - echo "-r|--rebuild: don't trust archive file name (test & correct mode)" - echo " rebuild archives (correct mode)" - echo "-m|--max : maximum rom id to load from dat file" - echo "-n|--renum: try to renumber archives" - echo " --list_ok: list roms with ok status" - echo " --list_ko: list roms with ko status" - echo " --list_miss: list missing roms" - echo "-v|--verbose: switch on verbosity" + echo "Path options:" + echo "-i | --repo_in : input repository path (default: ${nds_repository_in})" + echo "-o | --repo_out : output repository path (default: ${nds_repository_out})" + echo "" + echo "Mode selection" + echo "-C | --correct: corect output repository" + echo "-T | --test: test input repository (default mode)" + echo "-D | --dsrom: dsrom.lst will be dumped" + echo "-h | --help: print this help and exit" + echo "-V | --version: print the version and exit" + echo "" + echo "Global options" + echo "-m | --max : maximum rom id to load from dat file (default: ${max_idx})" + echo "-v | --verbose: switch on verbosity" + echo "-c | --compressor : set archive compressor (zip, rar or 7z) (default: ${compressor})" + echo "" + echo "Test and Correct Mode options:" + echo "-j | --jobs : nuber of parallel jobs to run (default: ${job_nb})" + echo "-r | --rebuild: don't trust archive file name (test & correct mode)" + echo " rebuild archives (correct mode)" + echo "-n | --renum: try to renumber archives" + echo " --list_ok: list roms with ok status" + echo " --list_ko: list roms with ko status" + echo " --list_miss: list missing roms" } @@ -186,17 +150,21 @@ function help_print() function args_parse() { - mode="test" - rebuild="no" - renum="no" - lok="no" - lko="no" - lmiss="no" - verbose="no" - max_idx=9999 + nds_repository_in="/opt/public/nds" + nds_repository_out="/opt/public/nds" + mode="test" + verbose="no" + max_idx=9999 + compressor="7z" + job_nb=1 + rebuild="no" + renum="no" + lok="no" + lko="no" + lmiss="no" - tmp_args=$(getopt -o CTDhVrm:nv --long correct,test,dsrom,help,version,rebuild,max:,renum,list_ok,list_ko,list_miss,verbose -n 'nds_rom_mng' -- "$@") + tmp_args=$(getopt -o i:o:CTDhVm:vc:j:rn --long repo_in,repo_out,correct,test,dsrom,help,version,max:,verbose,compressor:,jobs:,rebuild,renum,list_ok,list_ko,list_miss -n 'nds_simple_rom_mng' -- "$@") if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi @@ -205,19 +173,32 @@ function args_parse() while true ; do case "$1" in - -C|--correct) mode="correct"; shift;; - -T|--test) mode="test"; shift;; - -D|--dsrom) mode="dsrom"; shift;; - -h|--help) mode="exit"; help_print; shift;; - -V|--version) mode="exit"; version_print; shift;; - -r|--rebuild) rebuild="yes"; shift;; - -m|--max) shift; max_idx="$1"; shift;; - -n|--renum) renum="yes"; shift;; - --list_ok) lok="yes"; shift;; - --list_ko) lko="yes"; shift;; - --list_miss) lmiss="yes"; shift;; - -v|--verbose) verbose="yes"; shift;; - --) shift; break;; + # Path options + -i|--repo_in) shift; nds_repository_in="$1"; shift;; + -o|--repo_out) shift; nds_repository_out="$1"; shift;; + + # Mode switches + -C|--correct) mode="correct"; shift;; + -T|--test) mode="test"; shift;; + -D|--dsrom) mode="dsrom"; shift;; + -h|--help) mode="exit"; help_print; shift;; + -V|--version) mode="exit"; version_print; shift;; + + # Global options + -m|--max) shift; max_idx="$1"; shift;; + -v|--verbose) verbose="yes"; shift;; + -c|--compressor) shift; compressor="$1"; shift;; + + # T & C options + -j|--jobs) shift; job_nb="$1"; shift;; + -r|--rebuild) rebuild="yes"; shift;; + -n|--renum) renum="yes"; shift;; + --list_ok) lok="yes"; shift;; + --list_ko) lko="yes"; shift;; + --list_miss) lmiss="yes"; shift;; + + # + --) shift; break;; *) echo "args_parse internal error [$1] !"; exit 1;; esac done @@ -227,6 +208,56 @@ function args_parse() +# Setup Environment +#----------------------------------------------------------------------------------------------------------------------------------- + +function env_setup() +{ + if [[ ${nds_repository_in} == ${nds_repository_out} ]] + then + in_place=yes + else + in_place=no + fi + + # Path Config + nds_roms_in=${nds_repository_in}/roms + nds_roms_out=${nds_repository_out}/roms + nds_xml=${nds_repository_in}/misc/dsrom.xml + + if [[ ! -f ${nds_xml} ]] + then + echo "error: dsrom.xml not found !" 1>&2 + exit 1 + fi + + case "${compressor}" + in + (zip) + csfx=zip + ;; + + (rar) + csfx=rar + ;; + + (7z) + csfx=7z + ;; + + (*) + echo "Error: unsuported compressor: ${compressor} !" + exit 1 + ;; + esac + + rnfh_regex=".... - .* \(.*:.*\) \[..\] \{........} <....>[-]*[0-9]*\.${csfx}$" +} + + + + + # Print Counter #----------------------------------------------------------------------------------------------------------------------------------- @@ -368,7 +399,7 @@ function xml_load() ;; esac fi - done < ${NDS_XML} + done < ${nds_xml} } @@ -382,7 +413,7 @@ function job_init() { job_id=0 - while [[ ${job_id} -lt ${JOB_NB} ]] + while [[ ${job_id} -lt ${job_nb} ]] do job_pid[${job_id}]="0" job_dir[${job_id}]="${TMP_DIR}/nds2rom-$$-${job_id}" @@ -405,7 +436,7 @@ function job_deinit() { job_id=0 - while [[ ${job_id} -lt ${JOB_NB} ]] + while [[ ${job_id} -lt ${job_nb} ]] do rm -R "${job_dir[${job_id}]}" @@ -424,7 +455,7 @@ function job_switch() { job_id=$((${job_id} + 1)) - if [[ ${job_id} -ge ${JOB_NB} ]] + if [[ ${job_id} -ge ${job_nb} ]] then job_id=0 fi @@ -660,33 +691,33 @@ function arc_build() then print_verbose "removing ${file}" - \rm -f "${NDS_ROMS_IN}/${file}" + \rm -f "${nds_roms_in}/${file}" fi - case "${COMPRESSOR}" + case "${compressor}" in (zip) print_verbose "zipping ${rom} into ${file_name}" - zip -m9 "${NDS_ROMS_OUT}/${file_name}" "${rom}" >/dev/null 2>&1 + zip -m9 "${nds_roms_out}/${file_name}" "${rom}" >/dev/null 2>&1 ;; (rar) print_verbose "raring ${rom} into ${file_name}" - rar m -m5 "${NDS_ROMS_OUT}/${file_name}" "${rom}" >/dev/null 2>&1 + rar m -m5 "${nds_roms_out}/${file_name}" "${rom}" >/dev/null 2>&1 ;; (7z) print_verbose "7zipping ${rom} into ${file_name}" - 7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -bd "${NDS_ROMS_OUT}/${file_name}" "${rom}" >/dev/null 2>&1 + 7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -bd "${nds_roms_out}/${file_name}" "${rom}" >/dev/null 2>&1 \rm -f "${rom}" ;; (*) - echo "arc_build internal error [$COMPRESSOR] !" 1>&2 + echo "arc_build internal error [$compressor] !" 1>&2 exit 1 ;; esac @@ -720,11 +751,11 @@ function arc_rename() then print_verbose "moving ${file} to ${file_name}" - mv "${NDS_ROMS_IN}/${file}" "${NDS_ROMS_OUT}/${file_name}" + mv "${nds_roms_in}/${file}" "${nds_roms_out}/${file_name}" else print_verbose "copying ${file} to ${file_name}" - cp "${NDS_ROMS_IN}/${file}" "${NDS_ROMS_OUT}/${file_name}" + cp "${nds_roms_in}/${file}" "${nds_roms_out}/${file_name}" fi # fi fi @@ -770,25 +801,25 @@ function rom_extract() (*.nds) print_verbose "copying ${file} to ${rom}" - cp "${NDS_ROMS_IN}/${file}" "${rom}" + cp "${nds_roms_in}/${file}" "${rom}" ;; (*.rar) print_verbose "extracting ${rom} from ${file}" - unrar p -inul "${NDS_ROMS_IN}/${file}" > "${rom}" + unrar p -inul "${nds_roms_in}/${file}" > "${rom}" ;; (*.7z) print_verbose "extracting ${rom} from ${file}" - 7z x -so "${NDS_ROMS_IN}/${file}" > "${rom}" 2>/dev/null + 7z x -so "${nds_roms_in}/${file}" > "${rom}" 2>/dev/null ;; (*.zip) print_verbose "extracting ${rom} from ${file}" - unzip -p "${NDS_ROMS_IN}/${file}" > "${rom}" + unzip -p "${nds_roms_in}/${file}" > "${rom}" ;; (*) @@ -812,11 +843,11 @@ function tmp_mv() IFS=' ' mv_cnt=0 - for file_src in ${NDS_ROMS_OUT}/*.tmp + for file_src in ${nds_roms_out}/*.tmp do - if [[ "${file_src}" != "${NDS_ROMS_OUT}/*.tmp" ]] + if [[ "${file_src}" != "${nds_roms_out}/*.tmp" ]] then - file_trg=${file_src/.${CSFX}.tmp/.${CSFX}} + file_trg=${file_src/.${csfx}.tmp/.${csfx}} print_verbose "move ${file_src} to ${file_trg}" @@ -846,7 +877,7 @@ function arc_ident() # Type of archive ? - if [[ ${file} =~ ${RNFH_REGEX} ]] + if [[ ${file} =~ ${rnfh_regex} ]] then eval ${arc_type_ptr}="rx3" else @@ -1051,7 +1082,7 @@ function arc_mng() tmp_file=$(mktemp) - ls ${NDS_ROMS_IN} > ${tmp_file} + ls ${nds_roms_in} > ${tmp_file} while read file do @@ -1116,7 +1147,7 @@ function suffix_mng() tmp_file=$(mktemp) - ls ${NDS_ROMS_OUT} > ${tmp_file} + ls ${nds_roms_out} > ${tmp_file} while read file do @@ -1144,7 +1175,7 @@ function suffix_mng() idx_old=${idx} status_old=${status} dup_id=0 - file_name="${file/) \[*/}) [${status}] {${crc}} <${fp}>.${CSFX}" + file_name="${file/) \[*/}) [${status}] {${crc}} <${fp}>.${csfx}" dat_fp[${idx}]="${fp}" dat_status[${idx}]="${status}" @@ -1157,7 +1188,7 @@ function suffix_mng() # Duplicate rom dup_id=$((${dup_id} + 1)) - file_name="${file/) \[*/}) [${status}] {${crc}} <${fp}>-${dup_id}.${CSFX}" + file_name="${file/) \[*/}) [${status}] {${crc}} <${fp}>-${dup_id}.${csfx}" dup_cnt=$((${dup_cnt} + 1)) @@ -1170,7 +1201,7 @@ function suffix_mng() fi print_verbose "moving ${file} to ${file_name}" - arc_mv "${NDS_ROMS_OUT}/${file_name}" "${NDS_ROMS_OUT}/${file}" "${mode}" + arc_mv "${nds_roms_out}/${file_name}" "${nds_roms_out}/${file}" "${mode}" fi found_cnt=$((${found_cnt} + 1)) @@ -1365,7 +1396,7 @@ function fp_scan() tmp_file=$(mktemp) - ls ${NDS_ROMS_IN} > ${tmp_file} + ls ${nds_roms_in} > ${tmp_file} while read file do @@ -1388,7 +1419,7 @@ function fp_scan() # Type of archive ? - if [[ ${file} =~ ${RNFH_REGEX} ]] + if [[ ${file} =~ ${rnfh_regex} ]] then fp=${file/*\} \*/} status=${file/* \[/}; status=${status/\] \{*/} @@ -1440,9 +1471,9 @@ function test_correct_mode() { if [[ ${in_place} == "yes" ]] then - file_suffix=".${CSFX}.tmp" + file_suffix=".${csfx}.tmp" else - file_suffix=".${CSFX}" + file_suffix=".${csfx}" fi # Remove .tmp suffix @@ -1492,16 +1523,6 @@ function test_correct_mode() cd ${TMP_DIR} -# Initialise stats variables - -# ok_cnt=0 -# ko_cnt=0 -# found_cnt=0 -#missing_cnt=0 -# renum_cnt=0 - - - shopt -s extglob args_parse "$@" @@ -1511,24 +1532,24 @@ then exit 0 fi -if [[ ${NDS_REPOSITORY_IN} == ${NDS_REPOSITORY_OUT} ]] -then - in_place=yes -else - in_place=no -fi +env_setup -if [[ ! -f ${NDS_XML} ]] -then - echo "error: dsrom.xml not found !" 1>&2 - exit 1 -fi +case "${mode}" +in + (dsrom): + echo "mode: [${mode}] repository: [${nds_repository_in}] max idx: (${max_idx}) compressor: [${compressor}]" 1>&2 + ;; + + (test|correct): + echo "mode: [${mode}] repository in: [${nds_repository_in}] repository out: [${nds_repository_out}]" 1>&2 + echo "max idx: (${max_idx}) compressor: [${compressor}] rebuild: [${rebuild}] renum: [${renum}] jobs: (${job_nb})" 1>&2 + ;; +esac #----------------------------------------------------------------------------------------------------------------------------------- -#dat_load xml_load