利用shell自动创建代码库管理gitosis 服务环境

为了大家都能偷懒而已~把步骤写成脚本~

用法:

bootstrap.sh && gitosis-knstall.sh

git 安装~

  
  
  
  
  1.  wget http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.gz 

  2.  tar xzvf git-latest.tar.gz 

  3.  cd git-{date} 

  4.  autoconf 

  5.  ./configure --with-curl=/usr/local 

  6.  make 

  7.  sudo make install 

下面是 bootstrap.sh 

  
  
  
  
  1. #!/bin/sh 

  2. mkdir -p bin 

  3. curl https://raw.github.com/pypa/virtualenv/master/virtualenv.py > bin/virtualenv.py 

  4. python ./bin/virtualenv.py --distribute gitosis-env 

  5.    . gitosis-env/bin/activate 

  6. mkdir src 

  7. cd src 

  8.    git clone https://github.com/tv42/gitosis.git 

  9.    cd gitosys 

  10.       python ./setup.py install 

  11. cd ../.. 

下面是 gitosis-knstall.sh

  
  
  
  
  1. #!/bin/sh 

  2. # Create gitosis env 

  3. LOCAL_DIR=$( cd $(dirname $0) && pwd) 

  4. GITOSIS_USER=git

  5. GITOSIS_SERVER=efate

  6. GITOSIS_HOMEDIR=/srv/${GITOSIS_SERVER}/git 

  7. git_user=$(getent passwd ${GITOSIS_USER}) 

  8. if [ -z "${git_user}" ] 

  9. then 

  10.     sudo adduser \ 

  11.         --system \ 

  12.         --shell /bin/sh \ 

  13.         --gecos 'git version control' \ 

  14.         --group \ 

  15.         --disabled-password \ 

  16.         --home ${GITOSIS_HOMEDIR} \ 

  17.         ${GITOSIS_USER} 

  18. else 

  19. GITOSIS_HOMEDIR=$(echo ${git_user} | cut -d: -f6) 

  20. fi 

  21. #TODO: check env if exists ... (update ?) 

  22. sudo rsync -av ${LOCAL_DIR}/gitosis-env ${GITOSIS_HOMEDIR} 

  23. sudo python ${LOCAL_DIR}/bin/virtualenv.py --relocatable ${GITOSIS_HOMEDIR}/gitosis-env 

  24. [ ! -f ~/.ssh/gitosis.pub ] && ssh-keygen -t rsa -f ~/.ssh/gitosis 

  25. sudo -H -u ${GITOSIS_USER} ${GITOSIS_HOMEDIR}/gitosis-env/bin/gitosis-init < ~/.ssh/gitosis.pub 

  26. sudo sh -c "printf '. \${HOME}/gitosis-env/bin/activate'  > ${GITOSIS_HOMEDIR}/.profile" 

  27. sudo chown -R git:git ${GITOSIS_HOMEDIR} 

 

 

你可能感兴趣的:(shell脚本,gitosis,自动创建代码库)