Last active
October 8, 2024 00:49
-
-
Save deepakkumarnd/8d2c597d10dc9a0bddb0 to your computer and use it in GitHub Desktop.
Server setup script
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
# This script has to be run as a root user | |
echo "* Updating system" | |
apt-get update | |
apt-get -y upgrade | |
echo "* Installing packages" | |
apt-get -y install build-essential libmagickcore-dev imagemagick libmagickwand-dev libxml2-dev libxslt1-dev git-core nginx redis-server curl nodejs htop | |
id -u deploy &> /dev/null | |
if [ $? -ne 0 ] | |
then | |
echo "* Creating user deploy" | |
useradd -m -g staff -s /bin/bash deploy | |
echo "* Adding user deploy to sudoers" | |
chmod +w /etc/sudoers | |
echo "deploy ALL=(ALL) ALL" >> /etc/sudoers | |
chmod -w /etc/sudoers | |
else | |
echo "* deploy user already exists" | |
fi | |
echo "* Installing rvm" | |
. /etc/profile.d/rvm.sh &> /dev/null | |
type rvm &> /dev/null | |
if [ $? -ne 0 ] | |
then | |
curl -L https://get.rvm.io | bash -s | |
echo "source /etc/profile.d/rvm.sh" >> /etc/bash.bashrc | |
. /etc/profile.d/rvm.sh &> /dev/null | |
else | |
echo "* rvm already installed" | |
fi | |
cat /etc/environment | grep RAILS_ENV | |
if [ $? -ne 0 ] | |
then | |
echo "RAILS_ENV=production" >> /etc/environment | |
fi | |
echo "* Adding a gemrc file to deploy user" | |
echo -e "verbose: true\nbulk_threshold: 1000\ninstall: --no-ri --no-rdoc --env-shebang\nupdate: --no-ri --no-rdoc --env-shebang" > /home/deploy/.gemrc | |
chmod 644 /home/deploy/.gemrc | |
chown deploy /home/deploy/.gemrc | |
chgrp staff /home/deploy/.gemrc | |
echo "* Adding ssh key to authorized_keys" | |
test -d /home/deploy/.ssh | |
if [ $? -ne 0 ] | |
then | |
mkdir /home/deploy/.ssh | |
chmod 700 /home/deploy/.ssh | |
chown deploy /home/deploy/.ssh | |
chgrp staff /home/deploy/.ssh | |
fi | |
# deepak's public key | |
echo "deepak's public key" > /home/deploy/.ssh/authorized_keys | |
chmod 600 /home/deploy/.ssh/authorized_keys | |
chown deploy /home/deploy/.ssh/authorized_keys | |
chgrp staff /home/deploy/.ssh/authorized_keys | |
echo "* Install ruby version 2.0.0" | |
ruby -v &> /dev/null | |
if [ $? -ne 0 ] | |
then | |
rvm install 2.1.0 | |
else | |
echo "* Ruby already installed" | |
fi | |
echo "* Add user deploy to rvm group" | |
usermod -a -G rvm deploy | |
rvm --default use 2.1.0 | |
ruby -v | |
echo "* DONE *" | |
echo "* Rebooting system *" | |
reboot |
Seems like there a probleme here(L7 to L9) a got a "* deploy user already exists" message. Fix it by removing &> /dev/null
@vijayn Thanks
@nicolas-besnard If deploy user does not exists it "id -u deploy &> /dev/null" returns 1, it returns 0 if the user exists, have you ran the script two times or do u have the user already ?
@42races Excellent! Excuse my ignorance, does this script generate a deploy
user who is not practically capable of running anything with sudo
? I tried sudo apt-get update
and I get a prompt for a password which was never set. Is that by design or am I missing s'thing obvious?
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good one :)