Compare commits
3 Commits
034b035a91
...
940cef138e
| Author | SHA1 | Date | |
|---|---|---|---|
| 940cef138e | |||
| 296e460326 | |||
| 738e622fdc |
49
bootstrap.sh
Executable file
49
bootstrap.sh
Executable file
@@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# shellcheck disable=SC2002
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
set -o pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
# print useful message on failure
|
||||||
|
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
# cd "$DIR"
|
||||||
|
here="$PWD"
|
||||||
|
|
||||||
|
"$DIR/update-cached-repository.sh"
|
||||||
|
|
||||||
|
# repository="${2:-https://gitea.philologue.net/philologue/diachron}"
|
||||||
|
repository="${2:-$HOME/.cache/diachron/v1/repositories/diachron.git}"
|
||||||
|
ref="${1:-hydrators-kysely}"
|
||||||
|
|
||||||
|
echo will bootstrap ref "$ref" of repo "$repository"
|
||||||
|
|
||||||
|
into=$(mktemp -d)
|
||||||
|
cd "$into"
|
||||||
|
echo I am in $(pwd)
|
||||||
|
echo I will clone repository "$repository", ref "$ref"
|
||||||
|
git clone "$repository"
|
||||||
|
|
||||||
|
r=$(ls -1)
|
||||||
|
|
||||||
|
cd "$r"
|
||||||
|
|
||||||
|
echo I am in $(pwd)
|
||||||
|
|
||||||
|
git checkout "$ref"
|
||||||
|
|
||||||
|
ls
|
||||||
|
echo working dir: $PWD
|
||||||
|
# ls backend
|
||||||
|
|
||||||
|
# exit 0
|
||||||
|
|
||||||
|
tar cvf - $(cat "$PWD/file-list" | grep -v '^#') | (cd "$here" && tar xf -)
|
||||||
|
|
||||||
|
echo "$ref" > .diachron-version
|
||||||
|
|
||||||
|
echo "Now, run the command ./sync.sh"
|
||||||
@@ -5,10 +5,12 @@ backend/package.json
|
|||||||
backend/pnpm-workspace.yaml
|
backend/pnpm-workspace.yaml
|
||||||
# express/framework
|
# express/framework
|
||||||
cmd
|
cmd
|
||||||
|
file-list
|
||||||
develop
|
develop
|
||||||
diachron
|
diachron
|
||||||
logger
|
logger
|
||||||
master
|
master
|
||||||
mgmt
|
mgmt
|
||||||
sync.sh
|
sync.sh
|
||||||
templates
|
templates
|
||||||
|
upgrade.sh
|
||||||
|
|||||||
22
update-cached-repository.sh
Executable file
22
update-cached-repository.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
set -o pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
|
||||||
|
|
||||||
|
upstream=https://gitea.philologue.net/philologue/diachron
|
||||||
|
cache_dir="$HOME/.cache/diachron/v1/repositories"
|
||||||
|
cached_repo="$cache_dir/diachron.git"
|
||||||
|
|
||||||
|
mkdir -p "$cache_dir"
|
||||||
|
|
||||||
|
if [ -d "$cached_repo" ]; then
|
||||||
|
echo "Updating cached repository..."
|
||||||
|
git -C "$cached_repo" fetch --prune origin
|
||||||
|
else
|
||||||
|
echo "Creating cached repository..."
|
||||||
|
git clone --mirror "$upstream" "$cached_repo"
|
||||||
|
fi
|
||||||
|
|
||||||
113
upgrade.sh
Normal file → Executable file
113
upgrade.sh
Normal file → Executable file
@@ -1,38 +1,109 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# shellcheck disable=SC2002
|
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
# print useful message on failure
|
|
||||||
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
|
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
cd "$DIR"
|
new_ref="${1:?Usage: upgrade.sh <new-ref>}"
|
||||||
|
|
||||||
# - Check if the file .diachron-version exists; save its value in a variable
|
cached_repo="$HOME/.cache/diachron/v1/repositories/diachron.git"
|
||||||
# named old_diachron_version
|
tmpdir=""
|
||||||
|
|
||||||
# - Check if the repository is dirty; if there are any files that git knows
|
cleanup() {
|
||||||
# about that have been changed but not committed, abort with a message
|
if [ -n "$tmpdir" ]; then
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
# - Get the current commit and store it in a variable
|
echo "=== Diachron Framework Upgrade ==="
|
||||||
|
echo ""
|
||||||
|
echo "This will replace all framework files in your project."
|
||||||
|
echo "Make sure you have committed or backed up any local changes."
|
||||||
|
echo ""
|
||||||
|
read -r -p "Continue? [y/N] " answer
|
||||||
|
if [[ ! "$answer" =~ ^[Yy]$ ]]; then
|
||||||
|
echo "Aborted."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# - Perform a two checkouts of
|
# Update cached repository
|
||||||
# https://gitea.philologue.net/philologue/diachron, each in its own
|
"$DIR/update-cached-repository.sh"
|
||||||
# temporary directory. We'll call one "old" and one "new"
|
|
||||||
|
|
||||||
# - In old, check out $old_diachron_version; in our working application
|
# Read current version
|
||||||
# directory, delete all of the files in file-list using git rm
|
if [ ! -f "$DIR/.diachron-version" ]; then
|
||||||
|
echo "Error: .diachron-version not found." >&2
|
||||||
|
echo "Is this a diachron project?" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
old_ref=$(cat "$DIR/.diachron-version")
|
||||||
|
|
||||||
# - In new, check out whatever was passed as argv[1]
|
# Verify both refs exist in cached repo
|
||||||
|
if ! git -C "$cached_repo" rev-parse --verify "$old_ref^{commit}" >/dev/null 2>&1; then
|
||||||
|
echo "Error: current version '$old_ref' not found in cached repository." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! git -C "$cached_repo" rev-parse --verify "$new_ref^{commit}" >/dev/null 2>&1; then
|
||||||
|
echo "Error: target version '$new_ref' not found in cached repository." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# - Copy all of the files in file-list to the working application and stage
|
# Require a clean working tree
|
||||||
# them with git add
|
if [ -n "$(git -C "$DIR" status --porcelain)" ]; then
|
||||||
|
echo "Error: working tree is not clean." >&2
|
||||||
|
echo "Commit or stash all changes (including untracked files) before upgrading." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# - Commit
|
echo ""
|
||||||
|
echo "Upgrading: $old_ref -> $new_ref"
|
||||||
|
echo ""
|
||||||
|
|
||||||
# - Should we run sync.sh or should we advise the user to run sync.sh?
|
# Read current file-list (files to remove)
|
||||||
|
old_files=()
|
||||||
|
while IFS= read -r line; do
|
||||||
|
[[ "$line" =~ ^[[:space:]]*# ]] && continue
|
||||||
|
[[ -z "$line" ]] && continue
|
||||||
|
old_files+=("$line")
|
||||||
|
done < "$DIR/file-list"
|
||||||
|
|
||||||
|
# Clone and checkout new version into a temp directory
|
||||||
|
tmpdir=$(mktemp -d)
|
||||||
|
git clone --quiet "$cached_repo" "$tmpdir/diachron"
|
||||||
|
git -C "$tmpdir/diachron" checkout --quiet "$new_ref"
|
||||||
|
|
||||||
|
# Read new file-list (files to add)
|
||||||
|
new_files=()
|
||||||
|
while IFS= read -r line; do
|
||||||
|
[[ "$line" =~ ^[[:space:]]*# ]] && continue
|
||||||
|
[[ -z "$line" ]] && continue
|
||||||
|
new_files+=("$line")
|
||||||
|
done < "$tmpdir/diachron/file-list"
|
||||||
|
|
||||||
|
# Remove old framework files
|
||||||
|
for f in "${old_files[@]}"; do
|
||||||
|
git -C "$DIR" rm -rf --quiet --ignore-unmatch "$f"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Copy in new framework files
|
||||||
|
(cd "$tmpdir/diachron" && tar cvf - "${new_files[@]}") | (cd "$DIR" && tar xf -)
|
||||||
|
|
||||||
|
# Stage them
|
||||||
|
for f in "${new_files[@]}"; do
|
||||||
|
git -C "$DIR" add "$f"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Update version marker
|
||||||
|
echo "$new_ref" > "$DIR/.diachron-version"
|
||||||
|
git -C "$DIR" add "$DIR/.diachron-version"
|
||||||
|
|
||||||
|
echo "=== Upgrade staged: $old_ref -> $new_ref ==="
|
||||||
|
echo ""
|
||||||
|
echo "Framework files have been removed, replaced, and staged."
|
||||||
|
echo ""
|
||||||
|
echo "Next steps:"
|
||||||
|
echo " 1. Review: git diff --cached"
|
||||||
|
echo " 2. Commit: git commit -m 'Upgrade diachron to $new_ref'"
|
||||||
|
echo " 3. Install: ./sync.sh"
|
||||||
|
|||||||
Reference in New Issue
Block a user