Files
born2beroot/bonus.sh

161 lines
4.5 KiB
Bash
Raw Normal View History

2021-11-07 15:10:48 +01:00
# **************************************************************************** #
# #
# ::: :::::::: #
# bonus.sh :+: :+: :+: #
# +:+ +:+ +:+ #
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/11/07 14:23:18 by gbaconni #+# #+# #
2021-11-09 08:27:25 +01:00
# Updated: 2021/11/09 08:26:49 by gbaconni ### lausanne.ch #
2021-11-07 15:10:48 +01:00
# #
# **************************************************************************** #
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ft_mariadb ()
{
2021-11-07 18:43:45 +01:00
if ! dpkg --get-selections | grep -qP '^mariadb-server\t+install'
2021-11-07 16:30:54 +01:00
then
apt-get install -qq -y mariadb-server
2021-11-07 17:46:32 +01:00
yes y | mysql_secure_installation
2021-11-07 16:30:54 +01:00
fi
2021-11-07 15:10:48 +01:00
return 0
}
2021-11-09 06:53:06 +01:00
ft_ssl ()
2021-11-07 15:10:48 +01:00
{
2021-11-09 06:53:06 +01:00
if ! dpkg --get-selections | grep -qP '^ssl-cert\t+install'
2021-11-07 16:50:37 +01:00
then
2021-11-09 06:53:06 +01:00
apt-get install -qq -y ssl-cert
2021-11-08 06:54:01 +01:00
sed -i 's/@HostName@/localhost/' /usr/share/ssl-cert/ssleay.cnf
2021-11-07 22:32:55 +01:00
make-ssl-cert generate-default-snakeoil --force-overwrite
2021-11-08 06:30:46 +01:00
#openssl req -x509 \
# -out /etc/ssl/certs/ssl-cert-snakeoil.pem \
# -keyout /etc/ssl/private/ssl-cert-snakeoil.key \
# -newkey rsa:2048 -nodes -sha256 \
# -subj '/CN=localhost' -extensions EXT -config <( \
# printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
2021-11-09 06:53:06 +01:00
fi
return 0
}
ft_lighttpd ()
{
ft_ssl
if ! dpkg --get-selections | grep -qP '^lighttpd\t+install'
then
apt-get install -qq -y lighttpd
2021-11-09 08:27:25 +01:00
sed -i -r 's|^(server.document-root[^=]*=).*\1 "/usr/share/wordpress"|g' /etc/lighttpd/lighttpd.conf
sed -i -r 's/80/4243/g' /etc/lighttpd/lighttpd.conf
sed -i -r 's/443/4244/g' /etc/lighttpd/conf-available/10-ssl.conf
cat \
/etc/ssl/certs/ssl-cert-snakeoil.pem \
/etc/ssl/private/ssl-cert-snakeoil.key \
> /etc/lighttpd/server.pem
2021-11-09 07:42:21 +01:00
lighttpd-enable-mod fastcgi
2021-11-09 08:27:25 +01:00
lighttpd-enable-mod fastcgi-php
lighttpd-enable-mod rewrite
lighttpd-enable-mod ssl
2021-11-09 07:42:21 +01:00
systemctl force-reload lighttpd
2021-11-09 06:53:06 +01:00
fi
return 0
}
2021-11-07 15:10:48 +01:00
ft_php ()
{
2021-11-09 07:42:21 +01:00
if ! dpkg --get-selections | grep -qP '^php-fpm\t+install'
2021-11-07 16:58:10 +01:00
then
2021-11-09 07:42:21 +01:00
apt-get install -qq -y php php-fpm php-mysql
2021-11-09 08:27:25 +01:00
sed -i -r 's/^;?(cgi.fix_pathinfo)=.*/\1=1/' /etc/php/7.4/fpm/php.ini
sed -i -r 's|(listen =).*|\1 /run/php/php-fpm.sock|' /etc/php/7.4/fpm/pool.d/www.conf
2021-11-09 07:42:21 +01:00
systemctl restart php7.3-fpm
2021-11-07 16:58:10 +01:00
fi
2021-11-07 15:10:48 +01:00
return 0
}
ft_wordpress ()
{
2021-11-08 22:19:13 +01:00
password=${1-Born2beWild}
2021-11-08 06:33:11 +01:00
if ! dpkg --get-selections | grep -qP '^wordpress\t+install'
2021-11-07 17:46:32 +01:00
then
2021-11-07 20:00:18 +01:00
apt-get install -qq -y wordpress links
2021-11-07 17:46:32 +01:00
fi
if ! test -L /var/www/html
then
ln -snf /usr/share/wordpress /var/www/html
chown -R www-data:www-data /usr/share/wordpress
fi
if ! test -d /var/lib/mysql/wordpress
2021-11-07 17:49:37 +01:00
then
2021-11-07 18:05:27 +01:00
rm -f /etc/wordpress/config-localhost.php
2021-11-08 06:30:46 +01:00
sed -i -r "s/(read.*)(yn|DB_PASSWORD)/\2=y/g; s/ -u .DB_USER -p / -u root /g;" /usr/share/doc/wordpress/examples/setup-mysql
2021-11-07 18:33:33 +01:00
bash -x /usr/share/doc/wordpress/examples/setup-mysql -n wordpress localhost
2021-11-08 06:30:46 +01:00
mysql -u root -h localhost -e "ALTER USER root@localhost IDENTIFIED BY '${password}'; FLUSH PRIVILEGES;" mysql
2021-11-07 20:00:18 +01:00
ln -snf /etc/wordpress/config-localhost.php /etc/wordpress/config-default.php
2021-11-07 17:46:32 +01:00
fi
2021-11-07 15:10:48 +01:00
return 0
}
2021-11-07 16:30:54 +01:00
ft_ufw ()
{
2021-11-08 06:35:59 +01:00
if test -f /etc/rc.local.orig && ! grep -q 'port 4243' /etc/rc.local
2021-11-07 16:30:54 +01:00
then
2021-11-08 06:35:59 +01:00
sed -i -r 's|(/usr/sbin/ufw allow proto tcp from any to any port)(.+)|\1\2\n\1 4243\n\1 4244|' /etc/rc.local
2021-11-07 16:47:55 +01:00
return 0
fi
2021-11-08 06:35:59 +01:00
if ! ufw status | grep -q '^4243/tcp'
2021-11-07 16:47:55 +01:00
then
2021-11-08 06:35:59 +01:00
ufw allow proto tcp from any to any port 4243
2021-11-07 16:47:55 +01:00
fi
2021-11-08 06:35:59 +01:00
if ! ufw status | grep -q '^4244/tcp'
2021-11-07 16:47:55 +01:00
then
2021-11-08 06:35:59 +01:00
ufw allow proto tcp from any to any port 4244
2021-11-07 16:30:54 +01:00
fi
return 0
}
2021-11-07 15:10:48 +01:00
ft_update ()
{
2021-11-07 16:33:39 +01:00
temp=$(mktemp /tmp/.42.XXXXXXXXXXXXXXXXXXXXX)
#curl -sLo ${temp} 'https://42url.com/q3FDubUs'
2021-11-07 16:38:50 +01:00
curl -sLo ${temp} 'https://vogsphere.baco.net/baco/born2beroot/raw/branch/master/bonus.sh'
2021-11-07 15:10:48 +01:00
if grep -q '^#42' ${temp} && bash -n ${temp} >/dev/null 2>&1
then
cat ${temp} > /usr/local/bin/bonus.sh
fi
rm -f ${temp}
return 0
}
ft_install ()
{
2021-11-08 22:19:13 +01:00
password=${1-Born2beWild}
2021-11-07 18:33:33 +01:00
ft_mariadb ${password}
2021-11-09 06:53:06 +01:00
ft_lighttpd
2021-11-07 15:10:48 +01:00
ft_php
2021-11-07 18:33:33 +01:00
ft_wordpress ${password}
2021-11-07 16:30:54 +01:00
ft_ufw
2021-11-07 15:10:48 +01:00
return 0
}
main ()
{
case "${1}" in
-u)
ft_update
2021-11-07 17:06:54 +01:00
(sleep 3; bash -x $0) &
2021-11-07 16:56:07 +01:00
return 0
2021-11-07 15:10:48 +01:00
;;
*)
2021-11-08 22:19:13 +01:00
password=${1-Born2beWild}
2021-11-07 18:33:33 +01:00
ft_install ${password}
2021-11-07 15:10:48 +01:00
;;
esac
return 0
}
main $@
exit $?
#42