Handle existing qhtcp project dir gracefully
This commit is contained in:
@@ -267,14 +267,16 @@ random_words() {
|
||||
printf "%s_" "${arr[@]}" | sed 's/_$//'
|
||||
}
|
||||
# @description Backup one or more files to an incremented .bk file
|
||||
# @exitcode backup iterator max 255
|
||||
backup() {
|
||||
debug "Running: ${FUNCNAME[0]}" "$@"
|
||||
for f in "$@"; do
|
||||
[[ -e $f ]] || continue
|
||||
count=1
|
||||
while [[ -f $f.bk.$count ]]; do
|
||||
count=$((count+1))
|
||||
count=$((count++))
|
||||
done
|
||||
echo "Backing up $f to $f.bk.$count"
|
||||
debug "rsync -a $f $f.bk.$count"
|
||||
rsync -a "$f" "$f.bk.$count"
|
||||
done
|
||||
@@ -811,17 +813,34 @@ qhtcp() {
|
||||
debug "Running: ${FUNCNAME[0]}"
|
||||
|
||||
if [[ -d $QHTCP_PROJECT_DIR ]]; then
|
||||
# Handle existing output directory
|
||||
echo "A project already exists at $QHTCP_PROJECT_DIR"
|
||||
ask "Safely update $QHTCP_PROJECT_DIR from the $QHTCP_TEMPLATE_DIR template?"
|
||||
if ! ((YES)) && ask "Back up $QHTCP_PROJECT_DIR to $QHTCP_PROJECT_DIR.bk first and start fresh?"; then
|
||||
mv "$QHTCP_PROJECT_DIR" "$QHTCP_PROJECT_DIR.bk" || (echo "Backup unsuccessful, exiting"; exit 1)
|
||||
echo "Would you like to (c)ontinue, (u)pdate it from the template and continue, or (b)ack it up and continue from scratch?"
|
||||
for i in {1..3}; do # give the user three chances to get it right
|
||||
((YES)) || read -r -p "Hit [Enter] or c to continue: " response
|
||||
[[ -z $response ]] && break
|
||||
case $response in
|
||||
u)
|
||||
echo "Updating project from template"
|
||||
echo "Only files that are newer in the template will be overwritten"
|
||||
if rsync --archive --update "$QHTCP_TEMPLATE_DIR"/ "$QHTCP_PROJECT_DIR"; then
|
||||
echo "Project updated with template"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Copy template to QHTCP project directory
|
||||
;;
|
||||
b)
|
||||
backup "$QHTCP_PROJECT_DIR" && rm -rf "$QHTCP_PROJECT_DIR"
|
||||
if rsync --archive --update "$QHTCP_TEMPLATE_DIR"/ "$QHTCP_PROJECT_DIR"; then
|
||||
echo "New project created at $QHTCP_PROJECT_DIR"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
err "Invalid response, please try again"
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
fi
|
||||
|
||||
# Sets STUDIES_NUMS and NUM_STUDIES (yes this makes sense)
|
||||
get_studies "$STUDY_INFO_FILE"
|
||||
@@ -832,7 +851,7 @@ qhtcp() {
|
||||
|
||||
# If the next Exp dir already exists don't use it
|
||||
while [[ -d $QHTCP_PROJECT_DIR/Exp$next_study_num ]]; do
|
||||
(( next_study_num=next_study_num+1 ))
|
||||
(( next_study_num++ ))
|
||||
done
|
||||
|
||||
# Use initials from project not whoami
|
||||
|
||||
Reference in New Issue
Block a user