FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
packaging: use [[ for bash conditional tests (SonarCloud S7688) (#3003)
Dylan M. Taylor4d089668a84a
diff --git a/packaging/env.sh b/packaging/env.shindex d227a71ab..702318cde 100644--- a/packaging/env.sh+++ b/packaging/env.sh@@ -22,7 +22,7 @@ workspace_version() {}VERSION="${FILMCRAFT_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 "${FILMCRAFT_BUILD_SHA:-}" ]; then+if [[ -z "${FILMCRAFT_BUILD_SHA:-}" ]]; thenFILMCRAFT_BUILD_SHA="$(git -C "$ROOT" rev-parse HEAD 2>/dev/null || true)"fiexport FILMCRAFT_BUILD_SHA@@ -41,7 +41,7 @@ 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, plus the licences of the@@ -49,7 +49,7 @@ warn() {copy_docs() {local dest="$1" ffor f in README.md LICENSE LICENSE-MIT LICENSE-APACHE COPYRIGHT; do- if [ -f "$ROOT/$f" ]; then cp "$ROOT/$f" "$dest/"; fi+ if [[ -f "$ROOT/$f" ]]; then cp "$ROOT/$f" "$dest/"; fidonecopy_font_licences "$dest"}@@ -58,9 +58,9 @@ copy_docs() {# Does nothing without CRAFT_FONTS_DIR.copy_font_licences() {local dest="$1" lic family- if [ -z "${CRAFT_FONTS_DIR:-}" ]; then return 0; fi+ if [[ -z "${CRAFT_FONTS_DIR:-}" ]]; then return 0; fifor lic in "$CRAFT_FONTS_DIR"/fonts/*/OFL.txt; do- [ -f "$lic" ] || continue+ [[ -f "$lic" ]] || continuefamily="$(basename "$(dirname "$lic")")"cp "$lic" "$dest/OFL-$family.txt"donediff --git a/packaging/freebsd/package.sh b/packaging/freebsd/package.shindex 36835b5aa..ab24da426 100755--- a/packaging/freebsd/package.sh+++ b/packaging/freebsd/package.sh@@ -20,7 +20,7 @@ APP_ID=ai.storyteller.filmcraftSKIP_BUILD=0DRY_RUN=0-while [ $# -gt 0 ]; do+while [[ $# -gt 0 ]]; docase "$1" in--skip-build) SKIP_BUILD=1; shift ;;--dry-run) DRY_RUN=1; SKIP_BUILD=1; shift ;;@@ -36,7 +36,7 @@ case "$MACHINE" inarm64 | aarch64) ARCH=aarch64 ;;*) echo "unsupported architecture $MACHINE" >&2; exit 2 ;;esac-if [ "$DRY_RUN" = 0 ] && [ "$(uname -s)" != FreeBSD ]; then+if [[ "$DRY_RUN" = 0 ]] && [[ "$(uname -s)" != FreeBSD ]]; thenecho "error: build on FreeBSD (or pass --dry-run to check the tree layout)" >&2exit 2fi@@ -46,7 +46,7 @@ echo "==> FilmCraft $VERSION for FreeBSD $ARCH"# The release VM has 12 GB; full parallelism on the biggest crates runs it out of memory.export CARGO_BUILD_JOBS="${CARGO_BUILD_JOBS:-4}"-if [ "$SKIP_BUILD" = 0 ]; then+if [[ "$SKIP_BUILD" = 0 ]]; then(cd "$ROOT" && cargo build --release --locked -p filmcraft -p filmcraft-cli)fiWORK="$CARGO_TARGET_DIR/freebsd-package"@@ -56,7 +56,7 @@ mkdir -p "$WORK"BIN="$CARGO_TARGET_DIR/release"OUT_DIR="$DIST"-if [ "$DRY_RUN" = 1 ]; then+if [[ "$DRY_RUN" = 1 ]]; then# Stub binaries, and the tarball stays in the work dir so dist/ only ever holds real builds.BIN="$WORK/stub-bin"OUT_DIR="$WORK"@@ -81,13 +81,13 @@ sed -e "s/@VERSION@/$VERSION/g" -e "s/@DATE@/$FILMCRAFT_BUILD_DATE/g" \cp -R "$ROOT/assets/app-icon/hicolor" "$STAGE/share/icons/"copy_docs "$STAGE/share/doc/filmcraft"for f in NOTICE ATTRIBUTION.md; do- if [ -f "$ROOT/$f" ]; then install -m 644 "$ROOT/$f" "$STAGE/share/doc/filmcraft/"; fi+ if [[ -f "$ROOT/$f" ]]; then install -m 644 "$ROOT/$f" "$STAGE/share/doc/filmcraft/"; fidonefor f in bin/filmcraft bin/filmcraft-cli "share/applications/$APP_ID.desktop" \"share/icons/hicolor/256x256/apps/$APP_ID.png" "share/icons/hicolor/scalable/apps/$APP_ID.svg" \share/doc/filmcraft/LICENSE-MIT share/doc/filmcraft/LICENSE-APACHE; do- if [ ! -e "$STAGE/$f" ]; then echo "error: $f is missing from the package" >&2; exit 1; fi+ if [[ ! -e "$STAGE/$f" ]]; then echo "error: $f is missing from the package" >&2; exit 1; fidone# ---- .tar.gz ------------------------------------------------------------------------------------@@ -96,7 +96,7 @@ tar -C "$WORK" -czf "$OUT_DIR/$BASENAME.tar.gz" "$BASENAME"echo "wrote $OUT_DIR/$BASENAME.tar.gz""$STAGE/bin/filmcraft-cli" --version-if [ "$DRY_RUN" = 1 ]; then+if [[ "$DRY_RUN" = 1 ]]; thenecho "==> dry run: tarball contents"tar -tzvf "$OUT_DIR/$BASENAME.tar.gz"fidiff --git a/packaging/linux/flatpak-bundle.sh b/packaging/linux/flatpak-bundle.shindex 15d96c156..66406efb9 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="filmcraft-$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/filmcraft" ] || { echo "error: $TARBALL has no bin/filmcraft" >&2; exit 1; }+[[ -x "$WORK/stage/bin/filmcraft" ]] || { echo "error: $TARBALL has no bin/filmcraft" >&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=filmcraft-cli "$APP_ID" --versiondiff --git a/packaging/linux/install.sh b/packaging/linux/install.shindex 033fe9b7e..bd38730d5 100755--- a/packaging/linux/install.sh+++ b/packaging/linux/install.sh@@ -9,10 +9,10 @@ usage() {}fail() { echo "error: $*" >&2; exit 1; }prefix="${HOME:?HOME is not set}/.local"-while [ "$#" -gt 0 ]; do+while [[ "$#" -gt 0 ]]; docase "$1" in--prefix)- [ "$#" -ge 2 ] || fail '--prefix needs an absolute path'+ [[ "$#" -ge 2 ]] || fail '--prefix needs an absolute path'prefix="$2"; shift 2 ;;-h | --help) usage; exit 0 ;;*) usage >&2; fail "unknown argument: $1" ;;@@ -22,14 +22,14 @@ case "$prefix" in /*) ;; *) fail '--prefix must be an absolute path' ;; esacprefix="$(realpath -m -- "$prefix")"# Desktop Exec paths cannot contain '='; launchers also misinterpret '%' in executable names.[[ "$prefix" != *'='* && "$prefix" != *'%'* && ! "$prefix" =~ [[:cntrl:]] ]] || fail 'prefix cannot contain =, % or control characters'-[ "$prefix" != / ] || fail 'use /usr/local or a user directory, not /'+[[ "$prefix" != / ]] || fail 'use /usr/local or a user directory, not /'source_dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"case "$prefix/" in "$source_dir/"*) fail 'choose an installation prefix outside the extracted tarball' ;; esacapp_id=ai.storyteller.filmcraftfor binary in filmcraft filmcraft-cli; do- [ -f "$source_dir/bin/$binary" ] || fail "missing bin/$binary; extract the complete tarball first"+ [[ -f "$source_dir/bin/$binary" ]] || fail "missing bin/$binary; extract the complete tarball first"done-[ -f "$source_dir/share/applications/$app_id.desktop" ] || fail 'missing desktop entry; extract the complete tarball first'+[[ -f "$source_dir/share/applications/$app_id.desktop" ]] || fail 'missing desktop entry; extract the complete tarball first'mkdir -p -- "$prefix/bin" "$prefix/share"install -m755 -- "$source_dir/bin/filmcraft" "$prefix/bin/filmcraft"@@ -41,7 +41,7 @@ cp -R -- "$source_dir/share/." "$prefix/share/"# https://specifications.freedesktop.org/desktop-entry/latest/exec-variables.htmlexec_path="$(printf '%s' "$prefix/bin/filmcraft" | sed 's/[\\"`$]/\\&/g; s/\\/\\\\/g')"try_path="$(printf '%s' "$prefix/bin/filmcraft" | sed 's/\\/\\\\/g')"-while IFS= read -r line || [ -n "$line" ]; do+while IFS= read -r line || [[ -n "$line" ]]; docase "$line" inExec=*) printf 'Exec="%s" %%F\n' "$exec_path" ;;TryExec=*) printf 'TryExec=%s\n' "$try_path" ;;diff --git a/packaging/linux/package.sh b/packaging/linux/package.shindex f92544f93..9194cb075 100755--- a/packaging/linux/package.sh+++ b/packaging/linux/package.sh@@ -25,7 +25,7 @@ APP_ID=ai.storyteller.filmcraftSKIP_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="filmcraft-$VERSION-linux-$ARCH"echo "==> FilmCraft $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 filmcraft -p filmcraft-cli --target "$CROSS_TARGET")else(cd "$ROOT" && cargo build --release --locked -p filmcraft -p filmcraft-cli)@@ -113,9 +113,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@@ -138,16 +138,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/filmcraft-cli" --version-elif [ -n "${EMULATOR:-}" ]; then+elif [[ -n "${EMULATOR:-}" ]]; then"$EMULATOR" "$STAGE/usr/bin/filmcraft-cli" --versionfiecho "==> done"diff --git a/packaging/macos/import-cert.sh b/packaging/macos/import-cert.shindex 2a11b5309..2acf4bf3d 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 85902b91b..c84028b59 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/filmcraft-$VERSION-macos-$ARCH.dmg"CLI_ZIP="$DIST/filmcraft-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 "==> FilmCraft $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 filmcraft -p filmcraft-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@@ -117,7 +117,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/FilmCraft-notarize.zip"notarize "$WORK/FilmCraft-notarize.zip"xcrun stapler staple "$APP"@@ -144,7 +144,7 @@ hdiutil convert "$WORK/raw.dmg" -format UDZO -imagekey zlib-level=9 -o "$DMG"rm -f "$WORK/raw.dmg"sign "$DMG"codesign --verify --strict --verbose=2 "$DMG"-if [ "$NOTARIZE" = 1 ]; then+if [[ "$NOTARIZE" = 1 ]]; thennotarize "$DMG"xcrun stapler staple "$DMG"xcrun stapler validate "$DMG"@@ -162,7 +162,7 @@ codesign --verify --strict --verbose=2 "$CLI_DIR/filmcraft-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/filmcraft-cli" --versionecho "==> done"diff --git a/packaging/web/package.sh b/packaging/web/package.shindex fa208cad6..0aa031325 100755--- a/packaging/web/package.sh+++ b/packaging/web/package.sh@@ -11,10 +11,10 @@ set -euo pipefail. "$(dirname "${BASH_SOURCE[0]}")/../env.sh"HERE="$ROOT/packaging/web"-if [ "${1:-}" != "--skip-build" ]; then+if [[ "${1:-}" != "--skip-build" ]]; then# CI (the shared release workflow installs only trunk): install the wasm-bindgen CLI at the# crate's exact version. Locally, `cargo xtask web` says which version to install.- if [ -n "${CI:-}" ]; then+ if [[ -n "${CI:-}" ]]; thenWASM_BINDGEN_VERSION="$(sed -n 's/^const WASM_BINDGEN: &str = "\(.*\)";$/\1/p' "$ROOT/xtask/src/main.rs")"if ! { command -v wasm-bindgen >/dev/null && wasm-bindgen --version | grep -qF "$WASM_BINDGEN_VERSION"; }; thencargo install wasm-bindgen-cli --version "$WASM_BINDGEN_VERSION" --locked@@ -24,7 +24,7 @@ if [ "${1:-}" != "--skip-build" ]; thenfiSITE="$CARGO_TARGET_DIR/web/dist"-[ -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.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