From 4db7c0ec2c975f58613124c9d08734044e7c5424 Mon Sep 17 00:00:00 2001 From: Markus M <mmi.github@gmail.com> Date: Wed, 17 Apr 2024 00:03:12 +0200 Subject: [PATCH] feat(git): modified the fugit.sh script to allow cloning and running on andorra as well as switching between make, python and node --- fugit.sh | 35 ++++++++++++++++++++++++++++++----- fugitclean.sh | 5 +++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/fugit.sh b/fugit.sh index aabbd05..54576e4 100755 --- a/fugit.sh +++ b/fugit.sh @@ -1,9 +1,12 @@ #!/bin/sh -if [ $# -gt 2 ]; then - printf "Usage: %s [branch] [reponame]" $(basename $0) >&2 - printf "Default branch name will be read from comments.txt" >&2 - printf "Default reponame will be npvp-exercises" >&2 +if [ $# -gt 2 ] || [ "$1" = "--help" ]; then + printf "Usage: %s [branch] [reponame]\n" $(basename $0) >&2 + printf "Default branch name will be read from comments.txt\n" >&2 + printf "Default reponame will be npvp-exercises\n" >&2 + printf "set env:FU_ANDORRA_USER and optionally env:FU_ANDORRA_DIR to checkout and run on andorra automatically\n" >&2 + printf "if env:FU_ANDORRA_DIR is not set, a npvp-tmp dir will be created in your main dir\n" >&2 + printf "set env:FU_RUN={0,1,2} to 0 = make, 1 = python, 3 = nodejs\n when running on andorra (default is make)\n" >&2 exit 1 fi @@ -22,4 +25,26 @@ else branch_name=$1 fi -`git clone -b $branch_name git@git.imp.fu-berlin.de:$repo_name git-solution` +case ${FU_RUN:-0} in + 1) + run_cmd="python3 main.py" + ;; + 2) + run_cmd="node main.js" # i hope this is correct, we will see when the sheet are finalised. + ;; + *) + run_cmd="make run" + ;; +esac + +if ! [ -z $FU_ANDORRA_USER ]; then + # FU_ANDORRA_USER is set, executing on andorra + clone_dir=${FU_ANDORRA_DIR:-npvp-tmp} + + `ssh $FU_ANDORRA_USER@andorra.imp.fu-berlin.de \ + "git clone -b $branch_name git@git.imp.fu-berlin.de:$repo_name ./$clone_dir || exit 1; cd $clone_dir && $run_cmd; cd .. && rm -rf $clone_dir"` +else + # run locally: + git clone -b $branch_name git@git.imp.fu-berlin.de:$repo_name git-solution || exit 1 + cd git-solution && `$run_cmd`; cd .. +fi diff --git a/fugitclean.sh b/fugitclean.sh index b567d5e..23924f6 100755 --- a/fugitclean.sh +++ b/fugitclean.sh @@ -2,7 +2,12 @@ # this script cleans all checked out repositories when called from the same folder that contains the grades.csv # or a singular checked out repo when called from within a student folder +if [ -z $FU_ANDORRA_USER ]; then + # only clean up when not run on ssh + # ssh cleans up itself :) + find -type d \ -wholename "*/git-solution" -prune \ -execdir sh -c "rm -rf ./git-solution/" {} \; +fi -- GitLab