Open dvershinin opened 2 years ago
Our openlitespeed rpms are built from our pre-built binary package. the spec file is like
#
# The spec is to build OpenLiteSpeed rpm
#
Name: openlitespeed
Version: 1.7.15
Release: 2%{?dist}
Summary: OpenLiteSpeed
Group: Application/WebServer
License: GPLv3
URL: http://www.litespeedtech.com
BuildRoot: %{_tmppath}/%{name}-%{version}
AutoReqProv: no
BuildRequires: openssl
BuildRequires: wget
%if 0%{?rhel} >= 8
BuildRequires: libnsl
%endif
%if 0%{?rhel} < 8
BuildRequires: rcs
%endif
Requires: openssl
%if 0%{?rhel} >= 8
Requires: libnsl
%endif
%if 0%{?rhel} < 8
Requires: rcs
%endif
Requires: lsphp73 lsphp73-common lsphp73-gd lsphp73-process lsphp73-mbstring lsphp73-mysqlnd lsphp73-xml lsphp73-mcrypt lsphp73-pdo lsphp73-imap lsphp73-json lsphp73-opcache
%description
OpenLiteSpeed is a high-performance, lightweight, open source HTTP server developed and copyrighted by LiteSpeed Technologies. Users are free to download, use, distribute, and modify OpenLiteSpeed and its source code in accordance with the precepts of the GPLv3 license.
%package -n openlitespeed-debug
Group: Application/WebServer
Summary: Debug
Requires: openlitespeed == %{version}
%description -n openlitespeed-debug
OpenLiteSpeed debug binary.
%package -n openlitespeed-asan
Group: Application/WebServer
Summary: ASAN
Requires: openlitespeed == %{version}
%description -n openlitespeed-asan
OpenLiteSpeed asan binary.
%package -n ols-pagespeed
Group: Application/WebServer
Summary: Pagespeed
Requires: openlitespeed == %{version}
%description -n ols-pagespeed
Pagespeed module for openlitespeed webserver.
%package -n ols-modsecurity
Group: Application/WebServer
Summary: Mod Security
Requires: openlitespeed == %{version}
%description -n ols-modsecurity
Mod Security for openlitespeed webserver.
%prep
wget -q https://openlitespeed.org/packages/openlitespeed-%{version}.tgz
wget -q https://openlitespeed.org/packages/openlitespeed-%{version}.asan.tgz
wget -q https://openlitespeed.org/packages/openlitespeed-%{version}.dbg.tgz
tar -xzf openlitespeed-%{version}.tgz
tar -xzf openlitespeed-%{version}.asan.tgz
tar -xzf openlitespeed-%{version}.dbg.tgz
rm -rf *.tgz
%build
%install
rm -rf %{buildroot}
install -m 755 -d %{buildroot}/usr/local/lsws
rm -rf openlitespeed/ols.conf
sed -i -e 's:SERVERROOT=/usr/local/lsws:SERVERROOT=$1:g' openlitespeed/install.sh
sed -i -e 's:USE_LSPHP7=yes:USE_LSPHP7=no:g' openlitespeed/install.sh
sed -i -e 's:OPENLSWS_ADMINSSL=yes:OPENLSWS_ADMINSSL=no:g' openlitespeed/install.sh
sed -i -e 's:ln -sf "$LSWS_HOME/fcgi-bin/lsphp5" "$LSWS_HOME/fcgi-bin/lsphp":cd $LSWS_HOME/fcgi-bin/; ln -sf lsphp5 ./lsphp; cd -:g' openlitespeed/_in.sh
sed -i -e 's:mkdir $SERVERROOT:mkdir -p $SERVERROOT:g' openlitespeed/install.sh
sed -i -e 's|s:%LSWS_CTRL%:$LSWS_HOME/bin/lswsctrl:|s:%LSWS_CTRL%:/usr/local/lsws/bin/lswsctrl:|g' openlitespeed/functions.sh
./openlitespeed/install.sh %{buildroot}/usr/local/lsws
cp -pr openlitespeed-%{version}.asan %{buildroot}/usr/local/lsws/bin/openlitespeed.asan
cp -pr openlitespeed-%{version}.dbg %{buildroot}/usr/local/lsws/bin/openlitespeed.dbg
rm -f %{buildroot}/usr/local/lsws/admin/conf/admin_config.conf
cp -pr openlitespeed/admin/conf/admin_config_ssl.conf.in %{buildroot}/usr/local/lsws/admin/conf/admin_config.conf
sed -i -e "s:%ADMIN_PORT%:7080:g" %{buildroot}/usr/local/lsws/admin/conf/admin_config.conf
sed -i -e "s:%SSL_HOSTNAME%:webadmin:g" %{buildroot}/usr/local/lsws/admin/conf/admin_config.conf
install -m 755 -d %{buildroot}/etc/init.d
chmod u+w %{buildroot}/usr/local/lsws/admin/misc/lsws.rc
sed "s:%LSWS_CTRL%:/usr/local/lsws/bin/lswsctrl:" openlitespeed/admin/misc/lsws.rc.in > %{buildroot}/usr/local/lsws/admin/misc/lsws.rc
sed "s:%LSWS_CTRL%:/usr/local/lsws/bin/lswsctrl:" openlitespeed/admin/misc/lsws.rc.in > %{buildroot}/etc/init.d/lsws
chmod 0755 %{buildroot}/etc/init.d/lsws
chmod u+w %{buildroot}/usr/local/lsws/admin/misc/lsws.rc.gentoo
sed "s:%LSWS_CTRL%:/usr/local/lsws/bin/lswsctrl:" openlitespeed/admin/misc/lsws.rc.gentoo.in > %{buildroot}/usr/local/lsws/admin/misc/lsws.rc.gentoo
sed -i -e 's:fcgi-bin/lsphp:$SERVER_ROOT/lsphp73/bin/lsphp:g' %{buildroot}/usr/local/lsws/conf/httpd_config.conf
echo 'RPM' > %{buildroot}/usr/local/lsws/PLAT
%clean
%pre
getent group lsadm > /dev/null || groupadd -r lsadm
lsadm_gid=`grep ^lsadm: /etc/group | awk -F : '{ print $3; }'` >/dev/null 2>&1
getent passwd lsadm > /dev/null || useradd -g $lsadm_gid -d / -r -s /sbin/nologin -c "lsadm" lsadm >/dev/null 2>&1
usermod -G lsadm,nobody lsadm >/dev/null 2>&1
exit 0
%post
#############
#This is the beginning of the script to fix rpm file group and permission problem
# to replace the above hard coded one.
DEFAULT_USER="nobody"
DEFAULT_GROUP="nobody"
WS_USER=$DEFAULT_USER
WS_GROUP=$DEFAULT_GROUP
ADMIN_USER="lsadm"
LSWS_HOME="/usr/local/lsws"
OLD_USER=$DEFAULT_USER
OLD_GROUP=$DEFAULT_GROUP
grep -q nobody: "/etc/group"
if [ $? != 0 ] ; then
DEFAULT_GROUP="nogroup"
fi
if [ "$WS_GROUP" = "nobody" ] ; then
WS_GROUP=$DEFAULT_GROUP
fi
if [ -f "$LSWS_HOME/conf/httpd_config.xml" ] ; then
OLD_USER_CONF=`grep "<user>" "$LSWS_HOME/conf/httpd_config.xml"`
OLD_GROUP_CONF=`grep "<group>" "$LSWS_HOME/conf/httpd_config.xml"`
OLD_USER=`expr "$OLD_USER_CONF" : '.*<user>\(.*\)</user>.*'`
OLD_GROUP=`expr "$OLD_GROUP_CONF" : '.*<group>\(.*\)</group>.*'`
fi
if [ -f "$LSWS_HOME/conf/httpd_config.conf" ] ; then
#Now check if the user and group match with the conf file
OLD_USER_CONF=`grep "user" "$LSWS_HOME/conf/httpd_config.conf"`
OLD_GROUP_CONF=`grep "group" "$LSWS_HOME/conf/httpd_config.conf"`
OLD_USER=`expr "$OLD_USER_CONF" : '\s*user\s*\(\S*\)'`
OLD_GROUP=`expr "$OLD_GROUP_CONF" : '\s*group\s*\(\S*\)'`
fi
WS_USER=$OLD_USER
WS_GROUP=$OLD_GROUP
DIR_OWN=$WS_USER:$WS_GROUP
CONF_OWN=$WS_USER:$WS_GROUP
LOGDIR_OWN="root:$WS_GROUP"
grep "^lsadm:" /etc/passwd 1>/dev/null 2>&1
if [ $? -eq 0 ]; then
CONF_OWN="lsadm:lsadm"
fi
SDIR_OWN="root:root"
chown $SDIR_OWN $LSWS_HOME >/dev/null 2>&1
chown "$CONF_OWN" -R /usr/local/lsws/conf >/dev/null 2>&1
chown "$CONF_OWN" -R /usr/local/lsws/phpbuild >/dev/null 2>&1
if [ -d "/usr/local/lsws/autoupdate" ]; then
chown "$CONF_OWN" -R /usr/local/lsws/autoupdate >/dev/null 2>&1
fi
if [ -d "/usr/local/lsws/DEFAULT/conf" ]; then
chown "$CONF_OWN" -R /usr/local/lsws/DEFAULT/conf >/dev/null 2>&1
fi
if [ -d "/usr/local/lsws/Example/conf" ]; then
chown "$CONF_OWN" -R /usr/local/lsws/Example/conf >/dev/null 2>&1
fi
chown "$CONF_OWN" -R /usr/local/lsws/admin/conf >/dev/null 2>&1
chown "$CONF_OWN" -R /usr/local/lsws/admin/tmp >/dev/null 2>&1
chgrp $WS_GROUP /usr/local/lsws/admin/cgid >/dev/null 2>&1
chgrp $WS_GROUP /usr/local/lsws/admin/tmp >/dev/null 2>&1
chown "$CONF_OWN" $LSWS_HOME/admin/tmp/sess_* 1>/dev/null 2>&1
chown "$DIR_OWN" $LSWS_HOME/cachedata >/dev/null 2>&1
chown "$SDIR_OWN" "$LSWS_HOME/fcgi-bin/lsphp" >/dev/null 2>&1
chmod "$EXEC_MOD" "$LSWS_HOME/fcgi-bin/lsphp" >/dev/null 2>&1
chown "$CONF_OWN" "$LSWS_HOME/admin/conf/jcryption_keypair" >/dev/null 2>&1
chmod 0600 "$LSWS_HOME/admin/conf/jcryption_keypair" >/dev/null 2>&1
chown "$CONF_OWN" "$LSWS_HOME/admin/conf/htpasswd" >/dev/null 2>&1
chmod 0600 "$LSWS_HOME/admin/conf/htpasswd" >/dev/null 2>&1
chown "nobody:nobody" "$LSWS_HOME/tmp" >/dev/null 2>&1
chmod 0700 "$LSWS_HOME/tmp" >/dev/null 2>&1
chmod 0755 "$LSWS_HOME/autoupdate" >/dev/null 2>&1
chown "$LOGDIR_OWN" "$LSWS_HOME/logs" "$LSWS_HOME/admin/logs" >/dev/null 2>&1
chmod 0750 "$LSWS_HOME/logs" "$LSWS_HOME/admin/logs" >/dev/null 2>&1
#########this is the end of script to fix rpm build related file group and permission problem.
SSL_COUNTRY='US'
SSL_STATE="New Jersey"
SSL_LOCALITY='Virtual'
SSL_ORG='LiteSpeedCommunity'
SSL_ORGUNIT='Testing'
SSL_HOSTNAME='webadmin'
COMMNAME='openlitespeed.host'
SSL_COUNTRY=US
SSL_STATE="New Jersey"
csr="${SSL_HOSTNAME}.csr"
key="${SSL_HOSTNAME}.key"
cert="${SSL_HOSTNAME}.crt"
%define sslcert /usr/local/lsws/admin/conf/${cert}
%define sslkey /usr/local/lsws/admin/conf/${key}
cat << EOF > ${csr}
[req]
prompt=no
distinguished_name=openlitespeed
[openlitespeed]
commonName = ${COMMNAME}
countryName = ${SSL_COUNTRY}
localityName = Virtual
organizationName = LiteSpeedCommunity
organizationalUnitName = Testing
stateOrProvinceName = NJ
emailAddress = mail@${COMMNAME}
name = openlitespeed
initials = CP
dnQualifier = openlitespeed
[server_exts]
extendedKeyUsage=1.3.6.1.5.5.7.3.1
EOF
openssl req -x509 -config $csr -extensions 'server_exts' -nodes -days 820 -newkey rsa:2048 -keyout %{sslkey} -out %{sslcert}
chown lsadm.lsadm %{sslcert}; chmod 400 %{sslcert};
chown lsadm.lsadm %{sslkey}; chmod 400 %{sslkey};
/usr/local/lsws/admin/misc/rc-inst.sh > /dev/null 2>&1
%preun
if [ $1 = 0 ]; then
if [[ -e /etc/systemd/system ]] || [[ -e /usr/lib/systemd/system ]] || [[ -e /lib/systemd/system ]] ; then
systemctl stop lsws > /dev/null 2>&1
systemctl disable lsws > /dev/null 2>&1
else
service lsws stop > /dev/null 2>&1
chkconfig --del lsws > /dev/null 2>&1
fi
/usr/local/lsws/admin/misc/rc-uninst.sh > /dev/null 2>&1
fi
%posttrans
if [[ -e /etc/systemd/system ]] || [[ -e /usr/lib/systemd/system ]] || [[ -e /lib/systemd/system ]] ; then
systemctl status lsws > /dev/null 2>&1
if [[ $? = 3 ]] ; then
/usr/local/lsws/bin/lswsctrl stop > /dev/null 2>&1
fi
systemctl restart lsws > /dev/null 2>&1
else
service lsws restart >/dev/null 2>&1 || :
fi
%files
%defattr(-,root,root,-)
/etc/init.d/lsws
%dir /usr/local/lsws
/usr/local/lsws/*
%config(noreplace) /usr/local/lsws/conf/*
%config(noreplace) /usr/local/lsws/admin/conf/*
%config(noreplace) /usr/local/lsws/fcgi-bin/*
%config(noreplace) /usr/local/lsws/PLAT
%doc
%files -n openlitespeed-debug
%defattr(-,root,root,-)
%attr(-,root,root) /usr/local/lsws/bin/openlitespeed.dbg
%files -n openlitespeed-asan
%defattr(-,root,root,-)
%attr(-,root,root) /usr/local/lsws/bin/openlitespeed.asan
%files -n ols-pagespeed
%defattr(-,root,root,-)
%attr(-,root,root) /usr/local/lsws/modules/modpagespeed.so
%files -n ols-modsecurity
%defattr(-,root,root,-)
%attr(-,root,root) /usr/local/lsws/modules/mod_security.so
%changelog
Hope this is enough for creating your rpms.
@litespeedtech likewise can you please provide spec for lsphp?
Interested in building Fedora packages, but couldn't find a location, if any, for RPM specs of .src.rpm files...