LoginSignup
1
0

More than 5 years have passed since last update.

Linux:gitリポジトリを一時的にweb公開するscript

Posted at

gitは "git instaweb" でカレントのリポジトリをweb公開できて、webブラウザからlogやdiffがとれる。
特に複数のbranchを持っている状態のときにあちこちのbranchに移動しつつ参照できて便利だなと思う。
便利だけど、数十人のproject等でサーバマシンを共有している場合にportがかぶるとやだなって思ったので、開いているportを自動で割り当ててinstawebするshell-scriptを書いた。

"webgit.sh start"   で開始して
"webgit.sh stop"  で停止する

  • 表示イメージ 18333fig0401-tn1 (1).png
#!/bin/sh
#===============================================================================
# [webgit.sh]
# git-repoを一時的にwebに公開するscript
#
# git-repoの存在するサーバマシン上で実行できます
# ※ git-repoのweb参照が不要になったら必ず終了させてください
#
# 起動: git管理下にあるディレクトリ上で webgit.sh start
#                                       --> 表示されたURLにて参照できます
#
# 終了: git管理下にあるディレクトリ上で webgit.sh stop
#
#===============================================================================
# 2012.05.15 nfukuoka 新規作成

servername=`hostname`

f_getport()
{
    perl - <<'EOT'
    use IO;
    my $port_no = do {
        my $l = IO::Socket::INET->new(
            Listen => 5,
            LocalHost => '127.0.0.1',
            LocalPort => 0,
            Proto => 'tcp',
            ReuseAddr => 1,
        ) or die $!;
        print $l->sockport;
    };
EOT
}

cmd=$1
if [ "x$cmd" = "x" ];then
    echo "Usage: `basename $0` start|stop" >&2
    exit 1
fi


ret=9
if [ "x$cmd" = "xstart" ];then

    l_port=`f_getport`

    # (まずは apache2 instaweb 終了)
    git instaweb  --stop
    sleep 1

    # apache2 instaweb 開始
    git instaweb  --httpd=apache2 --port=$l_port --browser='none'

    # print access URL
    echo "\n"
    echo "-----"
    printf "Access URL -->   http://%s:%s/\n" "$servername" "$l_port"
    echo "-----"
    ret=0

elif [ "x$cmd" = "xstop" ];then

    # apache2 instaweb 終了
    git instaweb  --stop
    ret=0
fi

exit $ret
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0