Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Open LiteSpeed One Click Installation for non-root users v1.0
#!/bin/bash
##############################################################################
# Open LiteSpeed is an open source HTTP server. #
# Copyright (C) 2013 - 2017 LiteSpeed Technologies, Inc. #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see http://www.gnu.org/licenses/. #
##############################################################################
## Install
OS_VERSION=UNKNOWN
OS_TYPE=`uname -m`
### Status
OLS_INSTALLED=0
ALL_ERRORS=0
## Server
LS_VERSION=1.4.27
LS_PACKAGE_NAME=openlitespeed-${LS_VERSION}.tgz
LS_SERVER_ROOT_CURRENT=!/
LS_SERVER_ROOT=`pwd`/$LS_SERVER_ROOT_CURRENT
LS_SERVER_BUILD_CURRENT=${LS_SERVER_ROOT_CURRENT}0/
LS_SERVER_BUILD=${LS_SERVER_ROOT}0/
LS_USER=$USER
LS_GROUP=$USER
LS_EMAIL=root@localhost
LS_ADMIN=admin
LS_PASSWORD=123456
echoYellow()
{
echo -e "\033[38;5;148m$@\033[39m"
}
echoGreen()
{
echo -e "\033[38;5;71m$@\033[39m"
}
echoRed()
{
echo -e "\033[38;5;203m$@\033[39m"
}
function prepare
{
echoGreen "Preparing installation..."
# Check
# Root
if [ -d "$LS_SERVER_ROOT_CURRENT" ]; then
echoRed "LWS root folder exists! Do you want to continue the installation? [y/N]"
read answer1
if [ "x$answer1" = "x" ] || [ "x$answer1" = "xn" ] || [ "x$answer1" = "xN" ]; then
exit 0
fi
else
echoGreen "Creating root folder..."
mkdir $LS_SERVER_ROOT_CURRENT
fi
# Build
if [ -d "$LS_SERVER_BUILD_CURRENT" ]; then
echoRed "LWS build folder exists! Do you want to continue the installation? [y/N]"
read answer1
if [ "x$answer1" = "x" ] || [ "x$answer1" = "xn" ] || [ "x$answer1" = "xN" ]; then
exit 0
fi
else
echoGreen "Creating build folder..."
mkdir $LS_SERVER_BUILD_CURRENT
fi
echoGreen "Enter in LWS build folder..."
cd $LS_SERVER_BUILD_CURRENT
if [ -f "$LS_PACKAGE_NAME" ]; then
echo "Package exists! Do you want delete it to proceed with the installation? Type n to quit, otherwise will continue. [Y/n]"
read answer2
if [ "x$answer2" = "x" ] || [ "x$answer2" = "xy" ] || [ "x$answer2" = "xY" ]; then
echo "Clearing file remains..."
rm -rf ${LS_PACKAGE_NAME}*
fi
fi
echoGreen "Downloading source package..."
wget http://open.litespeedtech.com/packages/${LS_PACKAGE_NAME}
echoGreen "Decompressing package in current directory..."
tar --strip-components=1 -zxvf ${LS_PACKAGE_NAME}
}
function config
{
echoGreen "Enter in build folder..."
cd $LS_SERVER_BUILD
echoGreen "Configure..."
./configure \
--prefix=${LS_SERVER_ROOT} \
--with-user=${LS_USER} \
--with-group=${LS_GROUP} \
--with-admin=${LS_ADMIN} \
--with-password=${LS_PASSWORD} \
--with-email=${LS_EMAIL} \
--enable-http2
}
function build
{
echoGreen "Enter in build folder..."
cd $LS_SERVER_BUILD
### Stop Server
if [ -f "${LS_SERVER_ROOT}/bin/lswsctrl" ]; then
sudo ${LS_SERVER_ROOT}/bin/lswsctrl stop
fi
### Make
echoGreen "Make..."
make
echoGreen "Make install..."
make install
### Finish
if [ $? != 0 ]; then
echoRed "An error occurred during Open Lite Speed installation."
ALL_ERRORS=1
else
### Start Server
sudo ${LS_SERVER_ROOT}/bin/lswsctrl start
### Bye
if [ "x$ALL_ERRORS" = "x0" ]; then
echoGreen "Congratulations! Installation finished."
echoGreen 'Thanks for using "OpenLiteSpeed One Click Installation for non-root users".'
echo
echo "Installation path: $LS_SERVER_ROOT"
echo
echo "Open LiteSpeed Version: $LS_VERSION"
echo "WebServer Email: $LS_EMAIL"
echo "User Admin Login: $LS_ADMIN"
echo "User Admin Password: $LS_PASSWORD"
echo
echo "Web Admin Address (default): localhost:7080"
echo "Web Server Address (default): localhost:8088"
echo
echoGreen "Check ${LS_SERVER_ROOT}/logs/ if you have problems with WebAdmin or Web Server access."
echoGreen "Check build/dist/install.sh, build/Makefile.am and build/configure for more options of installation."
echoGreen "Enjoy!"
else
echoYellow "Installation finished. It seems some errors occurred, please check this as you may need to manually fix them."
fi
echo
fi
}
function install
{
echo
echoRed "You need to install dependencies with the root user before continuing:"
echoYellow "sudo apt-get install build-essential rcs libpcre3-dev libexpat1-dev libssl-dev libgeoip-dev libudns-dev zlib1g-dev libxml2 libxml2-dev libpng-dev openssl"
echo
echo "Installation path: $LS_SERVER_ROOT"
echo "Build path: $LS_SERVER_BUILD"
echo
echo "Open LiteSpeed Version: $LS_VERSION"
echo "WebServer Email: $LS_EMAIL"
echo "User Admin Login: $LS_ADMIN"
echo "User Admin Password: $LS_PASSWORD"
echoYellow 'Is the settings correct? Type n to quit, otherwise will continue. [Y/n]'
read answer
if [ "x$answer" = "xN" ] || [ "x$answer" = "xn" ]; then
echoGreen "Aborting installation!"
exit 0
fi
### Check
if [ "x$OLS_INSTALLED" = "x1" ]; then
echoRed "OpenLiteSpeed is already installed in this path $LS_SERVER_ROOT."
echo
exit 0
fi
### Prepare
prepare
### Configure
config
### Build
build
### Clean
}
function uninstall
{
echoRed 'Are you sure you want to uninstall LWS? [Y/n]'
read answer
if [ "x$answer" = "xN" ] || [ "x$answer" = "xn" ]; then
echoGreen "Aborting uninstall!"
exit 0
else
echo "Uninstalling..."
if [ "x$OLS_INSTALLED" != "x1" ]; then
echoYellow "OpenLiteSpeed not installed... Attempt to clean installation..."
fi
echoYellow "Stop LiteSpeed..."
sudo ${LS_SERVER_ROOT}bin/lswsctrl stop
echoRed "Removing directories..."
rm -rf ${LS_SERVER_ROOT}
echoGreen "Uninstalled."
fi
}
function usage
{
echoGreen "Usage: $0 [options] [options] ..."
echoGreen "Options:"
echoGreen " --install, to install OpenLiteSpeed!"
echoGreen " --uninstall, to uninstall OpenLiteSpeed and remove installation directory."
echoGreen " --help, to display usage."
echo
}
echoYellow '/*********************************************************************************************'
echoYellow '* Open LiteSpeed One Click Installation for non-root users v1.0 *'
echoYellow '* Copyright (C) 2016 LiteSpeed Technologies, Inc. *'
echoYellow '*********************************************************************************************/'
### 1) Check ###
### Root
#INST_USER=`id -u`
#if [ ${INST_USER} = 0 ]; then
# echoRed "Sorry, only non-root user can install."
# echo
# exit 1
#fi
### OS Version
OS_VERSION=
if [ -f /etc/lsb-release ]; then
cat /etc/lsb-release | grep "DISTRIB_RELEASE=12." > /dev/null
if [ $? = 0 ]; then
OS_VERSION=UBUNTU12
else
cat /etc/lsb-release | grep "DISTRIB_RELEASE=14." > /dev/null
if [ $? = 0 ]; then
OS_VERSION=UBUNTU14
else
cat /etc/lsb-release | grep "DISTRIB_RELEASE=16." > /dev/null
if [ $? = 0 ]; then
OS_VERSION=UBUNTU16
else
cat /etc/lsb-release | grep "DISTRIB_RELEASE=18." > /dev/null
if [ $? = 0 ]; then
OS_VERSION=MINT18
fi
fi
fi
fi
### Debian
elif [ -f /etc/debian_version ]; then
cat /etc/debian_version | grep "^7." > /dev/null
if [ $? = 0 ]; then
OS_VERSION=DEBIAN7
else
cat /etc/debian_version | grep "^8." > /dev/null
if [ $? = 0 ]; then
OS_VERSION=DEBIAN8
else
cat /etc/debian_version | grep "^9." > /dev/null
if [ $? = 0 ]; then
OS_VERSION=DEBIAN9
fi
fi
fi
fi
if [ "x$OS_VERSION" = "x" ]; then
echoRed "Sorry, currently One Click Installation only supports Debian(7-9) and Ubuntu(12,14,16)."
echo
exit 1
else
echoGreen "Current platform is $OS_VERSION."
fi
### Installations (need to improve)
### Lite Speed
if [ -e ${LS_SERVER_ROOT}bin/openlitespeed ]; then
OLS_INSTALLED=1
fi
### Dependencies
### wget
which wget > /dev/null 2>&1
if [ $? != 0 ]; then
apt-get -y install wget
which wget > /dev/null 2>&1
if [ $? != 0 ]; then
echoRed "An error occurred during wget installation."
exit 0
fi
fi
### 2) Configure ###
while [ "$1" != "" ]; do
case $1 in
--uninstall ) uninstall
exit 0
;;
--install ) install
exit 0
;;
--prepare ) prepare
exit 0
;;
--configure ) config
exit 0
;;
--build ) build
exit 0
;;
* ) usage
exit 0
;;
esac
shift
done
#### 3) Welcome #####
usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment