core

by ligonier
3 deployments · 0 still active · last rev. 5 years ago

All the specific StackScripts used by Ligonier depend on the core packages installed by this StackScript. It handles getting a fresh Linode up to date and setup with the basic packages to run all the other StackScripts.

Compatible with: No distros currently supported
						#!/bin/bash
#
# ---
#
# Core StackScript - handles basic distribution setup
#
# All the specific StackScripts used by Ligonier depend on the core packages
# installed by this StackScript. It handles getting a fresh Linode up to date
# and setup with the basic packages to run all the other StackScripts.
#
# ---
#
# Copyright (c) 2010 Linode LLC / Christopher S. Aker <caker@linode.com>
# Copyright (c) 2011 Ligonier Ministries
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
#   this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
#   this list of conditions and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
#
# * Neither the names of Linode LLC, Ligonier Ministries nor the names of
#   their contributors may be used to endorse or promote products derived
#   from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

##
## System Related Functions
##

# Log activity
function log {
  echo "$1 `date '+%D %T'`" >> /root/log.txt
}

# Bring the system up to date
function update_system {
  apt-get update
  apt-get -y install aptitude
  aptitude -y full-upgrade
  
  log "Updated system..." 
}

# Install core packages
function install_core_packages {
  apt-get -y install wget less vim git-core build-essential zlib1g-dev libssl-dev libreadline5-dev openssh-server libyaml-dev libcurl4-openssl-dev libxslt-dev libxml2-dev
  
  log "Installed core packages..."
}

# Setup core preferences
function setup_core_preferences {
  sed -i -e 's/^#PS1=/PS1=/' /root/.bashrc
  sed -i -e "s/^#alias ll='ls -l'/alias ll='ls -al'/" /root/.bashrc
  
  log "Setup core preferences..."
}

# Returns the primary IP assigned to eth0
function system_primary_ip {
	echo $(ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }')
}

# Calls host on an IP address and returns its reverse dns
function get_rdns {
	if [ ! -e /usr/bin/host ]; then
		aptitude -y install dnsutils > /dev/null
	fi
	echo $(host $1 | awk '/pointer/ {print $5}' | sed 's/\.$//')
}

# Returns the reverse dns of the primary IP assigned to this system
function get_rdns_primary_ip {
	echo $(get_rdns $(system_primary_ip))
}


##
## Utility Functions
##

# Restarts services that have a file in /tmp/needs-restart/
function restartServices {
	for service in $(ls /tmp/restart-* | cut -d- -f2-10); do
		/etc/init.d/$service restart
		rm -f /tmp/restart-$service
	done
}

# Generate a random string
function randomString {
	if [ ! -n "$1" ];
		then LEN=20
		else LEN="$1"
	fi

	echo $(</dev/urandom tr -dc A-Za-z0-9 | head -c $LEN)
}