Skip to content

Instantly share code, notes, and snippets.

@geta6
Created May 16, 2012 23:18
Show Gist options
  • Select an option

  • Save geta6/2714829 to your computer and use it in GitHub Desktop.

Select an option

Save geta6/2714829 to your computer and use it in GitHub Desktop.
初期状態のUbuntuサーバを俺仕様にするスクリプト
#!/bin/bash
TMP=`mktemp`
if [[ $1 == '-h' ]]; then
echo "Usage: $0"
echo "Available option: [skip | Skip OS version check]"
exit
fi
if [[ $1 != 'skip' ]]; then
VER='Ubuntu 12.04 LTS'
if [[ $VER != `lsb_release -d -s` ]]; then
apt-get install update-manager-core
do-release-upgrade -d
fi
fi
[[ $UID != 0 ]] && echo 'Please exec with super user.' && exit
trap '' 2
# Passwd
echo '[upgrade] > Set root password.'
echo '[upgrade] > If you already set, cancel with ^c'
passwd
# Package
echo '[upgrade] > apt-get update...'
apt-get update &
yes | apt-get upgrade &
wait
# Package
echo '[upgrade] > Package install.'
yes | apt-get purge apache2 &
yes | apt-get install git zsh vim build-essential curl nginx-full python-software-properties sysv-rc-conf ruby-rvm php5-cli php5-fpm php5-xdebug php-apc clamav &
wait
sysv-rc-conf rsync off
# Change shell
echo '[upgrade] > Chsh to ZSH.'
chsh -s /bin/zsh
# Change Dotfiles
echo '[upgrade] > Install Dotfiles.'
cd ~
mkdir lib
git clone https://github.com/geta6/dotfiles lib/dotfiles
cd lib/dotfiles && ./install
echo ':BundleInstall' | vim
# Locale
echo '[upgrade] > GET & SET locale to ja_JP.UTF-8.'
echo 'ja_JP.UTF-8 UTF-8' >> /var/lib/locales/supported.d/local
locale-gen
source ~/.zshenv > /dev/null 2&>1
# SSH
echo '[upgrade] > PermitRootLogin no'
cat /etc/ssh/sshd_config \
| sed -e "s/[#]*PermitRootLogin yes/PermitRootLogin no/g"\
> $TMP
yes|mv -f $TMP /etc/ssh/sshd_config
# PAM
echo '[upgrade] > PAM-Wheel'
cat /etc/pam.d/su \
| sed -e 's/# auth required pam_wheel.so/auth required pam_wheel.so group=adm/g'\
> $TMP
yes|mv -f $TMP /etc/pam.d/su
# sudoers
echo '[upgrade] > sudoers to %adm'
echo '[upgrade] > !!!WARNING!!! sudo user must be joined to "adm"'
cat /etc/sudoers | sed -e 's/^\([^#].*\)$/#\1/g' > $TMP
yes|mv -f $TMP /etc/sudoers
echo 'Defaults env_reset,targetpw\n%adm ALL=(root) ALL' >> /etc/sudoers
# vim
echo '[upgrade] > create /bin/vi'
cp `which vi` /bin/vi
# disable IPv6
echo '[upgrade] > disabling IPv6 transport'
echo 'net.ipv6.conf.all.disable_ipv6=1' >> /etc/sysctl.conf
# memcache /tmp
echo '[upgrade] > now /tmp is on memory 256MB (/etc/fstab)'
echo 'tmpfs /tmp tmpfs defaults,size=256M 0 2' >> /etc/fstab
# SSL
echo '[upgrade] > create SSL'
cd /etc/ssl/private
echo '[upgrade] > Enter Passphrase.'
openssl genrsa -des3 -out server.key 2048
echo '[upgrade] > Enter Same Passphrase.'
openssl rsa -in server.key -out server.key
echo '[upgrade] > Enter Some Info.'
echo '[upgrade] > JP. Tokyo. Machida. Keio. Perms. fqdn.servername. mail@address'
openssl req -new -days 3650 -key server.key -out server.csr
openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650
chmod 400 server.*
# ClamAv
cd ~
freshclam
wget http://www.eicar.org/download/eicar.com
clamscan --infected --remove --recursive ./
echo '[upgrade] > DONE.'
echo '[upgrade] > sudoers joined to "adm"? so, type "reboot".'
zsh
@geta6

geta6 commented May 16, 2012

Copy link
Copy Markdown
Author

Ubuntu Serverをイニシャライズするscriptです

セットアップ済みのubuntuでは実行しないでください

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment