6 # Michael McMahon and Andrew
10 # Based on https://gluestick.office.fsf.org/hosts/services/civicrm/upgrading/
12 # This script aids the CiviCRM upgrade procedure. This script rebases our
13 # changes onto the latest tag and then packages the changes into a tarball.
15 # To run this script, and follow these steps:
17 # 0. Boot Trisquel open a terminal, and connect to the FSF VPN.
18 # 1. Create a build directory to save your civicrm builds.
19 # mkdir -p ~/builds/fsf/civicrm && cd ~/builds/fsf/civicrm
20 # 2. Place this script in that directory.
21 # 3. Edit this file and set your first name to the my_name variable with
22 # all lowercase letters.
23 # 3. Run this script with:
24 # bash civicrmrebase.sh
25 # 4. Follow all prompts and continue with the workflow found at
26 # https://gluestick.office.fsf.org/hosts/services/civicrm/upgrading/
28 # To skip pushing changes to other machines (vcs or crmserver4d), use the
29 # ```--dry-run``` argument like so:
30 # bash civicrmrebase.sh --dry-run
37 # Initialization checks
39 # Check for /bin/bash.
40 if [ "$BASH_VERSION" = '' ]; then
41 echo "You are not using bash."
42 echo "Use this syntax instead:"
43 echo "sudo bash bluearchive.sh"
48 # https://unix.stackexchange.com/questions/190513/shell-scripting-proper-way-to-
49 # check-for-internet-connectivity
50 echo Checking network...
51 if ping -q -c 1 -W 1 fsf.org
>/dev
/null
; then
52 echo "The network is up."
54 echo "The network is down."
55 echo "Check connection and restart script!"
59 # Log all stdout to logfile with date.
60 logfile
=/tmp
/$
(date +%Y
%m
%d-
%H
%M
).log
61 exec &> >(tee -a "$logfile")
62 echo "Starting logfile as $logfile..."
66 echo "User is set to $my_name. If you are not $my_name, stop the script now"
67 echo "with CTRL+c. Edit this script, and replace $my_name with your name, and"
68 echo "rerun the script."
71 if [[ $1 != "--dry-run" ]]; then
72 echo "--dry-run is disabled! External changes will be made!"
73 echo "If this is not your intention, stop the script now with CTRL+c"
74 echo "and run again with this syntax: bash civicrmrebase.sh --dry-run"
76 echo "--dry-run is enabled. No external changes will be made."
80 # Clone civicrm-core from vcs.fsf.org
81 if ls -d .
/civicrm-core
1> /dev
/null
2>&1; then
82 echo "civicrm-core folder found!"
83 echo "Remove this directory?"
84 ls -d .
/civicrm-core |
xargs -p -n1 rm -r
86 echo "Cloning our civicrm-core repo..."
87 git clone git@vcs.fsf.org
:civicrm-core.git
91 echo "Adding upstream..."
92 git remote add upstream https
://github.com
/civicrm
/civicrm-core.git
94 echo "Fetching upstream..."
97 # Extract tag and branch information
98 echo "Latest upstream tag version:"
99 tag
=$
(git tag
--sort=-committerdate |
head -n 1)
100 # To manually upgrade to a different version, hardcode tag. Comment above and uncomment below.
104 # git tag --sort=-committerdate | head -n 1
105 # List all tags starting with the most recent.
107 # Output example: 5.17.0
110 # Check for previous attempts
111 if ls -d .
/*$tag 1> /dev
/null
2>&1; then
112 echo "Interactively removing folders that match $tag..."
113 echo "Remove these directories?"
114 ls -d .
/*$tag |
xargs -p -n1 rm -r
117 echo "Renaming folder civicrm-core-$tag..."
118 mv civicrm-core civicrm-core-
$tag
122 # echo "Latest upstream branch:"
123 # git branch -a --sort=-committerdate | head -n 1 | sed 's/ remotes\///'
125 # git branch -a --sort=-committerdate | sed -n '2p;3q' | sed 's/ remotes\///'
126 # List all branches starting with the most recent.
127 # Print 2nd line (faster than head -n 2 | tail -n 1).
128 # Remove blankspace and remotes from the beginning.
130 echo "Latest production branch:"
131 pbranchfsf
=$
(git branch
-a --sort=-committerdate |
grep 'fsf$' |
head -n 1 |
sed 's/ remotes\///')
134 # git branch -a --sort=-committerdate | grep 'fsf$' | head -n 1 | sed 's/ remotes\///'
135 # List all branches starting with the most recent.
136 # Print only lines that end with `fsf`.
138 # Remove blankspace and `remotes/` from the beginning.
139 # Output example: origin/5.16.3-fsf
141 echo "Creating production branch variable..."
142 pbranch
=$
(echo $pbranchfsf |
sed 's/origin\///' |
sed 's/-fsf//')
145 # Same as git branch -a --sort=-committerdate | grep 'fsf$' | head -n 1 | sed 's/ remotes\/origin\///' | sed 's/-fsf//'
146 # Output example: 5.16.3
148 # Check if latest tag and latest production branch are the same.
149 if [ "$pbranch" = "$tag" ]; then
150 echo "You are currently using the latest tag in produciton!"
151 echo "Script is exiting..."
155 # List commits between updates
156 echo "Abbreviated commit lines between tag $pbranch and tag $tag..."
157 git
--no-pager log
$pbranch..
$tag --pretty=oneline
--abbrev-commit
160 # Prepare work branch
163 echo "Creating temp branch..."
164 git checkout
-b $tag-fsf-$my_name-attempt-a
167 echo "Ready to start rebasing!"
168 echo "Our rebase command:"
169 echo "git rebase --onto $tag-fsf-$my_name-attempt-a $pbranch $pbranchfsf"
171 # DEBUG - Use this line with hard values instead of the following line to force
173 # git rebase --onto $tag-fsf-$my_name-attempt-a 4.6.29 origin/4.6.29-fsf
175 git rebase
--onto $tag-fsf-$my_name-attempt-a $pbranch $pbranchfsf
178 # If a merge conflict occurs, open a prompt to manually handle the conflicts.
179 if [ $
(tail -n 5 $logfile |
grep -e skip
-e continue -e abort |
wc -l) -gt 2 ]; then
180 echo "A merge conflict occurred, resolve and follow directions."
181 echo "Run 'meld .' without quotes to visually view conflicts with a GUI."
182 echo "Run 'exit' without quotes to continue with the script."
185 echo "A merge conflict did not occur! This simplifies things."
187 # TODO Feature Request
188 # If running dry-run as a cronjob, notifying whether there is a merge conflict
189 # or not would be useful. This would require a change in logic.
191 # Applying changes to a new branch name
192 echo "Creating new branch $tag-fsf-$my_name-attempt-0..."
193 git checkout
-b $tag-fsf-$my_name-attempt-0
195 echo "Removing temp branch..."
196 git branch
-d $tag-fsf-$my_name-attempt-a
200 # List differences between upstream and the rebased changes
201 echo "Differences between upstream tag $tag and our new"
202 echo "branch $tag-fsf-$my_name-attempt-0..."
203 git
--no-pager diff $tag $tag-fsf-$my_name-attempt-0
206 # Push attempt branch to VCS
207 if [[ $1 != "--dry-run" ]]; then
208 echo "Pushing branch $tag-fsf-$my_name-attempt-0 to origin..."
209 git push
-u origin
$tag-fsf-$my_name-attempt-0
211 echo "Skipping git push..."
214 echo "Creating new branch $tag-fsf..."
217 # Push fsf branch to VCS
218 # If multiple people are attempting, comment this section out and review with
219 # git diff between the attempt branches.
220 if [[ $1 != "--dry-run" ]]; then
221 echo "Pushing branch $tag-fsf to origin..."
222 git push
-u origin
$tag-fsf
224 echo "Skipping git push..."
227 # Creating live branch
228 echo "Creating new branch live-$tag..."
230 echo "NOTE: live-$tag is not pushed through this script."
233 echo "Leaving directory..."
236 echo "Creating packaging directory civicrm-pkg-$tag..."
237 mkdir
-p civicrm-pkg-
$tag
240 echo "Downloading latest tarball..."
241 if [ ! -f "civicrm-$tag-drupal.tar.gz" ]; then
242 wget
-q https
://download.civicrm.org
/civicrm-
$tag-drupal.
tar.gz
245 echo "Extracting tarball..."
246 tar xzf civicrm-
$tag-drupal.
tar.gz
248 echo "Overlaying our code on top the upstream tarball..."
249 rsync
-avrSPX ..
/civicrm-core-
$tag/* civicrm
/
251 echo "Ensuring that civicrm/civicrm directory does not exist..."
252 if [ -d "civicrm/civicrm" ]; then
253 echo "The directory civicrm/civicrm exists!"
257 # Add the trustcommerceIPN.php script from the live branch
258 if [ -d "tc-ipn-receiver" ]; then
259 echo "Removing tc-ipn-receiver folder..."
260 rm -fr tc-ipn-receiver
262 echo "Cloning tc-ipn-receiver..."
263 git clone git@vcs.fsf.org
:tc-ipn-receiver.git
265 echo "Changing to live branch..."
268 echo "Copying trustcommerceIPN.php to civicrm/CRM/Core/Payment/..."
270 cp tc-ipn-receiver
/trustcommerceIPN.php civicrm
/CRM
/Core
/Payment
/
272 echo "Creating the tarball..."
273 tar czf civicrm-
${tag}_fsf.
tar.gz civicrm
275 # Push the package to crmserver4d
276 if [[ $1 != "--dry-run" ]]; then
277 echo "Uploading the package to crmserver4d..."
278 scp civicrm-
${tag}_fsf.
tar.gz root@crmserver4d.fsf.org
:/root
/
280 echo "Skipping this command, due to dry-run:"
281 echo " scp civicrm-${tag}_fsf.tar.gz root@crmserver4d.fsf.org:/root/"
284 # Logfile maintenance
285 echo "Shrinking the logfile..."
286 sed -i -E 's/.{37}0:00:00 //g' $logfile # rsync transfer speed/estimates
288 echo "Copying $logfile to the civicrm-pkg-$tag directory..."
292 # Instructions to continue
293 echo "Script is complete! Double check the"
294 echo "civicrm-pkg-$tag/$(echo $logfile | sed 's/\/tmp\///') file"
295 echo "before applying changes. Once verified, continue following the"
296 echo "workflow at https://gluestick.office.fsf.org/hosts/services/civicrm/upgrading/"
297 echo "by testing in the development server."