Skip to content

Instantly share code, notes, and snippets.

@adunsulag
Forked from bradymiller/buildPatch
Last active August 23, 2022 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adunsulag/5b14d243db0996c16e03ec0f75e2bd26 to your computer and use it in GitHub Desktop.
Save adunsulag/5b14d243db0996c16e03ec0f75e2bd26 to your computer and use it in GitHub Desktop.
Build openemr patch
#!/bin/bash
#
# Copyright (C) 2022 Brady Miller <brady.g.miller@gmail.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# Script to build patch for openemr
#
# place this script in the official-patches directory and run it in that directory (bash buildPatch)
# - it will create a directory at patchDirectory(variable below) with the patch in it
#
# PATCH SETTINGS
patchFileName="7-0-0-Patch-2.zip"
versionStart="v7_0_0"
versionBranch="rel-700"
patchDirectory="official-patch-7-0-0-2"
copyStyles=false
copyVendor=false
rm -fr openemr
git clone https://github.com/openemr/openemr.git
cd openemr
if [ "$copyVendor" = true ] ; then
#we setup two directory versions of composer that we can compare against
#for our vendor patch
git checkout "$versionBranch"
composer install --no-dev
mv vendor vendor_dest
git checkout "$versionStart"
composer install --no-dev
fi
git checkout "$versionBranch"
listScripts=`git diff --name-only "$versionStart".."$versionBranch"`
echo "list of changed scripts:"
echo "$listScripts"
if [ "$copyStyles" = true ] ; then
# need to build the theme scripts
npm install --unsafe-perm
npm run build
fi
cd ../
echo "prepare the $patchDirectory directory"
rm -fr "$patchDirectory"
mkdir "$patchDirectory"
cd "$patchDirectory"
while read -r line; do
dirNameScript=`dirname "$line"`
if [ "$dirNameScript" != "." ] && [ ! -d "$dirNameScript" ]; then
echo "creating directory $dirNameScript"
mkdir -p "$dirNameScript"
fi
echo "bringing over $line into patch"
cp "../openemr/$line" "$line"
done <<< "$listScripts"
if [ "$copyStyles" = true ] ; then
echo "create public/themes directory and bring all the theme scripts over"
mkdir -p public/themes
cp -R ../openemr/public/themes/* public/themes/
fi
if [ "$copyVendor" = true ] ; then
echo "create vendor patch"
cd ../openemr/
# we use rsync and we base it on check-sum since timestamps won't help. We cut out the first 3 lines and last three lines
# to exclude rsync output that we don't care for
# This was tested on Ubuntu 22.04, should be POSIX compliant, but haven't tested it.
listVendor=`rsync --dry-run -auv --checksum vendor/ vendor_dest/ | tail -n +3 | head -n -3`
# clean things up
rm -rf ../openemr/vendor_dest/
cd "../$patchDirectory"
while read -r line; do
# skip anything that is just a directory so we don't break cp
if [ -d "../openemr/vendor/$line" ]; then
continue
fi
dirNameVendor=`dirname "vendor/$line"`
if [ "$dirNameVendor" != "." ] && [ ! -d "$dirNameVendor" ]; then
echo "creating directory $dirNameVendor"
mkdir -p "$dirNameVendor"
fi
echo "bringing over $line into patch"
cp "../openemr/vendor/$line" "vendor/$line"
done <<< "$listVendor"
echo "list of changed vendor files"
find vendor/ -type f
fi
echo "make setup.php blank"
> setup.php
echo "always bring over version.php"
cp ../openemr/version.php version.php
echo "always bring over sql_patch.php"
cp ../openemr/sql_patch.php sql_patch.php
echo "just to show you the number of files in the patch:"
find . -type f -print | wc -l
echo "just to show you all the files in the patch:"
find . -type f -print | cut -c 3- | sort
echo "dry run to show you command that will standardize permission:"
find . -type f -print0 | xargs -0 echo chmod 0644
echo "if above 2 commands look good, then running this to standardize permissions:"
find . -type f -print0 | xargs -0 chmod 0644
echo "building the $patchFileName patch:"
zip -r "$patchFileName" .
cd ../
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment