Skip to content

Instantly share code, notes, and snippets.

@pacojp
Last active December 18, 2015 01:28
Show Gist options
  • Save pacojp/5703761 to your computer and use it in GitHub Desktop.
Save pacojp/5703761 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# # sample usage
# curl -o /tmp/init_ec2.sh https://gist.github.com/pacojp/5703761/raw
# nohup /bin/bash /tmp/init_ec2.sh > /tmp/init_ec2.sh.log && rm -f /tmp/init_ec2.sh &
#
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# set hostname by user data
mkdir -p /root/bin
curl -o /root/bin/set_hostname.sh https://gist.github.com/pacojp/5716923/raw
echo "/bin/bash /root/bin/set_hostname.sh" >> /etc/rc.local
/bin/bash /root/bin/set_hostname.sh
# set local
/bin/cp -f /usr/share/zoneinfo/Japan /etc/localtime
# create swap for t1.micro instance
instance_type=`ec2-metadata -t`
t1micro_string="instance-type: t1.micro"
if [ "${instance_type}" = "${t1micro_string}" ]; then
dd if=/dev/zero of=/swap.img bs=1M count=1024
chmod 600 /swap.img
mkswap /swap.img
swapon /swap.img
echo "/swap.img none swap defaults 0 0" >> /etc/fstab
fi
# install a lot by yum
yum install -y git autoconf openssl-devel readline-devel zlib-devel curl-devel procps gcc gcc-devel patch
yum install -y php54 php54-devel php54-devel php54-mbstring php54-mysql php54-pdo pcre pcre-devel munin-node
# can not erace old ruby because of dependency of ami-tools
# yum remove -y ruby
useradd webadm
useradd sysadm
# install rbenv
#cd /usr/local/
#git clone https://github.com/sstephenson/rbenv.git rbenv
#git clone git://github.com/sstephenson/ruby-build.git rbenv/plugins/ruby-build
#mkdir rbenv/shims rbenv/versions
#groupadd rbenv
#chgrp -R rbenv rbenv
#chmod -R g+rwxXs rbenv
#
#cd rbenv/plugins/ruby-build
#./install.sh
#
#cat <<EOF > /etc/profile.d/rbenv.sh
#export RBENV_ROOT="/usr/local/rbenv"
#export PATH="/usr/local/rbenv/bin:\$PATH"
#eval "\$(rbenv init -)"
#EOF
#source /etc/profile.d/rbenv.sh
#
#rbenv install 2.0.0-p195
#rbenv global 2.0.0-p195
# install least gems
#gem install bundler --no-rdoc --no-ri
#rbenv rehash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment