Skip to content

Instantly share code, notes, and snippets.

@chimerast
Created March 23, 2012 03:24
Show Gist options
  • Save chimerast/2166454 to your computer and use it in GitHub Desktop.
Save chimerast/2166454 to your computer and use it in GitHub Desktop.
XenServerに入れたdebianをNISクライアントとしてセットアップ
#!/bin/bash
## XenServerVM用NISクライアント設定スクリプト
## xs-tools.isoを最初にマウントしておく
if [ "$UID" != "0" ]; then
echo "This script is for root user."
exit 0
fi
LOGINED=`users`
if [ "root" != "$LOGINED" ]; then
echo "Please run when only one root user is logined."
exit 0
fi
# 全てのユーザを削除するので確認
echo -n "This script will delete all users. (yes/no) "
read -n 1 ANS
echo
case $ANS in
[Yy])
;;
*)
exit 0
;;
esac
# 再確認
echo -n "Are you sure? (yes/no) "
read -n 1 ANS
echo
case $ANS in
[Yy])
;;
*)
exit 0
;;
esac
# 旧HOMEの移動先
mkdir /oldhome
# ユーザ(1000 <= UID < 30000)を調べて全削除しファイルを移動
USERNAMES=`cat /etc/passwd | awk -F: '$3 >= 1000 && $3 < 30000 { print $1 }'`
for USERNAME in $USERNAMES; do
deluser $USERNAME
mv /home/$USERNAME /oldhome
done
# Xenのクライアント用パッケージをインストール
mount /dev/xvdd /media
/media/Linux/install.sh
umount /media
aptitude update
aptitude -Ry upgrade
aptitude -Ry install ssh ntp nis autofs nfs-common sudo zsh
# NISクライアントの設定
cat << 'EOF' > /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.
passwd: nis compat
group: nis compat
shadow: nis compat
automount: nis compat
hosts: nis files dns
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis
EOF
/etc/init.d/autofs restart
# sudoersの設定
cat << 'EOF' > /etc/sudoers
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL) ALL
# Uncomment to allow members of group sudo to not need a password
# (Note that later entries override this, so you might need to move
# it further down)
# %sudo ALL=NOPASSWD: ALL
#
#includedir /etc/sudoers.d
%admin ALL=(ALL) NOPASSWD: ALL
EOF
cat << EOF > /etc/apt/sources.list
deb http://ftp.jp.debian.org/debian/ squeeze main contrib non-free
deb-src http://ftp.jp.debian.org/debian/ squeeze main contrib non-free
deb http://security.debian.org/ squeeze/updates main
deb-src http://security.debian.org/ squeeze/updates main
# squeeze-updates, previously known as 'volatile'
deb http://ftp.jp.debian.org/debian/ squeeze-updates main
deb-src http://ftp.jp.debian.org/debian/ squeeze-updates main
EOF
aptitude update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment