Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # LICENSE: SEE http://forum.kerbalspaceprogram.com/threads/92665-DMP-Linux-Server-Tools
- # ---------------------------------------------------------------------------------------------------------
- # PACKAGE
- # ---------------------------------------------------------------------------------------------------------
- # System Users
- # SysUser[0]="dmpserver"
- # Dirs
- # Target;chmodkey
- # NewDir[0]="/usr/share/dmpserver;755"
- # Pastebin Targets
- # Target;Key;Directory;chmodkey (Dir Must Exist)
- # Target[0]="dmpserver;X4E46Af5;/usr/bin;755"
- # Dependencies
- # Depends[0]="screen"
- # Disclaimer
- Disclaimer="
- This will be displayed line-by-line before installing the scripts. It will then ask the user
- yes or no."
- # Post-Installation Script
- function postInstall(){
- echo "This function will be called after the above has been accomplished."
- }
- # ---------------------------------------------------------------------------------------------------------
- # INSTALLER
- # ---------------------------------------------------------------------------------------------------------
- # Variables
- PASTEBIN_API="http://pastebin.com/raw.php?i="
- ifsNewline=$'\n'
- ifsReset=$IFS
- # Functions
- function linDistCheck(){
- if hash rpm 2> /dev/null ; then
- D_CHECK="rhel"
- elif hash dpkg 2> /dev/null ; then
- D_CHECK="debian"
- else
- echo "You are (probably) not running a Debian or RHEL based system!"
- echo "Your linux version is (probably) not supported."
- exit 1
- fi
- }
- function printDisclaimer(){
- IFS=$ifsNewline
- for line in $Disclaimer ; do
- echo $line
- done
- IFS=$ifsReset
- }
- function dependencyCheck(){
- for dependency in ${Depends[@]} ; do
- if hash $dependency 2> /dev/null ; then
- :
- else
- echo "This program requires '$dependency' to be available."
- echo "Please install it (try 'apt-get install $dependency' on Debian, or 'yum install $dependency' on RHEL) before continuing."
- exit 1
- fi
- done
- }
- function addSysUserList(){
- for user in ${SysUser[@]} ; do
- echo "Adding system user '$user'..."
- if id -u $user >/dev/null 2> /dev/null;
- then
- echo "User '$user' already exists! Skipping creation."
- else
- case "$D_CHECK" in
- "rhel")
- useradd -r $user
- usermod -s /bin/false $user
- ;;
- "debian")
- adduser -system $user
- ;;
- *) echo "Distro Not Supported." ;;
- esac
- echo "Added system user '$user'."
- fi
- done
- }
- function installDirList(){
- for src in ${NewDir[@]} ; do
- tdir=$(echo -n "$src" | awk -F ";" '{print $1}')
- tcode=$(echo -n "$src" | awk -F ";" '{print $2}')
- echo "Adding directory '$tdir'..."
- if [ ! -d $tdir ];
- then
- mkdir $tdir
- chmod $tcode $tdir
- echo "Added directory '$tdir' with chmod code '$tcode'."
- else
- echo -e "Directory '$tdir' already exists! Skipping creation."
- fi
- done
- }
- function getPBinScript(){
- echo "Installing '$2'. File will be downloaded from ${PASTEBIN_API}$1"
- curl --progress-bar ${PASTEBIN_API}$1 | tr -d '\r' > $2
- echo "Installed '$2'."
- }
- function installPBinList(){
- t=0
- for src in ${Target[@]} ; do
- tname=$(echo -n "$src" | awk -F ";" '{print $1}')
- tkey=$(echo -n "$src" | awk -F ";" '{print $2}')
- tdir=$(echo -n "$src" | awk -F ";" '{print $3}')
- tcode=$(echo -n "$src" | awk -F ";" '{print $4}')
- if [ ! -d $tdir ];
- then
- echo -e "FATAL: Directory '$tdir' does not exist! Skipping file '$tdir'."
- else
- getPBinScript $tkey $tdir/$tname
- chmod $tcode $tdir/$tname
- fi
- ((t++))
- done
- }
- # ---------------------------------------------------------------------------------------------------------
- # EXECUTION
- # ---------------------------------------------------------------------------------------------------------
- if [ $(whoami) != 'root' ]; then
- echo "This program must be run with root permissions."
- exit 1
- fi
- printDisclaimer
- echo -n "Do you understand and agree to the terms above? [y/n]: "
- read answer
- case $answer in
- [Yy]*)
- linDistCheck
- dependencyCheck
- addSysUserList
- installDirList
- installPBinList
- postInstall
- exit
- ;;
- [Nn]*) exit;;
- *) echo "Answer must be y or n.";;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement