You are here

modules.sh in Open Atrium 7.2

#!/bin/bash
# Script to list modules that need to be updated
#
main () {

if [ $# -eq 0 ]; then
  echo "Usage $0 [-c] [-d] [-p] [-f] [-b branch-name] [module]"
  echo "  -c change to directory of module"
  echo "  -d shows the current git description"
  echo "  -p pulls the latest code"
  echo "  -r tag a new release of the module"
  echo "  -f force module into local directory"
  echo "  -b switches to the specified branch (and creates if needed)"
  echo "     use 'dev' as branch-name to switch to current dev branch"
  echo "  [module] specifies specific module, or if omitted, all modules are processed"
  return 1
fi
local RED="\033[0;31m"
local YELLOW="\033[0;33m"
local NORMAL="\033[0;0m"

local CURRENT=""
local LOGFILE=""
local PULL=0
local DESCRIBE=0
local FORCE=0
local RELEASE=0
local CHANGEDIR=0
local BRANCH=""
local opt=""

CURRENT=$(pwd -P)
LOGFILE="$CURRENT/release.txt"

while getopts ":pcdfrb:" opt; do
  case $opt in
    p) # pull repo
      PULL=1
      ;;
    c) # change dir
      CHANGEDIR=1
      ;;
    d) # describe
      DESCRIBE=1
      ;;
    f) # force
      FORCE=1
      ;;
    r) # release
      RELEASE=1
      ;;
    b) # branch
      BRANCH=$OPTARG
      ;;
    ?)
      echo "Invalid option: -$OPTARG" >&2
      ;;
  esac
done
shift $((OPTIND-1))
echo 'Checking modules...'
local submodules=""
submodules=(
  "oa_core"
  "oa_discussion"
  "oa_events"
  "oa_wiki"
  "oa_worktracker"
  "oa_admin"
  "oa_analytics"
  "oa_appearance"
  "oa_archive"
  "oa_brand"
  "oa_clone"
  "oa_comment"
  "oa_contextual_tabs"
  "oa_devel"
  "oa_domains"
  "oa_export"
  "oa_events_import"
  "oa_favorites"
  "oa_files"
  "oa_home"
  "oa_htmlmail"
  "oa_mailhandler"
  "oa_markdown"
  "oa_media"
  "oa_messages_digest"
  "oa_notifications"
  "oa_project"
  "oa_related"
  "oa_sandbox"
  "oa_search"
  "oa_sitemap"
  "oa_site_layout"
  "oa_site_layout_defaults"
  "oa_styles"
  "oa_subspaces"
  "oa_toolbar"
  "oa_tour"
  "oa_tour_defaults"
  "oa_wizard"
  "oa_radix"
  "oa_basetheme"
  "oa_theme"
  "bootstrap_tour"
  "colorizer"
  "command_buttons"
  "contextual_tabs"
  "oa_angular"
  "oa_responsive_regions"
  "openatrium"
)
local module=""

TARGET=$1
# Make sure we have a target directory
if [ ! -z "$1" ]; then
  # if module is specified, then just use that instead of full list
  submodules=("$1")
fi

for module in "${submodules[@]}"
do
  TARGET=''
  # first look in local modules dir
  if [ -e modules ]; then
    TARGET=$(find modules -type d -name "$module" -print -quit)
  fi
  # if not found and not forced, look for other subdirs
  if [ -z $TARGET ]; then
    if [ $FORCE = 0 ]; then
      TARGET=$(find . -type d -name "$module" -print -quit)
    fi
  fi
  if [ ! -e "$TARGET/.git" ]; then
    # repo not found, so create it if pulling
    if [ $PULL = 1 ]; then
      if [ ! -e "modules" ]; then
        mkdir modules
      fi
      cd modules
      git clone git@git.drupal.org:project/"$module".git
      cd "$module"
      TARGET=$(pwd -P)
      cd $CURRENT
    fi
  fi

  if [ -e "$TARGET/.git" ]; then
    cd $TARGET
    if [ $PULL = 1 -o $RELEASE = 1 ]; then
      echo "Pulling $module"
      git fetch --tags
      if [ $module = "openatrium" ]; then
        # if pulling main distro, do a rebase
        git pull --rebase
      else
        git pull origin
      fi
    fi

    if [ $DESCRIBE = 1 ]; then
      local stat=""
      local tag=""
      local old_tag=""
      local branch=""

      stat=$(git status --porcelain --untracked-files=no)
      tag=$(git describe --tag)
      old_tag=$(git describe --abbrev=0 --tag)
      branch=$(git rev-parse --abbrev-ref HEAD)
      if [ ! "$stat" = "" ]; then
        printf "$RED$module: $tag (DIRTY)$NORMAL\n"
      elif [ "$tag" = "$old_tag" ]; then
        echo "$module: $tag"
      elif [ "$stat" = '' ]; then
        printf "$YELLOW$module: $tag ($branch)$NORMAL\n"
      fi
    fi

    if [ "${BRANCH}" != "" ]; then
      if [ "${BRANCH}" = "dev" ]; then
        local old_tag=$(git describe --abbrev=0 --tag)
        local dev_tag=${old_tag:0:6}
        git checkout "${dev_tag}x"
      else
        git branch ${BRANCH} 2>/dev/null
        git checkout ${BRANCH}
      fi
    fi

    if [ $RELEASE = 1 ]; then
      local full_tag=""
      local old_tag=""
      local new_tag=""

      full_tag=$(git describe --tag)
      old_tag=$(git describe --abbrev=0 --tag)
      if [ "$full_tag" = "$old_tag" ]; then
        echo "$module $full_tag : no release is needed"
      else
        # increment and release new tag
        new_tag="${old_tag/-beta/-beta.}"
        new_tag="${new_tag/-alpha/-alpha.}"
        new_tag="${new_tag/-rc/-rc.}"
        # http://stackoverflow.com/questions/8653126/how-to-increment-version-number-in-a-shell-script
        new_tag=$(echo $new_tag | \
          awk -F"." '{$NF+=1}{print $0RT}' OFS="." ORS="") #increments $old_tag
        new_tag="${new_tag/-beta./-beta}"
        new_tag="${new_tag/-alpha./-alpha}"
        new_tag="${new_tag/-rc./-rc}"

        if [ ! "$old_tag" = "$new_tag" ]; then
          echo "$module: Tagging with $new_tag"
          git tag $new_tag
          git push origin tag $new_tag
          local notes=""
          notes=$(drush rn $old_tag $new_tag)
          # use printf instead of echo to handle multiline
          printf "$notes\n"
          local name=""
          name=$(grep "name =" "$module".info | sed "s/name = //")
          echo "<h4>$name $new_tag</h4>" >> $LOGFILE
          # pull out just the list of changes
          # trick to convert \n to \r so sed sees the entire thing as one line
          local changes=""
          changes=$(printf "$notes\n" | tr '\n' '\r' | sed 's/.*\(<ul>.*<\/ul>\).*/\1/'  | tr '\r' '\n')
          printf "$changes\n" >> $LOGFILE
          echo "" >> $LOGFILE
        fi
      fi
    fi

    if [ $CHANGEDIR = 1 ]; then
      break
    fi
  fi
  if [ $CHANGEDIR = 0 ]; then
    cd $CURRENT
  fi
done
}

main "$@"

File

scripts/modules.sh
View source
  1. #!/bin/bash
  2. # Script to list modules that need to be updated
  3. #
  4. main () {
  5. if [ $# -eq 0 ]; then
  6. echo "Usage $0 [-c] [-d] [-p] [-f] [-b branch-name] [module]"
  7. echo " -c change to directory of module"
  8. echo " -d shows the current git description"
  9. echo " -p pulls the latest code"
  10. echo " -r tag a new release of the module"
  11. echo " -f force module into local directory"
  12. echo " -b switches to the specified branch (and creates if needed)"
  13. echo " use 'dev' as branch-name to switch to current dev branch"
  14. echo " [module] specifies specific module, or if omitted, all modules are processed"
  15. return 1
  16. fi
  17. local RED="\033[0;31m"
  18. local YELLOW="\033[0;33m"
  19. local NORMAL="\033[0;0m"
  20. local CURRENT=""
  21. local LOGFILE=""
  22. local PULL=0
  23. local DESCRIBE=0
  24. local FORCE=0
  25. local RELEASE=0
  26. local CHANGEDIR=0
  27. local BRANCH=""
  28. local opt=""
  29. CURRENT=$(pwd -P)
  30. LOGFILE="$CURRENT/release.txt"
  31. while getopts ":pcdfrb:" opt; do
  32. case $opt in
  33. p) # pull repo
  34. PULL=1
  35. ;;
  36. c) # change dir
  37. CHANGEDIR=1
  38. ;;
  39. d) # describe
  40. DESCRIBE=1
  41. ;;
  42. f) # force
  43. FORCE=1
  44. ;;
  45. r) # release
  46. RELEASE=1
  47. ;;
  48. b) # branch
  49. BRANCH=$OPTARG
  50. ;;
  51. ?)
  52. echo "Invalid option: -$OPTARG" >&2
  53. ;;
  54. esac
  55. done
  56. shift $((OPTIND-1))
  57. echo 'Checking modules...'
  58. local submodules=""
  59. submodules=(
  60. "oa_core"
  61. "oa_discussion"
  62. "oa_events"
  63. "oa_wiki"
  64. "oa_worktracker"
  65. "oa_admin"
  66. "oa_analytics"
  67. "oa_appearance"
  68. "oa_archive"
  69. "oa_brand"
  70. "oa_clone"
  71. "oa_comment"
  72. "oa_contextual_tabs"
  73. "oa_devel"
  74. "oa_domains"
  75. "oa_export"
  76. "oa_events_import"
  77. "oa_favorites"
  78. "oa_files"
  79. "oa_home"
  80. "oa_htmlmail"
  81. "oa_mailhandler"
  82. "oa_markdown"
  83. "oa_media"
  84. "oa_messages_digest"
  85. "oa_notifications"
  86. "oa_project"
  87. "oa_related"
  88. "oa_sandbox"
  89. "oa_search"
  90. "oa_sitemap"
  91. "oa_site_layout"
  92. "oa_site_layout_defaults"
  93. "oa_styles"
  94. "oa_subspaces"
  95. "oa_toolbar"
  96. "oa_tour"
  97. "oa_tour_defaults"
  98. "oa_wizard"
  99. "oa_radix"
  100. "oa_basetheme"
  101. "oa_theme"
  102. "bootstrap_tour"
  103. "colorizer"
  104. "command_buttons"
  105. "contextual_tabs"
  106. "oa_angular"
  107. "oa_responsive_regions"
  108. "openatrium"
  109. )
  110. local module=""
  111. TARGET=$1
  112. # Make sure we have a target directory
  113. if [ ! -z "$1" ]; then
  114. # if module is specified, then just use that instead of full list
  115. submodules=("$1")
  116. fi
  117. for module in "${submodules[@]}"
  118. do
  119. TARGET=''
  120. # first look in local modules dir
  121. if [ -e modules ]; then
  122. TARGET=$(find modules -type d -name "$module" -print -quit)
  123. fi
  124. # if not found and not forced, look for other subdirs
  125. if [ -z $TARGET ]; then
  126. if [ $FORCE = 0 ]; then
  127. TARGET=$(find . -type d -name "$module" -print -quit)
  128. fi
  129. fi
  130. if [ ! -e "$TARGET/.git" ]; then
  131. # repo not found, so create it if pulling
  132. if [ $PULL = 1 ]; then
  133. if [ ! -e "modules" ]; then
  134. mkdir modules
  135. fi
  136. cd modules
  137. git clone git@git.drupal.org:project/"$module".git
  138. cd "$module"
  139. TARGET=$(pwd -P)
  140. cd $CURRENT
  141. fi
  142. fi
  143. if [ -e "$TARGET/.git" ]; then
  144. cd $TARGET
  145. if [ $PULL = 1 -o $RELEASE = 1 ]; then
  146. echo "Pulling $module"
  147. git fetch --tags
  148. if [ $module = "openatrium" ]; then
  149. # if pulling main distro, do a rebase
  150. git pull --rebase
  151. else
  152. git pull origin
  153. fi
  154. fi
  155. if [ $DESCRIBE = 1 ]; then
  156. local stat=""
  157. local tag=""
  158. local old_tag=""
  159. local branch=""
  160. stat=$(git status --porcelain --untracked-files=no)
  161. tag=$(git describe --tag)
  162. old_tag=$(git describe --abbrev=0 --tag)
  163. branch=$(git rev-parse --abbrev-ref HEAD)
  164. if [ ! "$stat" = "" ]; then
  165. printf "$RED$module: $tag (DIRTY)$NORMAL\n"
  166. elif [ "$tag" = "$old_tag" ]; then
  167. echo "$module: $tag"
  168. elif [ "$stat" = '' ]; then
  169. printf "$YELLOW$module: $tag ($branch)$NORMAL\n"
  170. fi
  171. fi
  172. if [ "${BRANCH}" != "" ]; then
  173. if [ "${BRANCH}" = "dev" ]; then
  174. local old_tag=$(git describe --abbrev=0 --tag)
  175. local dev_tag=${old_tag:0:6}
  176. git checkout "${dev_tag}x"
  177. else
  178. git branch ${BRANCH} 2>/dev/null
  179. git checkout ${BRANCH}
  180. fi
  181. fi
  182. if [ $RELEASE = 1 ]; then
  183. local full_tag=""
  184. local old_tag=""
  185. local new_tag=""
  186. full_tag=$(git describe --tag)
  187. old_tag=$(git describe --abbrev=0 --tag)
  188. if [ "$full_tag" = "$old_tag" ]; then
  189. echo "$module $full_tag : no release is needed"
  190. else
  191. # increment and release new tag
  192. new_tag="${old_tag/-beta/-beta.}"
  193. new_tag="${new_tag/-alpha/-alpha.}"
  194. new_tag="${new_tag/-rc/-rc.}"
  195. # http://stackoverflow.com/questions/8653126/how-to-increment-version-number-in-a-shell-script
  196. new_tag=$(echo $new_tag | \
  197. awk -F"." '{$NF+=1}{print $0RT}' OFS="." ORS="") #increments $old_tag
  198. new_tag="${new_tag/-beta./-beta}"
  199. new_tag="${new_tag/-alpha./-alpha}"
  200. new_tag="${new_tag/-rc./-rc}"
  201. if [ ! "$old_tag" = "$new_tag" ]; then
  202. echo "$module: Tagging with $new_tag"
  203. git tag $new_tag
  204. git push origin tag $new_tag
  205. local notes=""
  206. notes=$(drush rn $old_tag $new_tag)
  207. # use printf instead of echo to handle multiline
  208. printf "$notes\n"
  209. local name=""
  210. name=$(grep "name =" "$module".info | sed "s/name = //")
  211. echo "

    $name $new_tag

    " >> $LOGFILE
  212. # pull out just the list of changes
  213. # trick to convert \n to \r so sed sees the entire thing as one line
  214. local changes=""
  215. changes=$(printf "$notes\n" | tr '\n' '\r' | sed 's/.*\(
      .*<\/ul>\).*/\1/' | tr '\r' '\n')
    • printf "$changes\n" >> $LOGFILE
    • echo "" >> $LOGFILE
    • fi
    • fi
    • fi
    • if [ $CHANGEDIR = 1 ]; then
    • break
    • fi
    • fi
    • if [ $CHANGEDIR = 0 ]; then
    • cd $CURRENT
    • fi
    • done
    • }
    • main "$@"