You are here

build_distro.sh in Drupal Commons 7.3

#!/bin/bash
#set -e

#modules=(commons_activity_streams commons_featured commons_notices commons_profile_social commons_user_profile_pages commons_body commons_follow commons_notify commons_q_a commons_utility_links commons_bw commons_groups commons_pages commons_radioactivity commons_wikis commons_content_moderation commons_like commons_polls commons_search commons_wysiwyg commons_documents commons_location commons_posts commons_site_homepage commons_events commons_misc commons_profile_base commons_topics commons_social_sharing commons_trusted_contacts)
#themes=(commons_origins)

merge_repos() {
  cd $BUILD_PATH/commons_profile
  for i in "${modules[@]}"; do
    if [[ -n $USERNAME ]]; then
      git remote add ${i} ${USERNAME}@git.drupal.org:project/${i}.git
    else
      git remote add ${i} http://git.drupal.org/project/${i}.git
    fi
    git fetch ${i}
    git merge -s ours --no-commit ${i}/7.x-3.x
    git read-tree --prefix=modules/commons/${i} -u ${i}/7.x-3.x
    git commit -m "Merged ${i} into Commons repo"
    git remote rm ${i}
    echo "Successfully added $i to commons profile"
  done
  #do the theme now
  i=commons_origins
  if [[ -n $USERNAME ]]; then
    git remote add ${i} ${USERNAME}@git.drupal.org:project/${i}.git
  else
    git remote add ${i} http://git.drupal.org/project/${i}.git
  fi
  git fetch ${i}
  git merge -s ours --no-commit ${i}/7.x-3.x
  git read-tree --prefix=themes/commons/${i} -u ${i}/7.x-3.x
  git commit -m "Merged ${i} into Commons repo"
  echo "Successfully added $i to commons profile"
}

# this function is no longer needed because we're in one repo now.
pull_git() {
    cd $BUILD_PATH/commons_profile
    if [[ -n $RESET ]]; then
      git reset --hard HEAD
    fi
    git pull origin 7.x-3.x

    cd $BUILD_PATH/repos/modules
    for i in `ls | awk -F/ '{print $1}'`; do
      echo $i
      cd $i
      if [[ -n $RESET ]]; then
        git reset --hard HEAD
      fi
      git pull origin
      cd ..
    done
}

release_notes() {
  rm -rf rn.txt
  pull_git $BUILD_PATH
  OUTPUT="<h2>Release Notes for $RELEASE</h2>"
  cd $BUILD_PATH/commons_profile
  OUTPUT="$OUTPUT <h3>Drupal Commons:</h3> `drush rn --date $FROM_DATE $TO_DATE`"

  ## old repos. don't use this anymore
  # cd $BUILD_PATH/repos/modules
  # for i in "${modules[@]}"; do
  #  echo $i
  #  cd $i
  #  RN=`drush rn --date $FROM_DATE $TO_DATE`
  #  if [[ -n $RN ]]; then
  #    OUTPUT="$OUTPUT <h3>$i:</h3> $RN"
  #  fi
  #  cd ..
  #done
  #cd $BUILD_PATH/repos/themes/commons_origins
  #RN=`drush rn --date $FROM_DATE $TO_DATE`
  #if [[ -n $RN ]]; then
  #  OUTPUT="$OUTPUT <h3>commons_origins:</h3> $RN"
  #fi

  echo $OUTPUT >> $BUILD_PATH/rn.txt
  echo "Release notes for $RELEASE created at $BUILD_PATH/rn.txt"
}

build_distro() {
  if [[ -d $BUILD_PATH ]]; then
      cd $BUILD_PATH
      #backup the sites directory
      if [[ -d docroot ]]; then
        rm -rf ./docroot
      fi
      # do we have the profile?
      if [[ -d $BUILD_PATH/commons_profile ]]; then
        if [[ -d $BUILD_PATH/repos ]]; then
          rm -f /tmp/commons.tar.gz
          drush make --no-cache --prepare-install --drupal-org=core $BUILD_PATH/commons_profile/drupal-org-core.make $BUILD_PATH/docroot
          drush make --no-cache --no-core --contrib-destination --tar $BUILD_PATH/commons_profile/drupal-org.make /tmp/commons
        else
          mkdir -p $BUILD_PATH/repos/modules/contrib
          cd $BUILD_PATH/repos/modules/contrib
          for i in "${modules[@]}"; do
            echo "bringing in ${i} for $USERNAME";
            if [[ -n $USERNAME ]]; then
              git clone ${USERNAME}@git.drupal.org:project/${i}.git
            else
              git clone http://git.drupal.org/project/${i}.git
            fi
          done
          cd $BUILD_PATH/repos
          mkdir -p $BUILD_PATH/repos/themes/contrib
          cd $BUILD_PATH/repos/themes
          for i in "${themes[@]}"; do
            if [[ -n $USERNAME ]]; then
              git clone ${USERNAME}@git.drupal.org:project/${i}.git
            else
              git clone http://git.drupal.org/project/${i}.git
            fi
          done
          build_distro $BUILD_PATH
        fi
        # symlink the profile sites folder to our dev copy
        cd docroot
        if [[ -d $BUILD_PATH/sites ]]; then
          rm -rf $BUILD_PATH/docroot/sites
          ln -s ../sites $BUILD_PATH/docroot/sites
        else
          mv $BUILD_PATH/docroot/sites $BUILD_PATH/sites
          ln -s ../sites $BUILD_PATH/docroot/sites
        fi
        chmod -R 777 $BUILD_PATH/docroot/sites/default

        ## put commons profile and modules into the profile folder
        rm -rf docroot/profiles/commons
        if [ -e $BUILD_PATH/repos.txt ]; then
          UNTAR="tar -zxvf /tmp/commons.tar.gz -X $BUILD_PATH/repos.txt"
        else
          cd $BUILD_PATH/repos
          find * -mindepth 1 -maxdepth 2 -type d -not -path ".*" -not -path "modules/.*" -not -path "themes/.*" -not -path "modules/contrib" -not -path "themes/contrib" > $BUILD_PATH/repos.txt
          # exclude repos since we're updating already by linking it to the repos directory.
          UNTAR="tar -zxvf /tmp/commons.tar.gz -X $BUILD_PATH/repos.txt"
        fi
        cd $BUILD_PATH/docroot/profiles
        eval $UNTAR
        cd commons
        ln -s ../../../commons_profile/* .
        ln -s ../../../../commons_profile/modules/commons ${BUILD_PATH}/docroot/profiles/commons/modules/
        ln -s ../../../../commons_profile/themes/commons ${BUILD_PATH}/docroot/profiles/commons/themes/
        for line in $(cat $BUILD_PATH/repos.txt); do
          ln -s ../../../../../repos/${line} ${BUILD_PATH}/docroot/profiles/commons/$(echo ${line} | awk -F/ '{print $1}')/contrib/
        done
        chmod -R 775 $BUILD_PATH/docroot/profiles/commons
      else
        git clone --branch 7.x-3.x ${USERNAME}@git.drupal.org:project/commons.git commons_profile
        build_distro $BUILD_PATH
      fi
  else
    mkdir $BUILD_PATH
    build_distro $BUILD_PATH $USERNAME
  fi
}

site_install() {
  read -p "You're about to DESTROY all data for site ${SITE} Are you sure? " -n 1 -r
  if [[ $REPLY =~ ^[Yy]$ ]]; then
    cd ${BUILD_PATH}/docroot/sites/${SITE}
    drush -y sql-drop
    drush site-install --site-name=${SITE} --account-name=admin --account-pass=${ADMIN_PASS} --account-mail=${ADMIN_EMAIL} --site-mail=commons_site@example.com -v -y commons commons_anonymous_welcome_text_form.commons_install_example_content=${DEMO_CONTENT} commons_anonymous_welcome_text_form.commons_anonymous_welcome_title="Commons Example Site" commons_anonymous_welcome_text_form.commons_anonymous_welcome_body="Using the site-install version of commons." commons_create_first_group.commons_first_group_title="Sales Group" commons_create_first_group.commons_first_group_body="This is the sales group from site-install."
  fi
}

# This allows you to test the make file without needing to upload it to drupal.org and run the main make file.
update() {
  if [[ -d $DOCROOT ]]; then
    cd $DOCROOT
    # do we have the profile?
    if [[ -d $DOCROOT/profiles/commons ]]; then
      # do we have an installed commons profile?
        rm -f /tmp/docroot.tar.gz
        rm -f /tmp/commons.tar.gz
        drush make --no-cache --tar --drupal-org=core profiles/commons/drupal-org-core.make /tmp/docroot
        drush make --no-core --no-cache --tar --drupal-org profiles/commons/drupal-org.make /tmp/commons
        cd ..
        tar -zxvf /tmp/docroot.tar.gz
        cd docroot/profiles/commons/modules/contrib
        # remove the symlinks in the repos before we execute
        find . -type l | awk -F/ '{print $2}' > /tmp/repos.txt
        cd $DOCROOT/profiles
        # exclude repos since we're updating already by linking it to the repos directory.
        UNTAR="tar -zxvf /tmp/commons.tar.gz -X /tmp/repos.txt"
        eval $UNTAR
        echo "Successfully Updated drupal from make files"
        exit 0
    fi
  fi
  echo "Unable to find Build path or drupal root. Please run build first"
  exit 1
}

case $1 in
  site-install)
    if [[ -n $2 ]] && [[ -n $3 ]]; then
      BUILD_PATH=$2
    else
      echo "Usage build_distro.sh site-install [build_path] [site] [demo-content] [admin-email] [admin-pass]"
    fi
    if [[ -n $3 ]]; then
      SITE=$3
    else
      SITE='default'
    fi
    if [[ -n $4 ]]; then
      DEMO_CONTENT='TRUE'
    else
      DEMO_CONTENT='FALSE'
    fi
    if [[ -n $5 ]]; then
      ADMIN_EMAIL=$5
    else
      ADMIN_EMAIL='admin@example.com'
    fi
    if [[ -n $6 ]]; then
      ADMIN_PASS=$6
    else
      ADMIN_PASS='admin'
    fi

    site_install $BUILD_PATH $SITE $DEMO_CONTENT $ADMIN_EMAIL $ADMIN_PASS;;
  pull)
    if [[ -n $2 ]]; then
      BUILD_PATH=$2
      if [[ -n $3 ]]; then
       RESET=1
      fi
    else
      echo "Usage: build_distro.sh pull [build_path]"
      exit 1
    fi
    pull_git $BUILD_PATH $RESET;;
  build)
    if [[ -n $2 ]]; then
      BUILD_PATH=$2
    else
      echo "Usage: build_distro.sh build [build_path]"
      exit 1
    fi
    if [[ -n $3 ]]; then
      USERNAME=$3
    fi
    build_distro $BUILD_PATH $USERNAME;;
  rn)
    if [[ -n $2 ]] && [[ -n $3 ]] && [[ -n $4 ]] && [[ -n $5 ]]; then
      BUILD_PATH=$2
      RELEASE=$3
      FROM_DATE=$4
      TO_DATE=$5
    else
      echo "Usage: build_distro.sh rn [build_path] [release] [from_date] [to_date]"
      exit 1
    fi
    release_notes $BUILD_PATH $RELEASE $FROM_DATE $TO_DATE;;
  update)
    if [[ -n $2 ]]; then
      DOCROOT=$2
    else
      echo "Usage: build_distro.sh update [DOCROOT]"
      exit 1
    fi
    if [[ -n $3 ]]; then
      USERNAME=$3
    fi
    update $DOCROOT;;
  merge_repos)
    if [[ -n $2 ]]; then
      BUILD_PATH=$2
    else
      echo "Usage: build_distro.sh build [build_path]"
      exit 1
    fi
    if [[ -n $3 ]]; then
      USERNAME=$3
    fi
    merge_repos $BUILD_PATH $USERNAME;;
esac

File

scripts/build_distro.sh
View source
  1. #!/bin/bash
  2. #set -e
  3. #modules=(commons_activity_streams commons_featured commons_notices commons_profile_social commons_user_profile_pages commons_body commons_follow commons_notify commons_q_a commons_utility_links commons_bw commons_groups commons_pages commons_radioactivity commons_wikis commons_content_moderation commons_like commons_polls commons_search commons_wysiwyg commons_documents commons_location commons_posts commons_site_homepage commons_events commons_misc commons_profile_base commons_topics commons_social_sharing commons_trusted_contacts)
  4. #themes=(commons_origins)
  5. merge_repos() {
  6. cd $BUILD_PATH/commons_profile
  7. for i in "${modules[@]}"; do
  8. if [[ -n $USERNAME ]]; then
  9. git remote add ${i} ${USERNAME}@git.drupal.org:project/${i}.git
  10. else
  11. git remote add ${i} http://git.drupal.org/project/${i}.git
  12. fi
  13. git fetch ${i}
  14. git merge -s ours --no-commit ${i}/7.x-3.x
  15. git read-tree --prefix=modules/commons/${i} -u ${i}/7.x-3.x
  16. git commit -m "Merged ${i} into Commons repo"
  17. git remote rm ${i}
  18. echo "Successfully added $i to commons profile"
  19. done
  20. #do the theme now
  21. i=commons_origins
  22. if [[ -n $USERNAME ]]; then
  23. git remote add ${i} ${USERNAME}@git.drupal.org:project/${i}.git
  24. else
  25. git remote add ${i} http://git.drupal.org/project/${i}.git
  26. fi
  27. git fetch ${i}
  28. git merge -s ours --no-commit ${i}/7.x-3.x
  29. git read-tree --prefix=themes/commons/${i} -u ${i}/7.x-3.x
  30. git commit -m "Merged ${i} into Commons repo"
  31. echo "Successfully added $i to commons profile"
  32. }
  33. # this function is no longer needed because we're in one repo now.
  34. pull_git() {
  35. cd $BUILD_PATH/commons_profile
  36. if [[ -n $RESET ]]; then
  37. git reset --hard HEAD
  38. fi
  39. git pull origin 7.x-3.x
  40. cd $BUILD_PATH/repos/modules
  41. for i in `ls | awk -F/ '{print $1}'`; do
  42. echo $i
  43. cd $i
  44. if [[ -n $RESET ]]; then
  45. git reset --hard HEAD
  46. fi
  47. git pull origin
  48. cd ..
  49. done
  50. }
  51. release_notes() {
  52. rm -rf rn.txt
  53. pull_git $BUILD_PATH
  54. OUTPUT="

    Release Notes for $RELEASE

    "
  55. cd $BUILD_PATH/commons_profile
  56. OUTPUT="$OUTPUT

    Drupal Commons:

    `drush rn --date $FROM_DATE $TO_DATE`"
  57. ## old repos. don't use this anymore
  58. # cd $BUILD_PATH/repos/modules
  59. # for i in "${modules[@]}"; do
  60. # echo $i
  61. # cd $i
  62. # RN=`drush rn --date $FROM_DATE $TO_DATE`
  63. # if [[ -n $RN ]]; then
  64. # OUTPUT="$OUTPUT

    $i:

    $RN"
  65. # fi
  66. # cd ..
  67. #done
  68. #cd $BUILD_PATH/repos/themes/commons_origins
  69. #RN=`drush rn --date $FROM_DATE $TO_DATE`
  70. #if [[ -n $RN ]]; then
  71. # OUTPUT="$OUTPUT

    commons_origins:

    $RN"
  72. #fi
  73. echo $OUTPUT >> $BUILD_PATH/rn.txt
  74. echo "Release notes for $RELEASE created at $BUILD_PATH/rn.txt"
  75. }
  76. build_distro() {
  77. if [[ -d $BUILD_PATH ]]; then
  78. cd $BUILD_PATH
  79. #backup the sites directory
  80. if [[ -d docroot ]]; then
  81. rm -rf ./docroot
  82. fi
  83. # do we have the profile?
  84. if [[ -d $BUILD_PATH/commons_profile ]]; then
  85. if [[ -d $BUILD_PATH/repos ]]; then
  86. rm -f /tmp/commons.tar.gz
  87. drush make --no-cache --prepare-install --drupal-org=core $BUILD_PATH/commons_profile/drupal-org-core.make $BUILD_PATH/docroot
  88. drush make --no-cache --no-core --contrib-destination --tar $BUILD_PATH/commons_profile/drupal-org.make /tmp/commons
  89. else
  90. mkdir -p $BUILD_PATH/repos/modules/contrib
  91. cd $BUILD_PATH/repos/modules/contrib
  92. for i in "${modules[@]}"; do
  93. echo "bringing in ${i} for $USERNAME";
  94. if [[ -n $USERNAME ]]; then
  95. git clone ${USERNAME}@git.drupal.org:project/${i}.git
  96. else
  97. git clone http://git.drupal.org/project/${i}.git
  98. fi
  99. done
  100. cd $BUILD_PATH/repos
  101. mkdir -p $BUILD_PATH/repos/themes/contrib
  102. cd $BUILD_PATH/repos/themes
  103. for i in "${themes[@]}"; do
  104. if [[ -n $USERNAME ]]; then
  105. git clone ${USERNAME}@git.drupal.org:project/${i}.git
  106. else
  107. git clone http://git.drupal.org/project/${i}.git
  108. fi
  109. done
  110. build_distro $BUILD_PATH
  111. fi
  112. # symlink the profile sites folder to our dev copy
  113. cd docroot
  114. if [[ -d $BUILD_PATH/sites ]]; then
  115. rm -rf $BUILD_PATH/docroot/sites
  116. ln -s ../sites $BUILD_PATH/docroot/sites
  117. else
  118. mv $BUILD_PATH/docroot/sites $BUILD_PATH/sites
  119. ln -s ../sites $BUILD_PATH/docroot/sites
  120. fi
  121. chmod -R 777 $BUILD_PATH/docroot/sites/default
  122. ## put commons profile and modules into the profile folder
  123. rm -rf docroot/profiles/commons
  124. if [ -e $BUILD_PATH/repos.txt ]; then
  125. UNTAR="tar -zxvf /tmp/commons.tar.gz -X $BUILD_PATH/repos.txt"
  126. else
  127. cd $BUILD_PATH/repos
  128. find * -mindepth 1 -maxdepth 2 -type d -not -path ".*" -not -path "modules/.*" -not -path "themes/.*" -not -path "modules/contrib" -not -path "themes/contrib" > $BUILD_PATH/repos.txt
  129. # exclude repos since we're updating already by linking it to the repos directory.
  130. UNTAR="tar -zxvf /tmp/commons.tar.gz -X $BUILD_PATH/repos.txt"
  131. fi
  132. cd $BUILD_PATH/docroot/profiles
  133. eval $UNTAR
  134. cd commons
  135. ln -s ../../../commons_profile/* .
  136. ln -s ../../../../commons_profile/modules/commons ${BUILD_PATH}/docroot/profiles/commons/modules/
  137. ln -s ../../../../commons_profile/themes/commons ${BUILD_PATH}/docroot/profiles/commons/themes/
  138. for line in $(cat $BUILD_PATH/repos.txt); do
  139. ln -s ../../../../../repos/${line} ${BUILD_PATH}/docroot/profiles/commons/$(echo ${line} | awk -F/ '{print $1}')/contrib/
  140. done
  141. chmod -R 775 $BUILD_PATH/docroot/profiles/commons
  142. else
  143. git clone --branch 7.x-3.x ${USERNAME}@git.drupal.org:project/commons.git commons_profile
  144. build_distro $BUILD_PATH
  145. fi
  146. else
  147. mkdir $BUILD_PATH
  148. build_distro $BUILD_PATH $USERNAME
  149. fi
  150. }
  151. site_install() {
  152. read -p "You're about to DESTROY all data for site ${SITE} Are you sure? " -n 1 -r
  153. if [[ $REPLY =~ ^[Yy]$ ]]; then
  154. cd ${BUILD_PATH}/docroot/sites/${SITE}
  155. drush -y sql-drop
  156. drush site-install --site-name=${SITE} --account-name=admin --account-pass=${ADMIN_PASS} --account-mail=${ADMIN_EMAIL} --site-mail=commons_site@example.com -v -y commons commons_anonymous_welcome_text_form.commons_install_example_content=${DEMO_CONTENT} commons_anonymous_welcome_text_form.commons_anonymous_welcome_title="Commons Example Site" commons_anonymous_welcome_text_form.commons_anonymous_welcome_body="Using the site-install version of commons." commons_create_first_group.commons_first_group_title="Sales Group" commons_create_first_group.commons_first_group_body="This is the sales group from site-install."
  157. fi
  158. }
  159. # This allows you to test the make file without needing to upload it to drupal.org and run the main make file.
  160. update() {
  161. if [[ -d $DOCROOT ]]; then
  162. cd $DOCROOT
  163. # do we have the profile?
  164. if [[ -d $DOCROOT/profiles/commons ]]; then
  165. # do we have an installed commons profile?
  166. rm -f /tmp/docroot.tar.gz
  167. rm -f /tmp/commons.tar.gz
  168. drush make --no-cache --tar --drupal-org=core profiles/commons/drupal-org-core.make /tmp/docroot
  169. drush make --no-core --no-cache --tar --drupal-org profiles/commons/drupal-org.make /tmp/commons
  170. cd ..
  171. tar -zxvf /tmp/docroot.tar.gz
  172. cd docroot/profiles/commons/modules/contrib
  173. # remove the symlinks in the repos before we execute
  174. find . -type l | awk -F/ '{print $2}' > /tmp/repos.txt
  175. cd $DOCROOT/profiles
  176. # exclude repos since we're updating already by linking it to the repos directory.
  177. UNTAR="tar -zxvf /tmp/commons.tar.gz -X /tmp/repos.txt"
  178. eval $UNTAR
  179. echo "Successfully Updated drupal from make files"
  180. exit 0
  181. fi
  182. fi
  183. echo "Unable to find Build path or drupal root. Please run build first"
  184. exit 1
  185. }
  186. case $1 in
  187. site-install)
  188. if [[ -n $2 ]] && [[ -n $3 ]]; then
  189. BUILD_PATH=$2
  190. else
  191. echo "Usage build_distro.sh site-install [build_path] [site] [demo-content] [admin-email] [admin-pass]"
  192. fi
  193. if [[ -n $3 ]]; then
  194. SITE=$3
  195. else
  196. SITE='default'
  197. fi
  198. if [[ -n $4 ]]; then
  199. DEMO_CONTENT='TRUE'
  200. else
  201. DEMO_CONTENT='FALSE'
  202. fi
  203. if [[ -n $5 ]]; then
  204. ADMIN_EMAIL=$5
  205. else
  206. ADMIN_EMAIL='admin@example.com'
  207. fi
  208. if [[ -n $6 ]]; then
  209. ADMIN_PASS=$6
  210. else
  211. ADMIN_PASS='admin'
  212. fi
  213. site_install $BUILD_PATH $SITE $DEMO_CONTENT $ADMIN_EMAIL $ADMIN_PASS;;
  214. pull)
  215. if [[ -n $2 ]]; then
  216. BUILD_PATH=$2
  217. if [[ -n $3 ]]; then
  218. RESET=1
  219. fi
  220. else
  221. echo "Usage: build_distro.sh pull [build_path]"
  222. exit 1
  223. fi
  224. pull_git $BUILD_PATH $RESET;;
  225. build)
  226. if [[ -n $2 ]]; then
  227. BUILD_PATH=$2
  228. else
  229. echo "Usage: build_distro.sh build [build_path]"
  230. exit 1
  231. fi
  232. if [[ -n $3 ]]; then
  233. USERNAME=$3
  234. fi
  235. build_distro $BUILD_PATH $USERNAME;;
  236. rn)
  237. if [[ -n $2 ]] && [[ -n $3 ]] && [[ -n $4 ]] && [[ -n $5 ]]; then
  238. BUILD_PATH=$2
  239. RELEASE=$3
  240. FROM_DATE=$4
  241. TO_DATE=$5
  242. else
  243. echo "Usage: build_distro.sh rn [build_path] [release] [from_date] [to_date]"
  244. exit 1
  245. fi
  246. release_notes $BUILD_PATH $RELEASE $FROM_DATE $TO_DATE;;
  247. update)
  248. if [[ -n $2 ]]; then
  249. DOCROOT=$2
  250. else
  251. echo "Usage: build_distro.sh update [DOCROOT]"
  252. exit 1
  253. fi
  254. if [[ -n $3 ]]; then
  255. USERNAME=$3
  256. fi
  257. update $DOCROOT;;
  258. merge_repos)
  259. if [[ -n $2 ]]; then
  260. BUILD_PATH=$2
  261. else
  262. echo "Usage: build_distro.sh build [build_path]"
  263. exit 1
  264. fi
  265. if [[ -n $3 ]]; then
  266. USERNAME=$3
  267. fi
  268. merge_repos $BUILD_PATH $USERNAME;;
  269. esac