Repository navigation
Expand file tree
/
Copy pathtask
More file actions
executable file
·59 lines (59 loc) · 2.5 KB
/
Copy pathtask
File metadata and controls
executable file
·59 lines (59 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh
set -eu
root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
cache=${LORE_BUILD_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/lore/build}
case "$cache" in /*) : ;; *) printf 'LORE build cache must be absolute.\n' >&2; exit 1 ;; esac
[ ! -L "$cache" ] || exit 1
mkdir -p "$cache/tmp"
chmod 700 "$cache" "$cache/tmp"
export TMPDIR=$cache/tmp CARGO_TARGET_DIR=$cache
export CARGO_BUILD_JOBS=${CARGO_BUILD_JOBS:-2}
mode=${1:-help}
[ "$#" -eq 0 ] || shift
case "$mode" in
build) cargo build --release --locked --manifest-path "$root/Cargo.toml" --package lore-core --bin lore-rs ;;
install)
cargo build --release --locked --manifest-path "$root/Cargo.toml" --package lore-core --bin lore-rs
bin=${LORE_BIN_DIR:-$HOME/.local/bin}
case "$bin" in /*) : ;; *) exit 1 ;; esac
mkdir -p "$bin"
stage=$(mktemp -d "$bin/.lore-install.XXXXXXXX")
installing=0
cleanup() {
trap - EXIT HUP INT TERM
if [ "$installing" -eq 1 ]; then
failed=0
for name in lore-rs lore; do
rm -f "$bin/$name" || { failed=1; continue; }
if [ -e "$stage/backup/$name" ] || [ -L "$stage/backup/$name" ]; then
mv "$stage/backup/$name" "$bin/$name" || failed=1
fi
done
[ "$failed" -eq 0 ] || { printf 'Rollback incomplete; backups remain in %s/backup\n' "$stage" >&2; exit 1; }
fi
rm -rf "$stage"
}
trap 'cleanup' EXIT
trap 'exit 1' HUP INT TERM
cp "$cache/release/lore-rs" "$stage/lore-rs"
chmod 755 "$stage/lore-rs"
ln -s lore-rs "$stage/lore"
mkdir "$stage/backup"
for name in lore-rs lore; do
[ ! -d "$bin/$name" ] || [ -L "$bin/$name" ] || exit 1
if [ -e "$bin/$name" ] || [ -L "$bin/$name" ]; then cp -Pp "$bin/$name" "$stage/backup/$name"; fi
done
installing=1
for name in lore-rs lore; do
if [ -L "$bin/$name" ]; then rm "$bin/$name"; fi
mv -f "$stage/$name" "$bin/$name"
done
installing=0
printf 'Installed native LORE at %s/lore\n' "$bin"
;;
run) cargo build --locked --manifest-path "$root/Cargo.toml" --package lore-core --bin lore-rs; exec "$cache/debug/lore-rs" "$@" ;;
setup) cargo build --release --locked --manifest-path "$root/Cargo.toml" --package lore-core --bin lore-rs; LORE_RS="$cache/release/lore-rs" exec "$root/bin/lore" setup "$@" ;;
test) cargo test --locked --manifest-path "$root/Cargo.toml" ;;
help|-h|--help) printf '%s\n' './task build | install | run [LORE arguments] | setup | test' ;;
*) printf 'Unknown task: %s\n' "$mode" >&2; exit 1 ;;
esac