# **************************************************************************** # # # # ::: :::::::: # # bonus.sh :+: :+: :+: # # +:+ +:+ +:+ # # By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/11/07 14:23:18 by gbaconni #+# #+# # # Updated: 2021/11/07 18:07:59 by gbaconni ### lausanne.ch # # # # **************************************************************************** # PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ft_mariadb () { if ! dpkg --get-selections | grep -q '^mariadb-server' then apt-get install -qq -y mariadb-server yes y | mysql_secure_installation fi return 0 } ft_apache () { if ! dpkg --get-selections | grep -q '^apache2' then apt-get install -qq -y ssl-cert apache2 fi return 0 } ft_php () { if ! dpkg --get-selections | grep -q '^libapache2-mod-php' then apt-get install -qq -y libapache2-mod-php fi return 0 } ft_wordpress () { if ! dpkg --get-selections | grep -q '^wordpress' then apt-get install -qq -y wordpress 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 then rm -f /etc/wordpress/config-localhost.php sed -i -r 's/(read.*)(DB_PASSWORD|yn)/\2=y/g; s/( -p )/ /g;' /usr/share/doc/wordpress/examples/setup-mysql bash -x /usr/share/doc/wordpress/examples/setup-mysql -n wordpress -u root -h localhost localhost fi return 0 } ft_ufw () { if test -f /etc/rc.local.orig && ! grep -q 'port 443' /etc/rc.local then sed -i -r 's|(/usr/sbin/ufw allow proto tcp from any to any port)(.+)|\1\2\n\1 80\n\1 443|' /etc/rc.local return 0 fi if ! ufw status | grep -q '^80/tcp' then ufw allow proto tcp from any to any port 80 fi if ! ufw status | grep -q '^443/tcp' then ufw allow proto tcp from any to any port 443 fi return 0 } ft_update () { temp=$(mktemp /tmp/.42.XXXXXXXXXXXXXXXXXXXXX) #curl -sLo ${temp} 'https://42url.com/q3FDubUs' curl -sLo ${temp} 'https://vogsphere.baco.net/baco/born2beroot/raw/branch/master/bonus.sh' 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 () { ft_mariadb ft_apache ft_php ft_wordpress ft_ufw return 0 } main () { case "${1}" in -u) ft_update (sleep 3; bash -x $0) & return 0 ;; *) ft_install ;; esac return 0 } main $@ exit $? #42