Skip to content

Instantly share code, notes, and snippets.

@fknaopen
Created May 15, 2012 11:24
Show Gist options
  • Save fknaopen/2700990 to your computer and use it in GitHub Desktop.
Save fknaopen/2700990 to your computer and use it in GitHub Desktop.
git instaweb launcher
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment