#!/bin/sh # Files: # /etc/ssh/ssh_config # Host jdgb gb=https://www.yatex.org/gitbucket/ user=`logname` user=$USER case "$user" in j21??) ryear=2021 ;; j22??) ryear=2022 ;; #j[23][0-9][0-9][0-9]) # ryear=20`expr "$user" : 'j\(..\)..'` ;; *) # We cannot use "date" command because of its option incompatibility ryear=`ruby -e 'print (Time.now-120*24*3600).strftime("%Y")'` ;; esac repo=ssh://git@jdgb/JD${ryear}student/Ruby.git edom=itl.koeki-u.ac.jp trashbin=$HOME/Trash trashmsg="がサーバ上の最新版と食い違ったので ~/Trash ディレクトリに上書きコピーしておきました。" export GIT_SSH=/usr/koeki/bin/jdgit-ssh if ! curl -m 3 -s $gb/signin >/dev/null; then echo "No network" >&2; exit 1 fi gitssh() { ssh -F /usr/koeki/etc/gbrepo/.ssh/config "$@" } start() { if ! grep -q "email.*$USER" $HOME/.gitconfig; then if [ -s $HOME/.email ]; then email=`grep -v '^#' $HOME/.email|head -1` else email=$USER@$edom fi getent passwd `logname` | if IFS=: read u p uid gid gecos rest; then git config --global user.name "$gecos" git config --global user.email "$email" fi fi if [ -d $HOME/Ruby/.git ]; then git -C $HOME/Ruby pull exit $? elif [ -d $HOME/Ruby ]; then td=`mktemp -d -t startRuby` if [ -n "$td" -a -w "$td" ]; then trap "rm -rf "$td"" INT HUP EXIT TERM (cd "$td" git clone "$repo" && rsync -axH Ruby $HOME ) fi else git clone $repo fi (cd $HOME/Ruby git config pull.rebase true git config --add merge.ff false git config --add pull.ff only if ! git fetch origin $USER; then git branch $USER fi git checkout -f $USER git push --set-upstream origin $USER git push ) } resetGit() { rm -rf $HOME/Ruby/.git 2>/dev/null start } ci() { cd $HOME/Ruby git add . git commit -m "${COMMIT_MESSAGE:-`date +'%F %T'`}" git pull "$@"; rc=$? if [ x$rc != x0 ]; then files=`git ls-files -u | awk '{print $NF}' | sort -u` if [ -n "$files" ]; then [ -d "$trashbin" ] || mkdir "$trashbin" cp $files "$trashbin" msg="$files $trashmsg" echo "----------------------------------" echo "$trashmsg" echo "----------------------------------" ls -lF $trashbin zenity --width 600 --info --text "$trashmsg" fi git rebase --skip || git rebase --abort fi git push || git push --set-upstream origin "$USER" echo git-ci "$@" ended with $rc return $rc } case `logname` in c1*|j2*) ;; yuuji) ;; *) exit 0 ;; esac case "`basename $0`" in jdgit-ssh) gitssh "$@" ;; start*) start ;; reset*) resetGit ;; ci*) ci ;; merge*) ci && ci origin master ;; jdgit) git "$@" ;; esac