refactor: repos init
This commit is contained in:
		
							parent
							
								
									00e0202f62
								
							
						
					
					
						commit
						34c9192711
					
				
							
								
								
									
										25
									
								
								joj-repo
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								joj-repo
									
									
									
									
									
								
							|  | @ -10,7 +10,6 @@ LXCHOST="tt@172.17.0.1" | ||||||
| # | # | ||||||
| # parse commit message | # parse commit message | ||||||
| # | # | ||||||
| 
 |  | ||||||
| parse_commit() { | parse_commit() { | ||||||
| 
 | 
 | ||||||
| 	message=$(git log -1 --pretty=format:%s ${GITHUB_WORKFLOW_SHA}) | 	message=$(git log -1 --pretty=format:%s ${GITHUB_WORKFLOW_SHA}) | ||||||
|  | @ -26,7 +25,6 @@ parse_commit() { | ||||||
| # | # | ||||||
| # gen  | # gen  | ||||||
| # | # | ||||||
| 
 |  | ||||||
| generate_json() { | generate_json() { | ||||||
| 
 | 
 | ||||||
| 	parse_commit | 	parse_commit | ||||||
|  | @ -42,33 +40,21 @@ generate_json() { | ||||||
| # | # | ||||||
| init() { | init() { | ||||||
| 
 | 
 | ||||||
|         [ -d $COURSE-config ] && backup $COURSE-config | 	# backup current grading scoreboard | ||||||
|  | 	[ -d $COURSE-joj ] && backup $COURSE-joj | ||||||
| 
 | 
 | ||||||
|         git clone $GITEA/$ORG/$COURSE-joj.git $COURSE-config | 	git clone $GITEA/$ORG/$COURSE-joj.git | ||||||
| 
 | 
 | ||||||
| 	cd $COURSE-config | 	cd $COURSE-config | ||||||
| 
 | 
 | ||||||
| # copy config files |  | ||||||
|         rsync -r ./$HOME/ $HOME |  | ||||||
| 
 |  | ||||||
| 	# check existence of grading branch | 	# check existence of grading branch | ||||||
| 	git branch -a | grep -q grading && br=1 | 	git branch -a | grep -q grading && br=1 | ||||||
| 
 | 
 | ||||||
|         cd .. |  | ||||||
| 
 |  | ||||||
| # backup current grading scoreboard |  | ||||||
|         [ -d $COURSE-joj ] && backup $COURSE-joj |  | ||||||
| 
 |  | ||||||
| # clone grading branch or create one + push readme | # clone grading branch or create one + push readme | ||||||
| if [ "x$br" = "x1" ]; then | if [ "x$br" = "x1" ]; then | ||||||
|                 git clone -b grading $GITEA/$COURSE-$SEMESTER/$COURSE-joj.git |  | ||||||
|                 cd $COURSE-joj |  | ||||||
| 	git switch grading | 	git switch grading | ||||||
| 	git pull | 	git pull | ||||||
| else | else | ||||||
|                 git clone $GITEA/$COURSE-$SEMESTER/$COURSE-joj.git |  | ||||||
| 
 |  | ||||||
|                 cd $COURSE-joj |  | ||||||
| 	git switch --orphan grading | 	git switch --orphan grading | ||||||
| 
 | 
 | ||||||
| 	echo "# $COURSE JOJ grading" > Readme.md | 	echo "# $COURSE JOJ grading" > Readme.md | ||||||
|  | @ -102,13 +88,16 @@ update() { | ||||||
| # | # | ||||||
| backup() { | backup() { | ||||||
| 
 | 
 | ||||||
|  | 	[ -d $HOME/.local/share/joj ] || mkdir -p $HOME/.local/share/joj | ||||||
|  | 
 | ||||||
| 	BCK="$HOME/.local/share/joj/$1-$(date +%y%m%d-%H%M%S)" | 	BCK="$HOME/.local/share/joj/$1-$(date +%y%m%d-%H%M%S)" | ||||||
| 	echo "WARNING: $1 already exits, backing it up to $BCK" | 	echo "WARNING: $1 already exits, backing it up to $BCK" | ||||||
| 	mv "$1" "$BCK" | 	mv "$1" "$BCK" | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| [ -z "$1" ] && echo "Usage: $0 update|init" | [ -z "$1" ] && echo "Usage: $0 update|init" && exit 1 | ||||||
| 
 | 
 | ||||||
|  | [ -d $HOME/.cache ] || mkdir $HOME/.cache | ||||||
| cd $HOME/.cache | cd $HOME/.cache | ||||||
| $1 | $1 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user