Refactor directory creation

This commit is contained in:
Jose Gracia 2024-05-29 14:04:18 +02:00
parent a7e0a60840
commit bdc64ff223

View file

@ -1,11 +1,14 @@
#!/bin/bash
#
# This scripts checks out spack from the repo
# This scripts checks out from the repo
#
# Input arguments:
# - repo: url to repo in git format
# - release_tag: tag/branch/commit in repo
# - release_dir:
# - destination: checkout into directory <release_dir>/<destination>
#
# Environment variables: $TMPDIR must be set
#
_VERBOSITY=1
@ -15,6 +18,8 @@ if [[ "$#" -ne 4 ]]; then
echo "Checkout tag <release_tag> from repo <repo> into path <release_dir>/<destination>."
fi
echo "TODO: check for $TMPDIR"
arg_repo=$1
arg_tag=$2
arg_dir=$3
@ -38,16 +43,30 @@ canonize_tag () {
}
# create and prepare destination directory
# or return existing directory
create_dir () {
local dir=$1
local rc
if [[ -d $dir ]]; then
rc=$dir
else
mkdir -p $dir
chmod g=u $dir
rc=$dir
fi
echo $rc
}
# create an empty new directory and prepare destination directory
create_or_fail_dir () {
local dir=$1
local rc
if [[ -d $dir ]]; then
rc=""
else
mkdir -p $dir
chmod g=u $dir
rc=$dir
rc=$(create_dir $dir)
fi
echo $rc
}
@ -65,7 +84,7 @@ checkout_git () {
repo=$(check_repo $arg_repo)
release_tag=$(canonize_tag $arg_tag)
destination_dir=$(create_dir $arg_dir/$arg_destination)
destination_dir=$(create_or_fail_dir $arg_dir/$arg_destination)
if [[ -z $destination_dir ]]; then
log "Covardly refusing to overwrite existing directory $arg_dir/$arg_destination."
else