Browse Source

Try to show the file in the correct editor. Rename variables.

master
poikilos 3 years ago
parent
commit
e8ad71d7c3
  1. 207
      prepatch.sh

207
prepatch.sh

@ -53,18 +53,22 @@ done
if [ "@$enable_bare_param" = "@true" ]; then if [ "@$enable_bare_param" = "@true" ]; then
branch="$2" branch="$2"
fi fi
project0=Bucket_Game branchUpstream=bucket_game-211114a
project1=Bucket_Game-base branchBase=Bucket_Game-base
project2=Bucket_Game-branches branchHead=Bucket_Game-branches
# project0_path="$HOME/git/EnlivenMinetest/webapp/linux-minetest-kit/minetest/games/$project0" # project0_path="$HOME/git/EnlivenMinetest/webapp/linux-minetest-kit/minetest/games/$branchUpstream"
project0_path="$HOME/minetest/games/$project0" project0_path="$HOME/minetest/games/$branchUpstream"
tryUnpatched="$HOME/minetest/$branchUpstream"
if [ -d "$tryUnpatched" ]; then
project0_path="$tryUnpatched"
fi
#patches="$HOME/git/EnlivenMinetest/patches" #patches="$HOME/git/EnlivenMinetest/patches"
#patches="$HOME/git/1.pull-requests/Bucket_Game-branches" #patches="$HOME/git/1.pull-requests/Bucket_Game-branches"
repo="$HOME/git/EnlivenMinetest" repo="$HOME/git/EnlivenMinetest"
patches="$HOME/git/EnlivenMinetest" patches="$HOME/git/EnlivenMinetest"
project1_path="$repo/$project1/$branch" branchBasePath="$repo/$branchBase/$branch"
project2_path="$repo/$project2/$branch" branchHeadPath="$repo/$branchHead/$branch"
if [ "@$enable_meld" = "@true" ]; then if [ "@$enable_meld" = "@true" ]; then
echo "meld..." echo "meld..."
if [ -z "$branch" ]; then if [ -z "$branch" ]; then
@ -72,15 +76,15 @@ if [ "@$enable_meld" = "@true" ]; then
fi fi
subgame= subgame=
patch_game_src= patch_game_src=
if [ -d "$project1_path/mods" ]; then if [ -d "$branchBasePath/mods" ]; then
branch_basis="$project1_path" branch_basis="$branchBasePath"
fi fi
if [ -d "$project2_path/mods" ]; then if [ -d "$branchHeadPath/mods" ]; then
patch_game_src="$project2_path" patch_game_src="$branchHeadPath"
else else
customExit "Cannot detect mods directory in $project2_path/mods" customExit "Cannot detect mods directory in $branchHeadPath/mods"
fi fi
#below (commented part) should only happen if $project2_path already has been edited (diverged from $project1_path) #below (commented part) should only happen if $branchHeadPath already has been edited (diverged from $branchBasePath)
#echo "meld $patch_game_src/ $HOME/minetest/games/ENLIVEN..." #echo "meld $patch_game_src/ $HOME/minetest/games/ENLIVEN..."
#if [ -f "`command -v meld`" ]; then #if [ -f "`command -v meld`" ]; then
#if [ -f "`command -v nohup`" ]; then #if [ -f "`command -v nohup`" ]; then
@ -124,12 +128,12 @@ elif [ "@$enable_install" = "@true" ]; then
fi fi
echo "* installing $branch branch..." echo "* installing $branch branch..."
subgame= subgame=
if [ -d "$project2_path/mods" ]; then if [ -d "$branchHeadPath/mods" ]; then
patch_game_src="$project2_path" patch_game_src="$branchHeadPath"
elif [ -d "$project2_path/patched/mods" ]; then elif [ -d "$branchHeadPath/patched/mods" ]; then
patch_game_src="$project2_path/patched" patch_game_src="$branchHeadPath/patched"
else else
customExit "Cannot detect mods directory in $project2_path/mods" customExit "Cannot detect mods directory in $branchHeadPath/mods"
fi fi
echo "rsync -rt $patch_game_src/ $HOME/minetest/games/ENLIVEN..." echo "rsync -rt $patch_game_src/ $HOME/minetest/games/ENLIVEN..."
rsync -rt "$patch_game_src/" "$HOME/minetest/games/ENLIVEN" rsync -rt "$patch_game_src/" "$HOME/minetest/games/ENLIVEN"
@ -150,12 +154,12 @@ usage() {
echo "Usage:" echo "Usage:"
echo echo
echo "$me <file_path> <new-fake-branch-name>" echo "$me <file_path> <new-fake-branch-name>"
echo "* will be copied to $project1 and $project2" echo "* will be copied to $branchBase and $branchHead"
echo echo
echo "Example:" echo "Example:"
echo "$me mods/coderfood/food_basic/init.lua milk-patch" echo "$me mods/coderfood/food_basic/init.lua milk-patch"
echo echo
echo "* copies the file to $project1 and $project2)" echo "* copies the file to $branchBase and $branchHead)"
echo "* also copies $licenses and same in .. and ../.." echo "* also copies $licenses and same in .. and ../.."
echo echo
echo echo
@ -172,111 +176,136 @@ if [ -z "$2" ]; then
exit 1 exit 1
fi fi
file0_path="$project0_path/$what" branchUpstreamFilePath="$project0_path/$what"
file1_path="$project1_path/$what" branchBaseFilePath="$branchBasePath/$what"
file2_path="$project2_path/$what" branchHeadFilePath="$branchHeadPath/$what"
whatname=`basename $file0_path` whatname=`basename $branchUpstreamFilePath`
date_string=$(date +%Y%m%d) date_string=$(date +%Y%m%d)
patchcmd="diff -u $file1_path $file2_path > $patches/$project0-$date_string-$whatname.patch" patchcmd="diff -u $branchBaseFilePath $branchHeadFilePath > $patches/$branchUpstream-$date_string-$whatname.patch"
echo echo
echo "After editing $file2_path, then create a patch by running:" echo "After editing $branchHeadFilePath, then create a patch by running:"
echo "$patchcmd" echo "$patchcmd"
echo echo
echo "* getting parent of $file0_path..." echo "* getting parent of $branchUpstreamFilePath..."
dir0="$(dirname -- "$(realpath -- "$file0_path")")" dirUpstream="$(dirname -- "$(realpath -- "$branchUpstreamFilePath")")"
# can't get realpath when directory doesn't exist yet (we make it): # can't get realpath when directory doesn't exist yet (we make it):
dir1="$(dirname -- "$file1_path")" dirBase="$(dirname -- "$branchBaseFilePath")"
dir2="$(dirname -- "$file2_path")" dirHead="$(dirname -- "$branchHeadFilePath")"
dir0_p="$(dirname -- "$(realpath -- "$dir0")")" dirUpstreamParent="$(dirname -- "$(realpath -- "$dirUpstream")")"
dir1_p="$(dirname -- "$dir1")" dirBaseParent="$(dirname -- "$dirBase")"
dir2_p="$(dirname -- "$dir2")" dirHeadParent="$(dirname -- "$dirHead")"
dir0_pp="$(dirname -- "$(realpath -- "$dir0_p")")" dirUpstreamGrandParent="$(dirname -- "$(realpath -- "$dirUpstreamParent")")"
dir1_pp="$(dirname -- "$dir1_p")" dirBaseGrandParent="$(dirname -- "$dirBaseParent")"
dir2_pp="$(dirname -- "$dir2_p")" dirHeadGrandParent="$(dirname -- "$dirHeadParent")"
#echo "* checking $dir0_pp..." #echo "* checking $dirUpstreamGrandParent..."
#echo "* checking $dir1_pp..." #echo "* checking $dirBaseGrandParent..."
#echo "* checking $dir2_pp..." #echo "* checking $dirHeadGrandParent..."
if [ ! -d "$project0_path" ]; then if [ ! -d "$project0_path" ]; then
customExit "ERROR: You must have '$project0' installed as '$project0_path'" customExit "ERROR: You must have '$branchUpstream' installed as '$project0_path'"
fi fi
if [ ! -f "$file0_path" ]; then if [ ! -f "$branchUpstreamFilePath" ]; then
customExit "ERROR: Missing '$file0_path')" customExit "ERROR: Missing '$branchUpstreamFilePath')"
fi fi
if [ ! -d "$dir1" ]; then if [ ! -d "$dirBase" ]; then
mkdir -p "$dir1" || customExit "Cannot mkdir $dir1" mkdir -p "$dirBase" || customExit "Cannot mkdir $dirBase"
fi fi
if [ ! -d "$dir2" ]; then if [ ! -d "$dirHead" ]; then
mkdir -p "$dir2" || customExit "Cannot mkdir $dir2" mkdir -p "$dirHead" || customExit "Cannot mkdir $dirHead"
fi fi
# if file1 exists, overwriting is ok--update basis so diff will make patch correctly # if file1 exists, overwriting is ok--update basis so diff will make patch correctly
echo "* updating $file1_path" echo "* updating $branchBaseFilePath"
cp -f "$file0_path" "$file1_path" || customExit "Cannot cp '$file0_path' '$file1_path'" cp -f "$branchUpstreamFilePath" "$branchBaseFilePath" || customExit "Cannot cp '$branchUpstreamFilePath' '$branchBaseFilePath'"
if [ -f "$file2_path" ]; then openImageAsync(){
customExit "Nothing done since '$file2_path' already exists." lximage-qt "$1" &
fi }
echo "* creating $file2_path"
cp -f "$file0_path" "$file2_path" || customExit "Cannot cp '$file0_path' '$file2_path'" openTextAsync(){
if [ -f "`command -v zbstudio`" ]; then if [ -f "`command -v zbstudio`" ]; then
nohup zbstudio "$file2_path" & nohup zbstudio "$1" &
else else
if [ -f "`command -v geany`" ]; then if [ -f "`command -v geany`" ]; then
nohup geany "$file2_path" & nohup geany "$1" &
fi
fi
}
if [ -f "$branchHeadFilePath" ]; then
if [ -f "`command -v lximage-qt`" ]; then
openImageAsync "$branchHeadFilePath"
fi
customExit "Nothing done since '$branchHeadFilePath' already exists."
fi
echo "* creating $branchHeadFilePath"
cp -f "$branchUpstreamFilePath" "$branchHeadFilePath" || customExit "Cannot cp '$branchUpstreamFilePath' '$branchHeadFilePath'"
gotMimeType="`mimetype -b $branchHeadFilePath`"
if [ "$gotMimeType" = "image/png" ]; then
if [ -f "`command -v lximage-qt`" ]; then
openImageAsync "$branchHeadFilePath"
fi
elif [ "$gotMimeType" = "image/jpeg" ]; then
if [ -f "`command -v lximage-qt`" ]; then
openImageAsync "$branchHeadFilePath"
fi fi
elif [ "$gotMimeType" = "image/bmp" ]; then
if [ -f "`command -v lximage-qt`" ]; then
openImageAsync "$branchHeadFilePath"
fi fi
else
openTextAsync "$branchHeadFilePath"
if [ -d "$HOME/minetest/games/ENLIVEN" ]; then if [ -d "$HOME/minetest/games/ENLIVEN" ]; then
if [ -f "`command -v meld`" ]; then if [ -f "`command -v meld`" ]; then
nohup meld "$file2_path" "$HOME/minetest/games/ENLIVEN/$what" & nohup meld "$branchHeadFilePath" "$HOME/minetest/games/ENLIVEN/$what" &
fi
fi fi
fi fi
eval "arr=($licenses)" eval "arr=($licenses)"
for license in "${arr[@]}"; do for license in "${arr[@]}"; do
lic0="$dir0/$license" upstreamLicense="$dirUpstream/$license"
lic1="$dir1/$license" baseLicense="$dirBase/$license"
lic2="$dir2/$license" headLicense="$dirHead/$license"
if [ -f "$lic0" ]; then if [ -f "$upstreamLicense" ]; then
echo "* updating LICENSE '$lic1'..." echo "* updating LICENSE '$baseLicense'..."
cp -f "$lic0" "$lic1" || customExit "Cannot cp -f '$lic0' '$lic1'" cp -f "$upstreamLicense" "$baseLicense" || customExit "Cannot cp -f '$upstreamLicense' '$baseLicense'"
if [ ! -f "$lic2" ]; then if [ ! -f "$headLicense" ]; then
echo " - also for $project2..." echo " - also for $branchHead..."
cp --no-clobber "$lic0" "$lic2" || customExit "Cannot cp -f '$lic0' '$lic2'" cp --no-clobber "$upstreamLicense" "$headLicense" || customExit "Cannot cp -f '$upstreamLicense' '$headLicense'"
fi fi
fi fi
lic0="$dir0_p/$license" upstreamLicense="$dirUpstreamParent/$license"
lic1="$dir1_p/$license" baseLicense="$dirBaseParent/$license"
lic2="$dir2_p/$license" headLicense="$dirHeadParent/$license"
if [ -f "$lic0" ]; then if [ -f "$upstreamLicense" ]; then
echo "* updating LICENSE '$lic1'..." echo "* updating LICENSE '$baseLicense'..."
cp -f "$lic0" "$lic1" || customExit "Cannot cp -f '$lic0' '$lic1'" cp -f "$upstreamLicense" "$baseLicense" || customExit "Cannot cp -f '$upstreamLicense' '$baseLicense'"
if [ ! -f "$lic2" ]; then if [ ! -f "$headLicense" ]; then
echo " - also for $project2..." echo " - also for $branchHead..."
cp --no-clobber "$lic0" "$lic2" || customExit "Cannot cp -f '$lic0' '$lic2'" cp --no-clobber "$upstreamLicense" "$headLicense" || customExit "Cannot cp -f '$upstreamLicense' '$headLicense'"
fi fi
fi fi
lic0="$dir0_pp/$license" upstreamLicense="$dirUpstreamGrandParent/$license"
lic1="$dir1_pp/$license" baseLicense="$dirBaseGrandParent/$license"
lic2="$dir2_pp/$license" headLicense="$dirHeadGrandParent/$license"
if [ -f "$lic0" ]; then if [ -f "$upstreamLicense" ]; then
echo "* updating '$lic1'..." echo "* updating '$baseLicense'..."
cp -f "$lic0" "$lic1" || customExit "Cannot cp -f '$lic0' '$lic1'" cp -f "$upstreamLicense" "$baseLicense" || customExit "Cannot cp -f '$upstreamLicense' '$baseLicense'"
if [ ! -f "$lic2" ]; then if [ ! -f "$headLicense" ]; then
echo " - also for $project2..." echo " - also for $branchHead..."
cp --no-clobber "$lic0" "$lic2" || customExit "Cannot cp -f '$lic0' '$lic2'" cp --no-clobber "$upstreamLicense" "$headLicense" || customExit "Cannot cp -f '$upstreamLicense' '$headLicense'"
fi fi
fi fi
done done
echo "Done." echo "Done."
echo "To apply, set BUCKET_GAME then:" echo "To apply, set BUCKET_GAME then:"
echo "cd EnlivenMinetest && git pull && rsync -rt Bucket_Game-branches/$branch/ $BUCKET_GAME" echo "cd EnlivenMinetest && git pull && rsync -rt Bucket_Game-branches/$branch/ \$BUCKET_GAME"
echo echo

Loading…
Cancel
Save