This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
fradrive-old/clean.sh
2022-10-12 09:43:42 +02:00

47 lines
952 B
Bash
Executable File

#!/usr/bin/env bash
set -e
# SPDX-FileCopyrightText: 2022 Gregor Kleen <gregor.kleen@ifi.lmu.de>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en .stack-work.lock "$0" "$@" || :
if [[ -n "${1}" ]]; then
target=".stack-work-${1}"
else
target=".stack-work"
fi
shift
if [[ ! -d "${target}" ]]; then
printf "%s does not exist or is no directory\n" "${target}" >&2
exit 1
fi
if [[ "${target}" != ".stack-work" ]]; then
if [[ -e .stack-work-clean ]]; then
printf ".stack-work-clean exists\n" >&2
exit 1
fi
move-back() {
if [[ -d .stack-work ]]; then
mv -vT .stack-work "${target}"
else
mkdir -v "${target}"
fi
[[ -d .stack-work-clean ]] && mv -vT .stack-work-clean .stack-work
}
mv -vT .stack-work .stack-work-clean
mv -vT "${target}" .stack-work
trap move-back EXIT
fi
(
set -ex
stack clean $@
)