Get yer rails user in shape
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
#!/usr/bin/env bash | |
# install: | |
# bash < <(curl -L http://gist.github.com/raw/629402/moonshine_bootstrap.sh) | |
# | |
printf "===> Bootstrapping moonshine user: ${user} ...\n" | |
user=rails | |
if ! grep -q "^${user}:" /etc/group >/dev/null ; then | |
printf "===> Adding group: ${user} ...\n" | |
groupadd -g 2020 ${user} | |
fi | |
if ! grep -q "^${user}:" /etc/passwd >/dev/null ; then | |
printf "===> Adding user: ${user} ...\n" | |
useradd --comment "Rails Deployment User" --home /home/${user} \ | |
--gid ${user} --uid 2020 --system --shell /bin/bash ${user} | |
fi | |
printf "===> Creating home directory: /home/${user} ...\n" | |
mkdir -p /home/${user} | |
printf "===> Fixing up home directory permissions on: /home/${user} ...\n" | |
chown -R ${user}:${user} /home/${user} | |
if ! grep -q "^sudo:.*${user}" /etc/group >/dev/null ; then | |
printf "===> Adding user: ${user} to sudo group ...\n" | |
if grep -q "^sudo:.*:$" /etc/group >/dev/null ; then | |
perl -pi -e "s|^(sudo:.*):$|\$1:${user}|" /etc/group | |
else | |
perl -pi -e "s|^(sudo:.*)$|\$1,${user}|" /etc/group | |
fi | |
fi | |
printf "===> All done. W00t.\n\n" | |
printf "===> Need your rails password now so run:\n passwd $user\n\n" | |
unset user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment