Skip to content

Instantly share code, notes, and snippets.

@echochamber
Last active December 21, 2015 08:09
Show Gist options
  • Save echochamber/6a6f8605be907f2ec0ca to your computer and use it in GitHub Desktop.
Save echochamber/6a6f8605be907f2ec0ca to your computer and use it in GitHub Desktop.
#########################################################
# User Additions
#########################################################
#########################################################
# User Defined Variables
#########################################################
#
#########################################################
# User Defined Functions
#########################################################
# function bashrc_edit()
# Open .bashrc and edit it, then reload it
function bashrc_edit ()
{
vim ~/.bashrc +121
source ~/.bashrc
green='\e[0;32m'
NC='\e[0m'
echo -e "${green}$HOME/.bashrc edited and reloaded${NC}"
#copy .bash_profile to git directory
cp -p -fr ~/.bashrc ~/bash/.bashrc
}
# function edit vhost()
# @param string - name of vhost file in /etc/apache2/sites-available/
# if running as root, open vhosts file if exists for editing
function edit_vhost ()
{
#require root user
if [[ $(/usr/bin/id -u) -ne 0 ]]
then
echo "Not running as root"
exit
fi
vhost=$1
vhostsDir="/etc/apache2/sites-available/"
localhostRootDir="/var/www/"
if [ -e $vhostsDir$vhost ]
then
vim $vhostsDir$vhost
else
echo "No vhost file $vhostsDir$vhost"
fi
}
# function make vHost()
#
# @param string - name of vhost (ex: personalsite.dev)
# creates a vhost file in /etc/apache2/sites-available/{param1}
#
# creates a directory in /var/www/{param1}/
# sets directory ownership to current user
# sets permissions on directory to 755
# edits /etc/hosts file and adds line "127.0.1.1 {param1}"
# turns on the virtual host
# restarts apache
function make_vhost()
{
#require root user
if [[ $(/usr/bin/id -u) -ne 0 ]]
then
echo "Not running as root"
exit
fi
vhost=$1
vhostsDir="/etc/apache2/sites-available/"
localhostRootDir="/var/www/"
if [ ! -a $vhostsDir$vhost ] && [ ! -d $localhostRootDir$vhost ]
then
cp $vhostsDir"default" $vhostsDir$vhost
sed -i "s/\/var\/www\//&$vhost\//g" $vhostsDir$vhost
sed -i "s/\/var\/www/&\/$vhost/g" $vhostsDir$vhost
cat "127.0.1.1 $vhost" >> /etc/hosts
mkdir $localhostRootDir$vhost
chown $USER:$USER $localhostRootDir$vhost
chmod -R 755 $localhostRootDir$vhost
a2ensite $vhost
else
red='\e[0;31m'
NC='\e[0m'
echo -e "${red}Already a directory made with that name or a vhost running under that name${NC}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment