mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
build.sh and the releases/ scripts wrote all over the machine: temporary files to /tmp and macOS's /var/folders, downloads and release zips to ~/Downloads or ~/Lataukset, Meteor to ~/.meteor, Node.js to /usr/local (sudo n) or ~/.nvm, the npm cache to ~/.npm, Volta to ~/.volta, the Sandstorm toolchain to ~/projects, and PATH lines into ~/.zshrc and ~/.bashrc. A sandboxed editor (Flatpak on Linux, sandbox-exec on macOS) can reach only the checkout, and a container's own /tmp is a few hundred megabytes. Everything is in .tools/ now, which git and Meteor ignore: - releases/tools-env.sh, sourced by build.sh and every script that writes files, sets TMPDIR/TMP/TEMP to .tools/tmp (also downloads and release zips), NVM_DIR, npm_config_cache, VOLTA_HOME and the meteor-spk directory to .tools/, METEOR_WAREHOUSE_DIR to .tools/.meteor once Meteor is installed there, and puts those tools first on PATH, so no shell rc file is edited. HOME is not moved: git needs ~/.gitconfig and ~/.ssh. A TMPDIR already inside a .tools/ is kept, so a test's own directory there stays its own; without a writable one it stops rather than fall back to /tmp. It never fails a caller running set -euo pipefail. - macOS's mktemp ignores TMPDIR when given no template, so every mktemp names one: mktemp "$TMPDIR/name.XXXXXX". Fixed /tmp files are in $TMPDIR. - build.sh installs Node.js on Linux into .tools/n (N_PREFIX, no sudo), nvm on macOS into .tools/nvm (PROFILE=/dev/null: no rc file edited), and Meteor with HOME=.tools for the installer only, into .tools/.meteor. build.sh is replaced, not edited in place, while it may be running. - Containers get this checkout's .tools/tmp as their /tmp: every db-conformance database (MariaDB's temporary tables were verified to land there, and MongoDB's socket) and the repack container, which empty it themselves before they are removed. install-node-for-arch.sh requires the mounted TMPDIR. - tests/run-node-suites.cjs gives every suite TMPDIR in .tools/tmp, and the tests that copied a script into a fixture copy tools-env.sh too; tests that pinned ~/.meteor, the rc file edits, sudo n or /tmp/manifest.json pin the .tools/ places now and say why. tests/toolsDirOnly.test.cjs runs tools-env.sh against a TMPDIR already set elsewhere and under set -euo pipefail, and fails on any script that makes a temporary file without naming .tools/tmp, writes to the home directory, or edits a shell rc file, or on a container whose /tmp is its own. Thanks to xet7 !
46 lines
1.6 KiB
Bash
Executable File
46 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# nextcloud-pack.sh - pack the Nextcloud ExApp directory as <app-id>/...
|
|
#
|
|
# Usage: nextcloud-pack.sh <source dir> <app id> <archive.tar.gz>
|
|
#
|
|
# The Nextcloud App Store wants every member under one directory named after
|
|
# the app (releases/nextcloud-release.py verify_archive checks it). This used
|
|
# to be GNU tar's --transform "s,^\.$,<id>,;s,^\./,<id>/,", which bsdtar - the
|
|
# tar of macOS and the BSDs - does not have, so the release could not be packed
|
|
# or tested there. The source is copied under a staging <app-id>/ instead and
|
|
# that directory is packed: --exclude, -C and -czf are the same in both tars.
|
|
#
|
|
# Never packed: .git, .tools, .env, node_modules. COPYFILE_DISABLE keeps
|
|
# macOS's tar from adding ._* AppleDouble files for extended attributes.
|
|
set -euo pipefail
|
|
. "$(dirname "${BASH_SOURCE[0]}")/tools-env.sh" # temporary files and downloads go to .tools/tmp
|
|
|
|
if [ "$#" -ne 3 ]; then
|
|
echo "Usage: $0 <source dir> <app id> <archive.tar.gz>" >&2
|
|
exit 2
|
|
fi
|
|
source_dir=$1
|
|
app_id=$2
|
|
archive=$3
|
|
|
|
case "$app_id" in
|
|
''|*/*|.|..|*[!A-Za-z0-9_.-]*) echo "nextcloud-pack: invalid app id: $app_id" >&2; exit 2 ;;
|
|
esac
|
|
if [ ! -d "$source_dir" ]; then
|
|
echo "nextcloud-pack: no such directory: $source_dir" >&2
|
|
exit 2
|
|
fi
|
|
case "$archive" in
|
|
/*) ;;
|
|
*) archive="$PWD/$archive" ;;
|
|
esac
|
|
|
|
export COPYFILE_DISABLE=1
|
|
stage=$(mktemp -d "$TMPDIR/nextcloud-pack.XXXXXX")
|
|
trap 'rm -rf -- "$stage"' EXIT
|
|
mkdir "$stage/$app_id"
|
|
tar --exclude=.git --exclude=.tools --exclude=.env --exclude=node_modules \
|
|
-cf - -C "$source_dir" . | tar -xf - -C "$stage/$app_id"
|
|
tar -czf "$archive" -C "$stage" "$app_id"
|