32 lines
1.2 KiB
Bash
32 lines
1.2 KiB
Bash
#!/bin/bash
|
|||
|
|
# Keep existing Telegraf command paths pointing at this checkout.
|
||
|
|
set -euo pipefail
|
||
|
|
repo=$(cd -- "$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")" && pwd -P)
|
||
|
|
target=${1:-/etc/telegraf}
|
||
|
|
[[ $# -le 1 ]] || { echo "Usage: $0 [telegraf-directory]" >&2; exit 2; }
|
||
|
|
[[ -d $target && -w $target ]] || {
|
||
|
|
echo "Directory must exist and be writable: $target (use sudo for /etc/telegraf)" >&2
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
backup=
|
||
|
|
staging=$(mktemp -d "$target/.bcachefs-install.XXXXXXXX")
|
||
|
|
trap 'rm -rf -- "$staging"' EXIT
|
||
|
|
for source in "$repo"/bcachefs*.sh; do
|
||
|
|
name=${source##*/}
|
||
|
|
destination=$target/$name
|
||
|
|
[[ -x $source ]] || { echo "Not executable: $source" >&2; exit 1; }
|
||
|
|
if [[ -L $destination && $(readlink -- "$destination") == "$source" ]]; then
|
||
|
|
continue
|
||
|
|
fi
|
||
|
|
[[ ! -d $destination ]] || { echo "Refusing to replace directory: $destination" >&2; exit 1; }
|
||
|
|
if [[ -e $destination || -L $destination ]]; then
|
||
|
|
if [[ -z $backup ]]; then
|
||
|
|
backup=$(mktemp -d "$target/bcachefs-backup.XXXXXXXX")
|
||
|
|
echo "Backup: $backup"
|
||
|
|
fi
|
||
|
|
cp -a -- "$destination" "$backup/$name"
|
||
|
|
fi
|
||
|
|
ln -s -- "$source" "$staging/$name"
|
||
|
|
mv -Tf -- "$staging/$name" "$destination"
|
||
|
|
echo "$destination -> $source"
|
||
|
|
done
|