script-qhtcp-new-project 839 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env bash
  2. # Generate a new QHTCP experiment directory
  3. # Copyright 2024 Bryan C. Roessler
  4. echo "This script supports one optional argument, a project name"
  5. PROJECTS_DIR="/mnt/data/StudiesQHTCP"
  6. TEMPLATE_DIR="/mnt/data/StudiesQHTCP/_TEMPLATE_2copy_rename_4every_new_QHTCPstudy_23_1001"
  7. PROJECT_PREFIX="$(whoami)-$(date +%y-%m-%d)"
  8. ask_project_name() { read -r -p "Enter a new project name: " PROJECT_NAME; }
  9. if [[ $# == 1 ]]; then
  10. PROJECT_NAME="$1"
  11. else
  12. ask_project_name
  13. fi
  14. PROJECT_DIR="$PROJECTS_DIR/$PROJECT_PREFIX-$PROJECT_NAME"
  15. while [[ -d $PROJECT_DIR ]]; do
  16. echo "A project already exists at $PROJECT_DIR"
  17. ask_project_name
  18. PROJECT_DIR="$PROJECTS_DIR/$PROJECT_PREFIX-$PROJECT_NAME"
  19. done
  20. if mkdir "$PROJECT_DIR" &&
  21. cp -a "$TEMPLATE_DIR"/* "$PROJECT_DIR"; then
  22. echo "New project created at $PROJECT_DIR"
  23. fi