Last active
October 14, 2017 18:31
-
-
Save seizo3/8dc3f5c34db8cfef5a6389f4731514ae to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# test if the user is root | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
if [ -z "$1" ] | |
then | |
echo "No username supplied" | |
fi | |
DEPS='zsh git vim' | |
DEF_SHELL='/usr/bin/zsh' | |
USER_NAME=$1 | |
# install deps | |
# ubuntu | |
apt-get update && apt-get install -y $DEPS | |
# create the user | |
useradd -m -s $DEF_SHELL $USER_NAME | |
if [ $? -eq 0 ]; then | |
echo 'User created' | |
passwd $USER_NAME | |
else | |
echo "Unable to create user: [%d] when executing useradd" $? | |
exit $? | |
fi | |
# give the user sudo privileges | |
echo $USER_NAME ' ALL=(ALL:ALL) ALL' >> /etc/sudoers | |
# change to $USER_NAME for the rest of the script | |
exec sudo -i -u $USER_NAME /bin/bash - <<'EOF' | |
# move to the new users home | |
cd $HOME | |
# install oh-my-zsh | |
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" | |
# remove the generated .zshrc file | |
rm -rf $HOME/.zshrc | |
# install spacemacs configs | |
git clone https://github.com/syl20bnr/spacemacs $HOME/.emacs.d | |
git clone --bare https://github.com/seizo3/cfg.git $HOME/.cfg | |
function config { | |
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@ | |
} | |
mkdir -p .config-backup | |
config checkout | |
if [ $? = 0 ]; then | |
echo "Checked out config."; | |
else | |
echo "Backing up pre-existing dot files."; | |
config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} .config-backup/{} | |
fi; | |
config checkout | |
config config status.showUntrackedFiles no | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment