|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ |
| 4 | +set -euo pipefail |
| 5 | + |
| 6 | +if [[ "$#" -ne 2 ]]; then |
| 7 | + echo "Usage: $0 <old-version> <new-version>" |
| 8 | + exit 1 |
| 9 | +fi |
| 10 | + |
| 11 | +OLD_VERSION="$1" |
| 12 | +NEW_VERSION="$2" |
| 13 | + |
| 14 | +# Users can set their own SED_IN_PLACE, for example, if their GNU sed is `gsed` |
| 15 | +if [[ -z "${SED_IN_PLACE[@]+"${SED_IN_PLACE[@]}"}" ]]; then |
| 16 | + if [[ "$(uname)" == "Darwin" ]]; then |
| 17 | + # BSD sed requires a space between -i and the backup extension |
| 18 | + SED_IN_PLACE=(sed -i "") |
| 19 | + else |
| 20 | + # Assume everything else has GNU sed, where the backup extension is optional |
| 21 | + SED_IN_PLACE=(sed --in-place) |
| 22 | + fi |
| 23 | +fi |
| 24 | + |
| 25 | +echo "Current directory: $(pwd)" |
| 26 | +if [[ ! -d "./crates/subspace-node" ]] || [[ ! -d "./crates/subspace-gateway" ]] || [[ ! -d "./crates/subspace-farmer" ]] || [[ ! -d "./crates/subspace-bootstrap-node" ]]; then |
| 27 | + echo "Changing to the root of the repository:" |
| 28 | + cd "$(dirname "$0")/.." |
| 29 | + echo "Current directory: $(pwd)" |
| 30 | + if [[ ! -d "./crates/subspace-node" ]] || [[ ! -d "./crates/subspace-gateway" ]] || [[ ! -d "./crates/subspace-farmer" ]] || [[ ! -d "./crates/subspace-bootstrap-node" ]]; then |
| 31 | + echo "Missing ./crates/subspace-node, ./crates/subspace-gateway, ./crates/subspace-farmer or ./crates/subspace-bootstrap-node" |
| 32 | + echo "This script must be run from the base of an autonomys/subspace repository checkout" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | +fi |
| 36 | + |
| 37 | +# show executed commands |
| 38 | +set -x |
| 39 | + |
| 40 | +echo "Replacing the old version ($OLD_VERSION) with the new version ($NEW_VERSION) in binary crates:" |
| 41 | +"${SED_IN_PLACE[@]}" -e "s/$OLD_VERSION/$NEW_VERSION/g" \ |
| 42 | + ./crates/subspace-node/Cargo.toml \ |
| 43 | + ./crates/subspace-gateway/Cargo.toml \ |
| 44 | + ./crates/subspace-farmer/Cargo.toml \ |
| 45 | + ./crates/subspace-bootstrap-node/Cargo.toml || (echo "'$SED_IN_PLACE' failed, please set \$SED_IN_PLACE to a valid sed in-place replacement command" && exit 1) |
| 46 | + |
| 47 | +echo "Updating Cargo.lock..." |
| 48 | +cargo check |
| 49 | + |
| 50 | +echo "Making sure the old version is not used anywhere else:" |
| 51 | +if ! grep --recursive --exclude-dir=target --exclude-dir=.git --exclude=Cargo.lock --exclude=Cargo.toml --fixed-strings "$OLD_VERSION" .; then |
| 52 | + # Stop showing executed commands |
| 53 | + set +x |
| 54 | + echo |
| 55 | + echo "===================================" |
| 56 | + echo "Success: all old versions replaced." |
| 57 | + echo "===================================" |
| 58 | + echo |
| 59 | +else |
| 60 | + echo |
| 61 | + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" |
| 62 | + echo "Error: The old version ($OLD_VERSION) is still in use." |
| 63 | + echo "Please update this script ($0) to automatically replace it." |
| 64 | + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" |
| 65 | + echo |
| 66 | + exit 1 |
| 67 | +fi |
0 commit comments