From: wchang kim Date: Thu, 29 Aug 2024 22:20:22 +0000 (+0900) Subject: Changes for working in both bash and zsh X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c4989636aa7615d5430ebd2599ed03c64625a2c;p=tools%2Ftbb.git Changes for working in both bash and zsh Change-Id: Ic2e6fedfbb37ddf2ac7de6c83735975f98e4f008 --- diff --git a/support/scripts/sync_tizen2x.sh b/support/scripts/sync_tizen2x.sh index 875a10c..6f06664 100755 --- a/support/scripts/sync_tizen2x.sh +++ b/support/scripts/sync_tizen2x.sh @@ -1,4 +1,18 @@ -#!/bin/bash +#!/bin/zsh + +echo "detecting shell:" +if [[ -n ${ZSH_VERSION} ]] && [[ ! -z ${ZSH_VERSION} ]]; then + INDEX_START=1 + INDEX_OFFSET=0 + echo " using zsh $ZSH_VERSION, index starts at $INDEX_START" +elif [[ -n $BASH_VERSION ]]; then + INDEX_START=0 + INDEX_OFFSET=1 + echo " using bash $BASH_VERSION, index starts at $INDEX_START" +else + echo " unknown" + exit 1 +fi function printc(){ color=$1 @@ -65,13 +79,13 @@ function printc(){ REFERENCE_MODE=0 ADDITIONAL=0 -if [ $# == "1" ] +if [ $# = "1" ] then printc "lblue" "****************" printc "lblue" " reference mode" printc "lblue" "****************" REFERENCE_MODE=1 -elif [ $# == "2" -a $2 == "list" ] +elif [ $# = "2" -a $2 = "list" ] then REFERENCE_MODE=1 ADDITIONAL=1 @@ -86,11 +100,11 @@ fi TYPE=$1 -if [ $# == 3 ] +if [ $# = 3 ] then TIZEN_SNAPSHOT=$2 TIZENX_SNAPSHOT=$3 -elif [ $# == 4 -a x"$4" == x"list" ] +elif [ $# = 4 -a x"$4" = x"list" ] then ADDITIONAL=1 fi @@ -110,7 +124,7 @@ function download_tizen_reference_id(){ then rm -f tizen_build.xml fi - if [ $TYPE == "base" ] + if [ $TYPE = "base" ] then DOWNLOAD_T_URL="http://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Base/reference/build.xml" else @@ -136,7 +150,7 @@ function download_tizen_x_reference_id(){ then rm -f tizen_x_build.xml fi - if [ $TYPE == "base" ] + if [ $TYPE = "base" ] then DOWNLOAD_T_URL="http://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Base-X/reference/build.xml" else @@ -154,7 +168,7 @@ function download_tizen_x_reference_id(){ } function download_tizen_list(){ - if [ $TYPE == "base" ] + if [ $TYPE = "base" ] then DOWNLOAD_T_URL="http://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Base/tizen-base_${TIZEN_SNAPSHOT}/builddata/manifest/" DOWNLOAD_E_URL="" @@ -176,7 +190,7 @@ function download_tizen_list(){ fi printc "lgreen" "Making standard list..." - xmlstarlet sel -t -m "//project" -c "." -n ${T_FILE} | sed -e "s/.\+ path=\"\(.\+\)\" revision=\"\(.\+\)\".\+$/\1 \2/" > tizen_${TIZEN_SNAPSHOT}_standard.lst + xmlstarlet sel -t -m "//project" -c "." -n ${T_FILE} | sed -r -e 's|.* path="(.*)" revision="(.*)".*|\1 \2|' > tizen_${TIZEN_SNAPSHOT}_standard.lst if [ x"$E_FILE" != "x" ] then @@ -189,7 +203,7 @@ function download_tizen_list(){ fi printc "lgreen" "Making emulator list..." - xmlstarlet sel -t -m "//project" -c "." -n ${E_FILE} | sed -e "s/.\+ path=\"\(.\+\)\" revision=\"\(.\+\)\".\+$/\1 \2/" > tizen_${TIZEN_SNAPSHOT}_emulator.lst + xmlstarlet sel -t -m "//project" -c "." -n ${E_FILE} | sed -r -e 's|.* path="(.*)" revision="(.*)".*|\1 \2|' > tizen_${TIZEN_SNAPSHOT}_emulator.lst else echo -n "" > tizen_${TIZEN_SNAPSHOT}_emulator.lst fi @@ -203,7 +217,7 @@ function download_tizen_list(){ function download_tizenx_list(){ - if [ $TYPE == "base" ] + if [ $TYPE = "base" ] then DOWNLOAD_T_URL="http://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Base-X/tizen-base-x_${TIZENX_SNAPSHOT}/builddata/manifest/" DOWNLOAD_E_URL="" @@ -225,7 +239,7 @@ function download_tizenx_list(){ fi printc "lgreen" "Making standard list..." - xmlstarlet sel -t -m "//project" -c "." -n ${T_FILE} | sed -e "s/.\+ path=\"\(.\+\)\" revision=\"\(.\+\)\".\+$/\1 \2/" > tizenx_${TIZENX_SNAPSHOT}_standard.lst + xmlstarlet sel -t -m "//project" -c "." -n ${T_FILE} | sed -r -e 's|.* path="(.*)" revision="(.*)".*|\1 \2|' > tizenx_${TIZENX_SNAPSHOT}_standard.lst if [ x"$E_FILE" != "x" ] then @@ -238,7 +252,7 @@ function download_tizenx_list(){ fi printc "lgreen" "Making emulator list..." - xmlstarlet sel -t -m "//project" -c "." -n ${E_FILE} | sed -e "s/.\+ path=\"\(.\+\)\" revision=\"\(.\+\)\".\+$/\1 \2/" > tizenx_${TIZENX_SNAPSHOT}_emulator.lst + xmlstarlet sel -t -m "//project" -c "." -n ${E_FILE} | sed -r -e 's|.* path="(.*)" revision="(.*)".*|\1 \2|' > tizenx_${TIZENX_SNAPSHOT}_emulator.lst else echo -n "" > tizenx_${TIZENX_SNAPSHOT}_emulator.lst fi @@ -251,7 +265,7 @@ function download_tizenx_list(){ rm -f tizenx_${TIZENX_SNAPSHOT}_emulator.lst } -if [ $REFERENCE_MODE == 1 ] +if [ $REFERENCE_MODE = 1 ] then download_tizen_reference_id download_tizen_x_reference_id @@ -320,25 +334,31 @@ profile/iot/apps/native/ug-setting-homescreen-efl \ declare -A tizen_list declare -A tizenx_list -if [ $TYPE == "base" ] +if [ $TYPE = "base" ] then RESULT_FILE="result_base_T${TIZEN_SNAPSHOT}_X${TIZENX_SNAPSHOT}.txt" else RESULT_FILE="result_unified_T${TIZEN_SNAPSHOT}_X${TIZENX_SNAPSHOT}.txt" fi +if [ $INDEX_START = 1 ] +then +READ_OPT="-rA" +else +READ_OPT="-ra" +fi OIFS=$IFS IFS=' ' -while read -ra line +while read $READ_OPT line do - index=${line[0]} - tizen_list[$index]="${line[1]}" + index=${line[$INDEX_START]} + tizen_list[$index]="${line[2 - $INDEX_OFFSET]}" done < tizen_${TIZEN_SNAPSHOT}_merge.lst -while read -ra line +while read $READ_OPT line do - index=${line[0]} - tizenx_list[$index]=${line[1]} + index=${line[$INDEX_START]} + tizenx_list[$index]=${line[2 - $INDEX_OFFSET]} done < tizenx_${TIZENX_SNAPSHOT}_merge.lst IFS=$OIFS rm -f tizen_${TIZEN_SNAPSHOT}_merge.lst tizenx_${TIZENX_SNAPSHOT}_merge.lst @@ -347,7 +367,7 @@ printc "yellow" "tizen total : ${#tizen_list[@]}, x total : ${#tizenx_list[@]}" CHANGE_COUNT=0 -if [ $TYPE == "base" ] +if [ $TYPE = "base" ] then EXCEPT_LIST="$EXCEPT_BASE_LIST" else @@ -355,24 +375,31 @@ else fi echo "Tizen : ${TIZEN_SNAPSHOT} to X : ${TIZENX_SNAPSHOT}" > ${RESULT_FILE} -for key in ${!tizenx_list[@]} +if [ $INDEX_START = 1 ] +then + LOOP_LIST="${(@k)tizenx_list}" +else + LOOP_LIST=${!tizenx_list[@]} +fi + +for key in $( echo ${LOOP_LIST} ) do FLAG="false" - for item in $EXCEPT_LIST + for item in $( echo ${EXCEPT_LIST} ) do - if [ $item == $key ] + if [ $item = $key ] then FLAG="true" continue fi done - if [ $FLAG == "true" ] + if [ $FLAG = "true" ] then printc "orange" "EXCEPT $key" continue fi - if [ x"${tizen_list[$key]}" == "x" ] + if [ x"${tizen_list[$key]}" = "x" ] then printc "orange" "Not Found $key in tizen list" continue @@ -405,7 +432,7 @@ then exit 0 fi -if [ $TYPE == "base" ] +if [ $TYPE = "base" ] then RESULT_FILE_AF="result_base_T${TIZEN_SNAPSHOT}_additional_files.txt" else @@ -417,24 +444,31 @@ echo "Tizen : ${TIZEN_SNAPSHOT}" > ${RESULT_FILE_AF} CHANGE_COUNT=0 -for key in ${!tizen_list[@]} +if [ $INDEX_START = 1 ] +then + LOOP_LIST="${(@k)tizen_list}" +else + LOOP_LIST=${!tizen_list[@]} +fi + +for key in $( echo ${LOOP_LIST} ) do FLAG="false" - for item in $EXCEPT_LIST + for item in $( echo ${EXCEPT_LIST} ) do - if [ $item == $key ] + if [ $item = $key ] then FLAG="true" continue fi done - if [ $FLAG == "true" ] + if [ $FLAG = "true" ] then printc "orange" "EXCEPT $key" continue fi - if [ x"${tizenx_list[$key]}" == "x" ] + if [ x"${tizenx_list[$key]}" = "x" ] then let "CHANGE_COUNT++" echo "$key@${tizen_list[$key]}" >> ${RESULT_FILE_AF}