Created
March 18, 2013 12:07
-
-
Save alpaca-tc/5186739 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# sudo ./user_add dlab-inc.jp | |
# 1. ユーザーdlab-inc.jpを追加 | |
# 2. dotfilesを設置 | |
# 3. /etc/httpd/conf.d/以下に、${name}.confの名前でapache用設定を追加 | |
# 4. gitを$HOMEに作成。pushすればhookによりwwwディレクトリを更新する | |
# define name and password | |
name=$1 | |
password=$(mkpasswd -l 32 -s 0) | |
# 作成するディレクトリ | |
user_dir="/home/${name}" | |
git_dir="${user_dir}/git.git" | |
www_dir="${user_dir}/www" | |
ssh_dir="${user_dir}/.ssh" | |
conf_file="/etc/httpd/conf.d/${name}.conf" | |
# ユーザーに付与するGroup | |
# GRANT_GROUPS=(rbenv) | |
# ディレクトリがある場合処理を中止#{{{ | |
if [ -d ${user_dir} ] | |
then | |
echo "既にユーザーかディレクトリが存在します。" | |
sleep 2 | |
exit | |
fi | |
#}}} | |
read -p "create ${name}? y/n " yn | |
if [ $yn = "y" -o $yn = "Y" ]; then | |
# ユーザー追加#{{{ | |
/usr/sbin/useradd $name | |
echo "password = " $password | |
#}}} | |
# permission#{{{ | |
chmod 750 /home/$name | |
chown -R :apache /home/$name | |
#}}} | |
# dotfilesを構築#{{{ | |
DOT_FILES=(.gitignore_global .ctags .dir_colors .emacs.el .gemrc .gitconfig .gitignore .gvimrc .inputrc .rsense .rspec .rvmrc .tmux.conf .tmux.split .vimrc .zshrc .autojump .emacs.d .tmuxinator .vim .zsh local .pryrc .eskk_jisyo .eskk .eskk_dict .bundle) | |
rm -rf ${user_dir}/.bash* | |
rm -rf ${user_dir}/.zsh* | |
for file in ${DOT_FILES[@]} | |
do | |
ln -s /dotfiles/$file ${user_dir}/$file | |
done | |
mkdir ${user_dir}/.vim.swapfile | |
chsh -s /bin/zsh ${name} | |
#}}} | |
# htaccessの設定#{{{ | |
cat http_skel.conf | sed -e "s/domain/${name}/" > ${conf_file} | |
#}}} | |
# gitを構築#{{{ | |
mkdir -p $git_dir | |
git init --bare $git_dir | |
# cat "(cd ${www_dir};git --git-dir=.git pull;)" > "${git_dir}/hooks/post-receive" | |
cat post-receive | sed -e "s?git_directory?${www_dir}?" > "${git_dir}/hooks/post-receive" | |
chmod +x "${git_dir}/hooks/post-receive" | |
rm -rf $www_dir | |
git clone $git_dir $www_dir | |
chown -R $name $www_dir $git_dir | |
#}}} | |
# sshを設定#{{{ | |
chmod 755 ${user_dir} | |
mkdir -p ${ssh_dir} | |
chmod 755 ${ssh_dir} | |
cp authorized_keys ${ssh_dir}/ | |
chmod 644 ${ssh_dir}/authorized_keys | |
#}}} | |
# 権限の追加#{{{ | |
for group in ${GRANT_GROUPS[@]} | |
do | |
gpasswd -a $name $group | |
done | |
#}}} | |
read -p "edit ${conf_file}? y/n " yn | |
if [ $yn = "y" -o $yn = "Y" ]; then | |
vi ${conf_file} | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment