Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ysaotome/cdc02c05425e01abc500 to your computer and use it in GitHub Desktop.
Save ysaotome/cdc02c05425e01abc500 to your computer and use it in GitHub Desktop.
Ubuntu 14.04 64bit Plain setup script for NiftyCloud (http://cloud.nifty.com/)
#!/bin/bash
# Description:Ubuntu 14.04 64bit Plain setup script for NiftyCloud (http://cloud.nifty.com/)
# File:Ubuntu1404_64bit_Plain_setup_script_for_niftycloud.sh
# 2014/07/10 @ysaotome
(
#===============================================
# Settings
#===============================================
##rootのパスワード
ROOT_PASSWORD='hoge##123'
##追加する管理ユーザ名
USER_NAME='hoge'
##管理ユーザのパスワード
USER_PASSWORD='hoge##123'
#===============================================
SALT=$(/usr/bin/uuidgen| /usr/bin/tr -d '-')
## ロケール設定変更
/usr/sbin/locale-gen ja_JP.UTF-8
/usr/sbin/dpkg-reconfigure locales
## hostname変更
HOSTNAME=$(/usr/sbin/vmtoolsd --cmd 'info-get guestinfo.hostname')
/bin/hostname ${HOSTNAME}
/bin/sed -i.org -e 's/^ubuntu/'${HOSTNAME}'/g' /etc/hostname
## ROOTパスワード設定
/usr/sbin/usermod -p $(/usr/bin/perl -e 'print crypt(${ARGV[0]}, ${ARGV[1]})' ${ROOT_PASSWORD} ${SALT}) root
## 管理ユーザ追加と設定
/usr/sbin/useradd -G 100 -p $(/usr/bin/perl -e 'print crypt(${ARGV[0]}, ${ARGV[1]})' ${USER_PASSWORD} ${SALT}) -m ${USER_NAME}
/bin/mkdir -p -m 700 /home/${USER_NAME}/.ssh
/bin/cp /root/.ssh/authorized_keys /home/${USER_NAME}/.ssh/.
/bin/chown -R ${USER_NAME}:${USER_NAME} /home/${USER_NAME}/.ssh
/bin/sed -i.org -e 's/^# Members/'${USER_NAME}' ALL\=\(ALL\:ALL\) ALL\n# Members/g' /etc/sudoers
## ssh経由でのROOTログイン禁止
/bin/sed -i.org -e 's/^PermitRootLogin .*/PermitRootLogin no/g' /etc/ssh/sshd_config
##resolv.conf変更
/bin/cat << _RESOLVCONF_ >> /etc/resolv.conf
nameserver 127.0.0.1
_RESOLVCONF_
## ツールセットアップ zsh,screen,ntp,sysstat,net-snmpをセットアップする
/usr/bin/apt -y update
/usr/bin/apt -y install zsh screen zip ntp sysstat dstat htop iotop jnettop snmpd figlet git openjdk-7-jdk
/usr/bin/apt -y upgrade
## zshとscreenとvimrcの設定ファイル取得
/usr/bin/wget --no-check-certificate -P /home/${USER_NAME}/ 'https://gist.github.com/ysaotome/1336176/raw/8ec9767aaaaec88cbe8c2b4a4092f16d7839c77b/.screenrc'
/usr/bin/wget --no-check-certificate -P /home/${USER_NAME}/ 'https://gist.github.com/ysaotome/1336176/raw/0388bb029061783bcb2d8bbd3218b04ac4b29ba4/.zshrc'
/usr/bin/wget --no-check-certificate -P /home/${USER_NAME}/ 'https://gist.github.com/ysaotome/1336176/raw/8cd856feaea3196251ca1d2599fb02544184c5d5/.vimrc'
/bin/chown -R ${USER_NAME}:${USER_NAME} /home/${USER_NAME}/.screenrc /home/${USER_NAME}/.zshrc /home/${USER_NAME}/.vimrc
/bin/ln -s /home/${USER_NAME}/.screenrc /root/
/bin/ln -s /home/${USER_NAME}/.zshrc /root/
/bin/ln -s /home/${USER_NAME}/.vimrc /root/
/usr/sbin/usermod -s /bin/zsh root
/usr/sbin/usermod -s /bin/zsh ${USER_NAME}
## update-motd設置
/usr/bin/wget --no-check-certificate -P /usr/local/bin/ 'https://gist.github.com/ysaotome/5997652/raw/05a680fc5a1df75469d5c26f505f217f727e0af6/update_motd_for_centos.sh'
/bin/chmod 755 /usr/local/bin/update_motd_for_centos.sh
/usr/local/bin/update_motd_for_centos.sh
/bin/cat << _UPDATEMOTD_ > /etc/cron.d/update-motd
#update-moted
*/5 * * * * root /usr/local/bin/update_motd_for_centos.sh
_UPDATEMOTD_
## ntpdの設定ファイル
/usr/bin/vmware-toolbox-cmd timesync disable
/bin/sed -i.org -e "s/^server /#server /g" /etc/ntp.conf
/bin/cat << _NTPDCONF_ >> /etc/ntp.conf
server -4 ntp.nict.jp iburst
server -4 ntp1.jst.mfeed.ad.jp
server -4 ntp2.jst.mfeed.ad.jp
server -4 ntp3.jst.mfeed.ad.jp
_NTPDCONF_
/usr/sbin/update-rc.d ntp enable
/etc/init.d/ntp start
## snmpdの設定ファイル
## by http://cloud.nifty.com/snmp/
/bin/sed -i.org -e 's/^agentAddress udp:127/#agentAddress udp:127/g' -e 's/^#agentAddress udp:161/agentAddress udp:161/g' /etc/snmp/snmpd.conf
/bin/cat << _SNMPDCONF_ >>/etc/snmp/snmpd.conf
rocommunity niftycloud 10.100.0.14 .1.3.6.1.
rocommunity niftycloud 10.100.8.15 .1.3.6.1.
rocommunity niftycloud 10.100.16.13 .1.3.6.1.
rocommunity niftycloud 10.100.32.15 .1.3.6.1.
rocommunity niftycloud 202.248.175.141 .1.3.6.1.
rocommunity niftycloud 10.100.48.13 .1.3.6.1.
rocommunity niftycloud 175.184.41.60 .1.3.6.1.
rocommunity niftycloud 10.100.64.11 .1.3.6.1.
rocommunity niftycloud 10.100.64.12 .1.3.6.1.
rocommunity niftycloud 202.248.45.254 .1.3.6.1.
rocommunity niftycloud 10.100.128.14 .1.3.6.1.
rocommunity niftycloud 10.100.144.15 .1.3.6.1.
disk / 10000
_SNMPDCONF_
/usr/sbin/update-rc.d snmpd enable
/etc/init.d/snmpd restart
## NIFTY Cloud API Tools の設定
/usr/bin/wget -P /home/${USER_NAME}/ 'http://cloud.nifty.com/api/sdk/NIFTY_Cloud_api-tools.zip'
/usr/bin/unzip -d /home/${USER_NAME}/ /home/${USER_NAME}/NIFTY_Cloud_api-tools.zip
/bin/rm -rf /home/${USER_NAME}/NIFTY_Cloud_api-tools.zip
/bin/rm -rf /home/${USER_NAME}/NIFTY_Cloud_api-tools/bin/*.cmd
/bin/chown -R ${USER_NAME}:${USER_NAME} /home/${USER_NAME}/NIFTY_Cloud_api-tools/
/bin/chmod 755 /home/${USER_NAME}/NIFTY_Cloud_api-tools/bin/*
/bin/cat << _NCSSCONF_ >> /home/${USER_NAME}/.zshrc
## NIFTY Cloud API Settings
export NIFTY_CLOUD_HOME=/home/${USER_NAME}/NIFTY_Cloud_api-tools/
export PATH=\${PATH}:\${NIFTY_CLOUD_HOME}/bin
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre/
_NCSSCONF_
## Update後のkernelにドライバ適用
/bin/cat << _RCLOCAL_VM_TOOLS_UPGRADAR_ > /etc/rc3.d/S90vmware-tools-upgrader
#!/bin/sh
/bin/rm -rf /etc/rc3.d/S90vmware-tools-upgrader
/usr/sbin/vmware-tools-upgrader -p "-d"
/sbin/shutdown -r now
_RCLOCAL_VM_TOOLS_UPGRADAR_
/bin/chmod 755 /etc/rc3.d/S90vmware-tools-upgrader
## After kernel Update Reboot
/sbin/shutdown -r now
) 2>&1 | /usr/bin/tee /var/log/Ubuntu1404_64bit_Plain_setup_script_for_niftycloud-installer.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment