migrate.sh: allow specifying an output file

This commit is contained in:
Chris Renshaw
2024-03-27 02:27:15 -03:00
committed by GitHub
parent 75cf629015
commit 8414785806

View File

@@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
case "$1" in case "$1" in
-h|--help|help) echo "sh migrate.sh [-f] [-a] [file]"; exit 0;; -h|--help|help) echo "sh migrate.sh [-f] [-a] [in-file] [out-file]"; exit 0;;
esac; esac;
N=" N="
@@ -28,7 +28,6 @@ esac;
if [ -f "$1" ]; then if [ -f "$1" ]; then
FILE="$1"; FILE="$1";
DIR="$1"; DIR="$1";
shift;
else else
case "$0" in case "$0" in
*.sh) DIR="$0";; *.sh) DIR="$0";;
@@ -38,6 +37,9 @@ fi;
DIR=$(dirname "$(readlink -f "$DIR")"); DIR=$(dirname "$(readlink -f "$DIR")");
[ -z "$FILE" ] && FILE="$DIR/custom.pif.json"; [ -z "$FILE" ] && FILE="$DIR/custom.pif.json";
OUT="$2";
[ -z "$OUT" ] && OUT="$DIR/custom.pif.json";
[ -f "$FILE" ] || die "No json file found"; [ -f "$FILE" ] || die "No json file found";
grep_check_json api_level && [ ! "$FORCE" ] && die "No migration required"; grep_check_json api_level && [ ! "$FORCE" ] && die "No migration required";
@@ -100,9 +102,9 @@ if [ -z "$DEVICE_INITIAL_SDK_INT" -o "$DEVICE_INITIAL_SDK_INT" = "null" ]; then
DEVICE_INITIAL_SDK_INT=25; DEVICE_INITIAL_SDK_INT=25;
fi; fi;
if [ -f "$DIR/custom.pif.json" ]; then if [ -f "$OUT" ]; then
item "Renaming old file to custom.pif.json.bak ..."; item "Renaming old file to $(basename "$OUT").bak ...";
mv -f "$DIR/custom.pif.json" "$DIR/custom.pif.json.bak"; mv -f "$OUT" "$OUT.bak";
fi; fi;
[ "$INSTALL" ] || item "Writing fields and properties to updated custom.pif.json ..."; [ "$INSTALL" ] || item "Writing fields and properties to updated custom.pif.json ...";
@@ -120,6 +122,6 @@ echo ' "*api_level": "'$DEVICE_INITIAL_SDK_INT'",';
if [ "$ADVANCED" ]; then if [ "$ADVANCED" ]; then
echo "$N // Advanced Settings"; echo "$N // Advanced Settings";
echo ' "verboseLogs": "0",'; echo ' "verboseLogs": "0",';
fi) | sed '$s/,/\n}/' > "$DIR/custom.pif.json"; fi) | sed '$s/,/\n}/' > "$OUT";
[ "$INSTALL" ] || cat "$DIR/custom.pif.json"; [ "$INSTALL" ] || cat "$OUT";