From 5fd512c465466320818f8a0c2513a67fdffa9b7e Mon Sep 17 00:00:00 2001 From: waynemowdirect Date: Thu, 30 Apr 2015 17:44:00 +0100 Subject: [PATCH 1/2] Altering the whitespace to match main repro style --- modman | 192 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/modman b/modman index 7303e9d..1c8b119 100755 --- a/modman +++ b/modman @@ -37,9 +37,9 @@ Global Commands: deploy-all deploy all modules (no VCS interaction) repair rebuild all modman-created symlinks (no updates performed) clean clean up broken symlinks (run this after deleting a module) - automodman loops through module directory: - - asks to include files & directories in new modman file - - does not create symlinks + automodman loops through module directory: + - asks to include files & directories in new modman file + - does not create symlinks --help display this help message --tutorial show a brief tutorial on using modman --version display the modman script's version @@ -606,98 +606,98 @@ apply_path () # Automatically create a modman file run_automodman () #"$module" "$mm" "$wc_dir" "$wc_desc" { - # returns 0 on success 1 on error - amodule=$1 - amm=$2 - awc_dir=$3 - awc_desc=$4 - - #echo "building modman file for $amodule" - #echo "in base directory $amm" - #echo "in working copy $awc_dir" - #echo "modman file will be or is $awc_desc" - - #does the modman file exist? - #yes - if [ -r "$awc_desc" ]; then - echo "$awc_desc file already exists" - return 0 #exit without error - - #no - else - #touch modman - echo "creating modman file for $amodule" - touch $awc_desc - fi - #loop through files - declare -a incpaths - - for f in $(find $awc_dir \( ! -iname 'modman' ! -regex "$awc_dir.*/\..*" \)) #ignore hidden files and modman - do - #strip path down - alngth=${#awc_dir} #length of working directory to remove from path - alngth=$((alngth+1)) #increase by one to account for the fact we added a slash - pathname=${f:$alngth} - - #first f tends to be empty because of our stripping the path down so test for it -n is default operator - if [ "$pathname" ]; then - - prevmatch=0 - #todo: possibly there is a neater way to do this without a loop?? - for incPath in "${incpaths[@]}" #loop through incpaths - do - if [[ "$pathname" != "${pathname/$incPath/}" ]]; then - prevmatch=1 - fi - done - - #if substring then do recurse - if [[ $prevmatch -eq 0 ]]; then #make sure we have not previously matched - - #pre-existing path: yes | no? - if grep -rq "^[^#].*\s$pathname$" "${amm}/"*"/modman" #target is what is important so find end line not beginning line - then #pre-existing path: yes - echo "..." - echo "A path was found that exists in below modman description file" #error - grep -r --color=always "\s$pathname$" "${amm}/"*"/modman" - echo "It is therefore presently illegal for it to be included in this module." - echo "..." - if [[ -d $f ]]; then - incpaths+=("$pathname") - fi - read -p "press enter to continue..." goonthen - else #pre-existing path: no - - read -p "include '$pathname': [N][y]" include #include path: yes | no? - if [[ "$include" == "" ]]; then - include="N" - fi - - if [[ ${include,,} == "y" ]]; then #include path: yes - - echo "..." - echo "You answered y:yes modman will include the path" - echo "..." - - #write path to modman - echo "$pathname $pathname" >> $awc_desc #substring ${var:start} - #was it a directory or file - if [[ -d $f ]]; then - incpaths+=("$pathname") - fi - - elif [[ ${include^^} == "N" ]]; then #include path: no - echo "You answered N:no, modman is not including the path" - else - echo "Warning: you answered $include which is invalid, modman is not including path" - fi - - fi # test other modules for pre-existing path - fi # test prvious match - fi #continue - done #no more paths - #return success - return 0 + # returns 0 on success 1 on error + amodule=$1 + amm=$2 + awc_dir=$3 + awc_desc=$4 + + #echo "building modman file for $amodule" + #echo "in base directory $amm" + #echo "in working copy $awc_dir" + #echo "modman file will be or is $awc_desc" + + #does the modman file exist? + #yes + if [ -r "$awc_desc" ]; then + echo "$awc_desc file already exists" + return 0 #exit without error + + #no + else + #touch modman + echo "creating modman file for $amodule" + touch $awc_desc + fi + #loop through files + declare -a incpaths + + for f in $(find $awc_dir \( ! -iname 'modman' ! -regex "$awc_dir.*/\..*" \)) #ignore hidden files and modman + do + #strip path down + alngth=${#awc_dir} #length of working directory to remove from path + alngth=$((alngth+1)) #increase by one to account for the fact we added a slash + pathname=${f:$alngth} + + #first f tends to be empty because of our stripping the path down so test for it -n is default operator + if [ "$pathname" ]; then + + prevmatch=0 + #todo: possibly there is a neater way to do this without a loop?? + for incPath in "${incpaths[@]}" #loop through incpaths + do + if [[ "$pathname" != "${pathname/$incPath/}" ]]; then + prevmatch=1 + fi + done + + #if substring then do recurse + if [[ $prevmatch -eq 0 ]]; then #make sure we have not previously matched + + #pre-existing path: yes | no? + if grep -rq "^[^#].*\s$pathname$" "${amm}/"*"/modman" #target is what is important so find end line not beginning line + then #pre-existing path: yes + echo "..." + echo "A path was found that exists in below modman description file" #error + grep -r --color=always "\s$pathname$" "${amm}/"*"/modman" + echo "It is therefore presently illegal for it to be included in this module." + echo "..." + if [[ -d $f ]]; then + incpaths+=("$pathname") + fi + read -p "press enter to continue..." goonthen + else #pre-existing path: no + + read -p "include '$pathname': [N][y]" include #include path: yes | no? + if [[ "$include" == "" ]]; then + include="N" + fi + + if [[ ${include,,} == "y" ]]; then #include path: yes + + echo "..." + echo "You answered y:yes modman will include the path" + echo "..." + + #write path to modman + echo "$pathname $pathname" >> $awc_desc #substring ${var:start} + #was it a directory or file + if [[ -d $f ]]; then + incpaths+=("$pathname") + fi + + elif [[ ${include^^} == "N" ]]; then #include path: no + echo "You answered N:no, modman is not including the path" + else + echo "Warning: you answered $include which is invalid, modman is not including path" + fi + + fi # test other modules for pre-existing path + fi # test prvious match + fi #continue + done #no more paths + #return success + return 0 } ########################################################################### @@ -1044,7 +1044,7 @@ wc_desc=$wc_dir/modman # path to modman structure descriptor file case "$action" in automodman) - run_automodman "$module" "$mm" "$wc_dir" "$wc_desc" + run_automodman "$module" "$mm" "$wc_dir" "$wc_desc" ;; update) require_wc "$module" || exit 1 From 9f7124da87ab4299a73ac70e0e2ff239c123361c Mon Sep 17 00:00:00 2001 From: waynemowdirect Date: Thu, 30 Apr 2015 18:09:06 +0100 Subject: [PATCH 2/2] Adding the changes needed for Mac portability --- modman | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modman b/modman index 1c8b119..205437b 100755 --- a/modman +++ b/modman @@ -673,7 +673,7 @@ run_automodman () #"$module" "$mm" "$wc_dir" "$wc_desc" include="N" fi - if [[ ${include,,} == "y" ]]; then #include path: yes + if [ "$include" == "y" -o "$include" == "Y" ]; then #include path: yes echo "..." echo "You answered y:yes modman will include the path" @@ -686,7 +686,7 @@ run_automodman () #"$module" "$mm" "$wc_dir" "$wc_desc" incpaths+=("$pathname") fi - elif [[ ${include^^} == "N" ]]; then #include path: no + elif [ "$include" == "n" -o "$include" == "N" ]; then #include path: no echo "You answered N:no, modman is not including the path" else echo "Warning: you answered $include which is invalid, modman is not including path"