#!/bin/sh # Files: # /etc/ssh/ssh_config # Host jdgb gb=https://www.yatex.org/gitbucket/ repo=ssh://git@jdgb/JD2021student/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 $USER git push --set-upstream origin $USER git push ) } ci() { cd $HOME/Ruby git add . git commit -m "`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 fi git push echo git-ci "$@" ended with $rc return $rc } case "`basename $0`" in jdgit-ssh) gitssh "$@" ;; start*) start ;; ci*) ci ;; merge*) ci && ci origin master ;; esac