VectorCraft: An open-source, vector art tool written by scratch in pure Rust
packaging: use [[ for bash conditional tests (SonarCloud S7688) (#3853)
Dylan M. Taylorc6e6c23b99e3
diff --git a/packaging/env.sh b/packaging/env.shindex 9d84cd916..9d98ada1d 100644--- a/packaging/env.sh+++ b/packaging/env.sh@@ -22,7 +22,7 @@ workspace_version() {}VERSION="${VECTORCRAFT_VERSION:-$(workspace_version)}"-if [ -z "$VERSION" ]; then+if [[ -z "$VERSION" ]]; thenecho "error: could not read [workspace.package] version from $ROOT/Cargo.toml" >&2exit 1fi@@ -32,7 +32,7 @@ DIST="${DIST:-$ROOT/dist/release}"mkdir -p "$DIST"export DIST-if [ -z "${VECTORCRAFT_BUILD_SHA:-}" ]; then+if [[ -z "${VECTORCRAFT_BUILD_SHA:-}" ]]; thenVECTORCRAFT_BUILD_SHA="$(git -C "$ROOT" rev-parse HEAD 2>/dev/null || true)"fiexport VECTORCRAFT_BUILD_SHA@@ -41,16 +41,16 @@ export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$ROOT/target}"# Emit a GitHub Actions warning (plain stderr outside Actions).warn() {- if [ -n "${GITHUB_ACTIONS:-}" ]; then echo "::warning::$*"; else echo "warning: $*" >&2; fi+ if [[ -n "${GITHUB_ACTIONS:-}" ]]; then echo "::warning::$*"; else echo "warning: $*" >&2; fi}# Copy licence and readme files that exist into a package directory.copy_docs() {local dest="$1" ffor f in README.md LICENSE LICENSE-MIT LICENSE-APACHE COPYRIGHT NOTICE ASSETS.md; do- if [ -f "$ROOT/$f" ]; then cp "$ROOT/$f" "$dest/"; fi+ if [[ -f "$ROOT/$f" ]]; then cp "$ROOT/$f" "$dest/"; fidone- if [ -d "$ROOT/licenses" ]; then+ if [[ -d "$ROOT/licenses" ]]; thenmkdir -p "$dest/licenses"cp -R "$ROOT/licenses/." "$dest/licenses/"fi@@ -61,9 +61,9 @@ copy_docs() {# the package, as OFL-<family dir>.txt. Nothing to do without it.copy_font_licences() {local dest="$1" ofl family- [ -n "${CRAFT_FONTS_DIR:-}" ] || return 0+ [[ -n "${CRAFT_FONTS_DIR:-}" ]] || return 0for ofl in "$CRAFT_FONTS_DIR"/fonts/*/OFL.txt; do- [ -f "$ofl" ] || continue+ [[ -f "$ofl" ]] || continuefamily="$(basename "$(dirname "$ofl")")"cp "$ofl" "$dest/OFL-$family.txt"donediff --git a/packaging/freebsd/package.sh b/packaging/freebsd/package.shindex 3e25edc1d..dffc56571 100755--- a/packaging/freebsd/package.sh+++ b/packaging/freebsd/package.sh@@ -19,7 +19,7 @@ LINUX="$ROOT/packaging/linux"APP_ID=ai.storyteller.vectorcraftSKIP_BUILD=0-while [ $# -gt 0 ]; do+while [[ $# -gt 0 ]]; docase "$1" in--skip-build) SKIP_BUILD=1; shift ;;-h | --help) sed -n '2,13p' "$0"; exit 0 ;;@@ -37,7 +37,7 @@ BASENAME="vectorcraft-$VERSION-freebsd-$ARCH"echo "==> VectorCraft $VERSION for FreeBSD $ARCH"-if [ "$SKIP_BUILD" = 0 ]; then+if [[ "$SKIP_BUILD" = 0 ]]; then(cd "$ROOT" && cargo build --release --locked -p vectorcraft -p vectorcraft-cli)fiBIN="$CARGO_TARGET_DIR/release"@@ -58,7 +58,7 @@ sed -e "s/@VERSION@/$VERSION/g" -e "s/@DATE@/$VECTORCRAFT_BUILD_DATE/g" \cp -R "$ROOT/assets/app-icon/hicolor" "$STAGE/share/icons/"copy_docs "$STAGE/share/doc/vectorcraft"for f in NOTICE ASSETS.md; do- if [ -f "$ROOT/$f" ]; then cp "$ROOT/$f" "$STAGE/share/doc/vectorcraft/"; fi+ if [[ -f "$ROOT/$f" ]]; then cp "$ROOT/$f" "$STAGE/share/doc/vectorcraft/"; fidone# ---- .tar.gz -------------------------------------------------------------------------------------diff --git a/packaging/linux/flatpak-bundle.sh b/packaging/linux/flatpak-bundle.shindex bb844193b..d5fddb473 100755--- a/packaging/linux/flatpak-bundle.sh+++ b/packaging/linux/flatpak-bundle.sh@@ -21,7 +21,7 @@ FLATHUB=https://dl.flathub.org/repo/flathub.flatpakrepoTEST=1TARBALL=""-while [ $# -gt 0 ]; do+while [[ $# -gt 0 ]]; docase "$1" in--no-test) TEST=0; shift ;;-h | --help) sed -n '2,14p' "$0"; exit 0 ;;@@ -38,7 +38,7 @@ case "$ARCH" inesacBASENAME="vectorcraft-$VERSION-linux-$ARCH"TARBALL="${TARBALL:-$DIST/$BASENAME.tar.gz}"-[ -f "$TARBALL" ] || { echo "error: $TARBALL not found (run packaging/linux/package.sh --formats tar first)" >&2; exit 1; }+[[ -f "$TARBALL" ]] || { echo "error: $TARBALL not found (run packaging/linux/package.sh --formats tar first)" >&2; exit 1; }for tool in flatpak flatpak-builder; docommand -v "$tool" >/dev/null || { echo "error: $tool not found (apt install flatpak flatpak-builder librsvg2-common)" >&2; exit 1; }done@@ -49,7 +49,7 @@ WORK="$CARGO_TARGET_DIR/flatpak-bundle"rm -rf "$WORK"mkdir -p "$WORK/stage"tar -xzf "$TARBALL" -C "$WORK/stage" --strip-components=1-[ -x "$WORK/stage/bin/vectorcraft" ] || { echo "error: $TARBALL has no bin/vectorcraft" >&2; exit 1; }+[[ -x "$WORK/stage/bin/vectorcraft" ]] || { echo "error: $TARBALL has no bin/vectorcraft" >&2; exit 1; }cp "$HERE/flatpak/$APP_ID.bundle.yml" "$WORK/$APP_ID.yml"flatpak remote-add --user --if-not-exists flathub "$FLATHUB"@@ -62,7 +62,7 @@ OUT="$DIST/$BASENAME.flatpak"flatpak build-bundle --runtime-repo="$FLATHUB" "$WORK/repo" "$OUT" "$APP_ID" stableecho "wrote $OUT"-if [ "$TEST" = 1 ]; then+if [[ "$TEST" = 1 ]]; thenflatpak install --user -y --noninteractive --reinstall "$OUT"flatpak info --user "$APP_ID"flatpak run --command=vectorcraft-cli "$APP_ID" --versiondiff --git a/packaging/linux/package.sh b/packaging/linux/package.shindex 56c5705a9..3f457be14 100755--- a/packaging/linux/package.sh+++ b/packaging/linux/package.sh@@ -25,7 +25,7 @@ APP_ID=ai.storyteller.vectorcraftSKIP_BUILD=0FORMATS="appimage deb rpm tar"-while [ $# -gt 0 ]; do+while [[ $# -gt 0 ]]; docase "$1" in--skip-build) SKIP_BUILD=1; shift ;;--formats) FORMATS="$2"; shift 2 ;;@@ -46,8 +46,8 @@ BASENAME="vectorcraft-$VERSION-linux-$ARCH"echo "==> VectorCraft $VERSION for Linux $ARCH ($FORMATS)"-if [ "$SKIP_BUILD" = 0 ]; then- if [ -n "${CROSS_TARGET:-}" ]; then+if [[ "$SKIP_BUILD" = 0 ]]; then+ if [[ -n "${CROSS_TARGET:-}" ]]; then(cd "$ROOT" && cargo build --release --locked -p vectorcraft -p vectorcraft-cli --target "$CROSS_TARGET")else(cd "$ROOT" && cargo build --release --locked -p vectorcraft -p vectorcraft-cli)@@ -114,9 +114,9 @@ if has appimage; thenln -s "$APP_ID.png" "$APPDIR/.DirIcon"TOOL="${APPIMAGETOOL:-$(command -v appimagetool || true)}"- if [ -z "$TOOL" ]; then+ if [[ -z "$TOOL" ]]; thenTOOL="$CARGO_TARGET_DIR/appimagetool-$ARCH.AppImage"- if [ ! -x "$TOOL" ]; then+ if [[ ! -x "$TOOL" ]]; thencurl --proto '=https' -fsSL -o "$TOOL" "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-$ARCH.AppImage"chmod +x "$TOOL"fi@@ -139,16 +139,16 @@ if has appimage; then# package) appimagetool also writes the .zsync, into its working directory, hence the cd.(cd "$DIST" && ARCH="$ARCH" APPIMAGE_EXTRACT_AND_RUN=1 "$TOOL" --no-appstream -u "$UPDATE_INFO" "$APPDIR" "$OUT")echo "wrote $OUT"- if [ -s "$OUT.zsync" ]; then+ if [[ -s "$OUT.zsync" ]]; thenecho "wrote $OUT.zsync"elsewarn "zsyncmake not found, so $OUT.zsync was not written; AppImage delta updates need it"fifi-if [ -z "${CROSS_TARGET:-}" ]; then+if [[ -z "${CROSS_TARGET:-}" ]]; then"$STAGE/usr/bin/vectorcraft-cli" --version-elif [ -n "${EMULATOR:-}" ]; then+elif [[ -n "${EMULATOR:-}" ]]; then"$EMULATOR" "$STAGE/usr/bin/vectorcraft-cli" --versionfiecho "==> done"diff --git a/packaging/macos/import-cert.sh b/packaging/macos/import-cert.shindex 3940a64a5..a2e18ee5e 100755--- a/packaging/macos/import-cert.sh+++ b/packaging/macos/import-cert.sh@@ -12,7 +12,7 @@ umask 077# shellcheck source=../env.sh. "$(dirname "${BASH_SOURCE[0]}")/../env.sh"-if [ -z "${APPLE_CERTIFICATE:-}" ]; then+if [[ -z "${APPLE_CERTIFICATE:-}" ]]; thenwarn "APPLE_CERTIFICATE is not set: macOS builds will be ad-hoc signed and not notarized"exit 0fi@@ -36,13 +36,13 @@ security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KC_PASS"security list-keychains -d user -s "$KEYCHAIN" $(security list-keychains -d user | tr -d '"')IDENTITY="$(security find-identity -v -p codesigning "$KEYCHAIN" | awk '/Developer ID Application/ { print $2; exit }')"-if [ -z "$IDENTITY" ]; then+if [[ -z "$IDENTITY" ]]; thensecurity find-identity -v -p codesigning "$KEYCHAIN" >&2echo "error: no 'Developer ID Application' identity in APPLE_CERTIFICATE" >&2exit 1fiecho "Imported signing identity $IDENTITY"-if [ -n "${GITHUB_ENV:-}" ]; then+if [[ -n "${GITHUB_ENV:-}" ]]; then{ echo "MACOS_SIGN_IDENTITY=$IDENTITY"; echo "MACOS_KEYCHAIN=$KEYCHAIN"; } >>"$GITHUB_ENV"elseecho "MACOS_SIGN_IDENTITY=$IDENTITY"diff --git a/packaging/macos/package.sh b/packaging/macos/package.shindex b824bd434..2ca11eed8 100755--- a/packaging/macos/package.sh+++ b/packaging/macos/package.sh@@ -19,7 +19,7 @@ HERE="$ROOT/packaging/macos"ARCH=universalSKIP_BUILD=0-while [ $# -gt 0 ]; do+while [[ $# -gt 0 ]]; docase "$1" in--arch) ARCH="$2"; shift 2 ;;--skip-build) SKIP_BUILD=1; shift ;;@@ -44,9 +44,9 @@ DMG="$DIST/vectorcraft-$VERSION-macos-$ARCH.dmg"CLI_ZIP="$DIST/vectorcraft-cli-$VERSION-macos-$ARCH.zip"NOTARIZE=0-if [ "$IDENTITY" = "-" ]; then+if [[ "$IDENTITY" = "-" ]]; thenwarn "macOS: ad-hoc signing (no MACOS_SIGN_IDENTITY); artifacts are not notarized"-elif [ -n "${APPLE_ID:-}" ] && [ -n "${APPLE_PASSWORD:-}" ] && [ -n "${APPLE_TEAM_ID:-}" ]; then+elif [[ -n "${APPLE_ID:-}" ]] && [[ -n "${APPLE_PASSWORD:-}" ]] && [[ -n "${APPLE_TEAM_ID:-}" ]]; thenNOTARIZE=1elsewarn "macOS: APPLE_ID / APPLE_PASSWORD / APPLE_TEAM_ID incomplete; signed but not notarized"@@ -55,7 +55,7 @@ fiecho "==> VectorCraft $VERSION for macOS ($ARCH), identity: $IDENTITY, notarize: $NOTARIZE"# ---- build --------------------------------------------------------------------------------------if [ "$SKIP_BUILD" = 0 ]; then+if [[ "$SKIP_BUILD" = 0 ]]; thenargs=()for t in "${TARGETS[@]}"; do args+=(--target "$t"); done(cd "$ROOT" && cargo build --release --locked -p vectorcraft -p vectorcraft-cli "${args[@]}")@@ -74,9 +74,9 @@ donesign() {# Hardened runtime + secure timestamp for a real identity; ad-hoc can't be timestamped.local ts=(--timestamp)- [ "$IDENTITY" = "-" ] && ts=(--timestamp=none)+ [[ "$IDENTITY" = "-" ]] && ts=(--timestamp=none)local kc=()- [ -n "${MACOS_KEYCHAIN:-}" ] && kc=(--keychain "$MACOS_KEYCHAIN")+ [[ -n "${MACOS_KEYCHAIN:-}" ]] && kc=(--keychain "$MACOS_KEYCHAIN")codesign --force --sign "$IDENTITY" ${kc[@]+"${kc[@]}"} "${ts[@]}" "$@"}@@ -88,8 +88,8 @@ notarize() {echo "$out"id="$(printf '%s' "$out" | plutil -extract id raw -o - - 2>/dev/null || true)"status="$(printf '%s' "$out" | plutil -extract status raw -o - - 2>/dev/null || true)"- if [ "$status" != "Accepted" ]; then- if [ -n "$id" ]; then+ if [[ "$status" != "Accepted" ]]; then+ if [[ -n "$id" ]]; thenxcrun notarytool log "$id" --apple-id "$APPLE_ID" --password "$APPLE_PASSWORD" --team-id "$APPLE_TEAM_ID" || truefiecho "error: notarization of $(basename "$file") failed (status: ${status:-unknown})" >&2@@ -104,7 +104,7 @@ stapler_retry() {local tryfor try in 1 2 3 4; doxcrun stapler "$1" "$2" && return 0- [ "$try" = 4 ] && break+ [[ "$try" = 4 ]] && breakecho "stapler $1 failed (try $try of 4); retrying in $((try * 20)) s" >&2sleep $((try * 20))done@@ -132,7 +132,7 @@ sign --options runtime --entitlements "$HERE/entitlements.plist" "$APP/Contents/sign --options runtime --entitlements "$HERE/entitlements.plist" "$APP"codesign --verify --strict --deep --verbose=2 "$APP"-if [ "$NOTARIZE" = 1 ]; then+if [[ "$NOTARIZE" = 1 ]]; thenditto -c -k --keepParent "$APP" "$WORK/VectorCraft-notarize.zip"notarize "$WORK/VectorCraft-notarize.zip"stapler_retry staple "$APP"@@ -165,7 +165,7 @@ hdiutil_retry() {if hdiutil "$@"; thenreturn 0fi- [ "$attempt" = 5 ] && { echo "hdiutil $what failed 5 times" >&2; return 1; }+ [[ "$attempt" = 5 ]] && { echo "hdiutil $what failed 5 times" >&2; return 1; }echo "hdiutil $what failed (attempt $attempt of 5); retrying in $((attempt * 10))s" >&2sleep $((attempt * 10))done@@ -183,7 +183,7 @@ if ! codesign --verify --strict --deep --verbose=2 "$MOUNT/VectorCraft.app"; theexit 1fihdiutil_retry detach detach "$MOUNT" >/dev/null-if [ "$NOTARIZE" = 1 ]; then+if [[ "$NOTARIZE" = 1 ]]; thennotarize "$DMG"stapler_retry staple "$DMG"stapler_retry validate "$DMG"@@ -201,7 +201,7 @@ codesign --verify --strict --verbose=2 "$CLI_DIR/vectorcraft-cli"rm -f "$CLI_ZIP"ditto -c -k --keepParent "$CLI_DIR" "$CLI_ZIP"# A bare Mach-O can't carry a stapled ticket; Gatekeeper looks the notarization up online.-if [ "$NOTARIZE" = 1 ]; then notarize "$CLI_ZIP"; fi+if [[ "$NOTARIZE" = 1 ]]; then notarize "$CLI_ZIP"; fi"$WORK/bin/vectorcraft-cli" --versionecho "==> done"diff --git a/packaging/web/package.sh b/packaging/web/package.shindex ea6ce8a52..d7630dd10 100755--- a/packaging/web/package.sh+++ b/packaging/web/package.sh@@ -11,13 +11,13 @@ set -euo pipefail. "$(dirname "${BASH_SOURCE[0]}")/../env.sh"HERE="$ROOT/packaging/web"-if [ "${1:-}" != "--skip-build" ]; then+if [[ "${1:-}" != "--skip-build" ]]; thencommand -v trunk >/dev/null || { echo "error: trunk not found (cargo install trunk --locked)" >&2; exit 1; }(cd "$ROOT/apps/vectorcraft-web" && trunk build --release)fiSITE="$ROOT/dist/web"-[ -f "$SITE/index.html" ] || { echo "error: $SITE/index.html missing; run without --skip-build" >&2; exit 1; }+[[ -f "$SITE/index.html" ]] || { echo "error: $SITE/index.html missing; run without --skip-build" >&2; exit 1; }# Paths must be relative so the site works under any prefix (public_url = "./" in Trunk.toml).if grep -Eq '(src|href)="/[^/]' "$SITE/index.html"; thenecho "error: $SITE/index.html has root-absolute URLs; it would break when served from a sub-path" >&2