Skip to content

Instantly share code, notes, and snippets.

@alghanmi
Last active December 26, 2015 05:08
Show Gist options
  • Select an option

  • Save alghanmi/7098036 to your computer and use it in GitHub Desktop.

Select an option

Save alghanmi/7098036 to your computer and use it in GitHub Desktop.
Basic VPS Account Setup
##
## Setup Env Variables
##
GIT_USERNAME=""
GIT_EMAIL=""
GIT_EDITOR=vim
SSH_KEY_COMMENT="$USER@$(hostname -f)"
SSH_KEY_SIZE=4096
if [ -z "$GIT_USERNAME" -o -z "$GIT_EMAIL" ]; then
echo "Git username and email need to be specified before proceed"
exit 1;
fi
##
## Bash Setup
##
#Colors Prompt
sed -i 's/\#force_color_prompt=/force_color_prompt=/' ~/.bashrc
sed -i 's/\(\w*\)\#\(alias grep.*\)/\1\2/g' ~/.bashrc
sed -i 's/\(\w*\)\#\(alias fgrep.*\)/\1\2/g' ~/.bashrc
sed -i 's/\(\w*\)\#\(alias egrep.*\)/\1\2/g' ~/.bashrc
#Git Branch in PS1
sed -i '/^if \[ "$color_prompt" = yes \].*/ { n ; s/\(\s*\).*/\1PS1='\''${debian_chroot:+($debian_chroot)}\\[\\033[01;31m\\]\\u@\\h:\\[\\033[01;31m\\]\\w \\[\\033[01;38;5;137m\\]$(__git_ps1 "(%s)")\\[\\033[00m\\]\\$ '\''/ }' ~/.bashrc
#Bash History
sed -i 's/^HISTSIZE=.*/HISTSIZE=10000/' ~/.bashrc
sed -i 's/^HISTFILESIZE=.*/HISTFILESIZE=40000/' ~/.bashrc
sed -i '/^HISTFILESIZE=.*/a PROMPT_COMMAND="history -a;"' ~/.bashrc
#Bashrc Modifications
echo -e "\n\n" >> ~/.bashrc
curl --silent https://gist.githubusercontent.com/alghanmi/7095326/raw/bashrc_additions.sh >> ~/.bashrc
echo "" >> ~/.bashrc
##
## Git Setup
##
#User Info
git config --global user.name "$GIT_USERNAME"
git config --global user.email "$GIT_EMAIL"
#Editor & Diff
git config --global core.editor "$GIT_EDITOR"
git config --global merge.tool vimdiff
#Output color
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global color.ui auto
#LF Normalization (Linux & MacOS)
git config --global core.autocrlf input
#LF Normalization (Windows)
#git config --global core.autocrlf true
#Adapt new push behavior
git config --global push.default simple
#Global gitignore
curl --silent -o ~/.gitignore_global https://gist.githubusercontent.com/alghanmi/7095543/raw/
git config --global core.excludesfile ~/.gitignore_global
##
## GPG Key Management
##
#Generate GnuPG configuration
gpg --list-keys &> /dev/null
#Set digest preferences. Namely, SHA256 over SHA1
echo "" >> ~/.gnupg/gpg.conf
echo "# Use SHA2 in preference to SHA1" >> ~/.gnupg/gpg.conf
echo "personal-digest-preferences SHA256" >> ~/.gnupg/gpg.conf
echo "cert-digest-algo SHA256" >> ~/.gnupg/gpg.conf
echo "default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed" >> ~/.gnupg/gpg.conf
#Refresh GPG Keys twice a month on days 1 and 15.
crontab -l > $USER.cron
echo -e "0\t0\t1,15\t*\t*\tgpg --refresh-keys" >> $USER.cron
crontab $USER.cron
rm $USER.cron
##
## SSH Configuration
##
#Create .ssh directory & required files
if [ ! -d ~/.ssh ]; then
mkdir -p ~/.ssh
chmod 700 ~/.ssh
fi
if [ ! -e ~/.ssh/authorized_keys ]; then
touch ~/.ssh/authorized_keys
chmod 644 ~/.ssh/authorized_keys
fi
if [ ! -e ~/.ssh/config ]; then
touch ~/.ssh/config
chmod 600 ~/.ssh/config
curl --silent https://gist.githubusercontent.com/alghanmi/7095326/raw/ssh_config.conf >> ~/.ssh/config
fi
#Create Key Pair
if [ ! -e ~/.ssh/id_rsa -o ! -e ~/.ssh/id_rsa.pub ]; then
ssh-keygen -t rsa -b $SSH_KEY_SIZE -C "$SSH_KEY_COMMENT"
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
fi
##
## Misc Modification
##
#Add nano syntax highlighting
find /usr/share/nano/ -name "*.nanorc" -print | sed -e 's/^\(.*\)$/include "\1"/g' >> ~/.nanorc
#TMUX configuration
mkdir -p ~/.tmux.conf.d
curl --silent -L -o ~/.tmux.conf https://raw.github.com/alghanmi/dotfiles.conf/master/tmux/tmux.conf
curl --silent -L -o ~/.tmux.conf.d/tmuxcolors-dark.conf https://raw.github.com/seebi/tmux-colors-solarized/master/tmuxcolors-dark.conf
curl --silent -L -o ~/.tmux.conf.d/restart-required.sh https://raw.github.com/alghanmi/dotfiles.conf/master/tmux/restart-required.sh
chmod 755 ~/.tmux.conf.d/restart-required.sh
curl --silent -L -o ~/.tmux.conf.d/clipboard-linux.conf https://raw.github.com/alghanmi/dotfiles.conf/master/tmux/clipboard-linux.conf
echo "source ~/.tmux.conf.d/clipboard-linux.conf" >> ~/.tmux.conf
#Bash completion for TMUX
sudo ln -s /usr/share/doc/tmux/examples/bash_completion_tmux.sh /etc/bash_completion.d/tmux
#Install directory colors compatible with Solarized Dark
curl -sL -o .dircolors https://github.com/seebi/dircolors-solarized/raw/master/dircolors.256dark
#VIM Setup
git clone --recursive git@github.com:alghanmi/dotvim.git ~/.vim
mkdir -p ~/.vim/.swap ~/.vim/.undo
ln -s ~/.vim/vimrc ~/.vimrc
cd ~/.vim
git submodule foreach git pull origin master
cd -
@alghanmi

Copy link
Copy Markdown
Author
curl -sLO https://gist.githubusercontent.com/alghanmi/7098036/raw/vps_account_setup.sh
chmod 755 vps_account_setup.sh
vim vps_account_setup.sh
./vps_account_setup.sh

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