Created
February 21, 2014 00:19
-
-
Save kapfenho/9126296 to your computer and use it in GitHub Desktop.
Shell function lib for system config and deployment tasks, produces easy to read configs
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
# Deployment shell functions | |
# | |
# Several functions for creating users and groups, adding system | |
#+packages, and setting system parameters and security limits. | |
# | |
_LIBDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
# create unix group, check if exists before | |
# params: name, id | |
create_group() { | |
grep $1 /etc/group &> /dev/null | |
[[ $? -eq 0 ]] || echo "groupadd -g $2 $1" | |
} | |
# create unix users, check if exists before | |
# params: name, id | |
create_user() { | |
grep $1 /etc/passwd &> /dev/null | |
[[ $? -eq 0 ]] || echo "useradd -u $2 -g $3 -G $4 $1" | |
} | |
# add sudoer file for user, all permissions, no pasword | |
# params: username | |
sudo_for() { | |
_sudoer=/etc/sudoers.d/$1 | |
if [ ! -a ${_sudoer} ] | |
then | |
echo "echo \"$1 ALL=(ALL) NOPASSWD: ALL\" > ${_sudoer}" | |
echo "chmod 440 ${_sudoer}" | |
fi | |
} | |
# create directory and chown to user:group | |
# params: directory, user:group | |
dir_for() { | |
if [ ! -a $1 ] | |
then | |
echo "mkdir -p $1; chown -R $2 $1" | |
fi | |
} | |
# setting system setting to value | |
# params: setting, value | |
set_sysctl() { | |
_sysctl=/etc/sysctl.conf | |
if grep -q $1 ${_sysctl} | |
then | |
echo "sed -i -e \"/$1/d\" ${_sysctl}" | |
fi | |
echo "echo \"$1=$2\" >> ${_sysctl}" | |
} | |
# activate the sysctl changes | |
# no params | |
activate_sysctl() { | |
echo "/sbin/sysctl -p" | |
} | |
# setting system security limits | |
# params: setting, value | |
# TODO: check to create file in /etc/security/limits.d/. | |
set_limit() { | |
_syslmt=/etc/security/limits.conf | |
echo "echo \"$1\" >> ${_syslmt}" | |
} | |
# install packages | |
add_packages() { | |
_packs=$1 | |
echo yum check-update | |
eval echo yum install -y \${$_packs[*]} | |
} | |
# add repo epel for additional packages | |
add_epel_rpm() { | |
echo "rpm -Uvh $1" | |
} | |
# disable system service via chkconfig | |
# param: service_name | |
disable_service() { | |
chkconfig | grep $1 &> /dev/null | |
[[ $? -eq 0 ]] && echo "chkconfig --del $1" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment