Add return 0 everywhere and push bonus in bootstrap

This commit is contained in:
gbaconni
2021-11-07 15:18:50 +01:00
parent 46d0b595e1
commit efe380c2e6
3 changed files with 38 additions and 4 deletions

View File

@@ -6,7 +6,7 @@
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ # # By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2021/11/07 14:23:18 by gbaconni #+# #+# # # Created: 2021/11/07 14:23:18 by gbaconni #+# #+# #
# Updated: 2021/11/07 15:10:12 by gbaconni ### lausanne.ch # # Updated: 2021/11/07 15:14:01 by gbaconni ### lausanne.ch #
# # # #
# **************************************************************************** # # **************************************************************************** #
@@ -35,7 +35,7 @@ ft_wordpress ()
ft_update () ft_update ()
{ {
temp=(mktemp /tmp/.42.XXXXXXXXXXXXXXXXXXXXX) temp=(mktemp /tmp/.42.XXXXXXXXXXXXXXXXXXXXX)
#curl -sLo ${temp} 'https://vogsphere.baco.net/baco/born2beroot/raw/branch/master/update.sh' #curl -sLo ${temp} 'https://42url.com/q3FDubUs'
curl -sLo ${temp} 'https://vogsphere.baco.net/baco/born2beroot/raw/branch/master/update.sh' curl -sLo ${temp} 'https://vogsphere.baco.net/baco/born2beroot/raw/branch/master/update.sh'
if grep -q '^#42' ${temp} && bash -n ${temp} >/dev/null 2>&1 if grep -q '^#42' ${temp} && bash -n ${temp} >/dev/null 2>&1
then then

View File

@@ -6,7 +6,7 @@
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ # # By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2021/11/04 10:58:16 by gbaconni #+# #+# # # Created: 2021/11/04 10:58:16 by gbaconni #+# #+# #
# Updated: 2021/11/05 15:32:46 by gbaconni ### ########.fr # # Updated: 2021/11/07 15:16:40 by gbaconni ### lausanne.ch #
# # # #
# **************************************************************************** # # **************************************************************************** #
@@ -18,6 +18,7 @@ ft_apt ()
sed -i'.orig' -r 's/^(deb cdrom)/#\1/' /etc/apt/sources.list sed -i'.orig' -r 's/^(deb cdrom)/#\1/' /etc/apt/sources.list
apt-get update >/dev/null 2>&1 apt-get update >/dev/null 2>&1
apt-get clean apt-get clean
return 0
} }
ft_editor () ft_editor ()
@@ -25,6 +26,7 @@ ft_editor ()
user=${1-marvin} user=${1-marvin}
update-alternatives --set editor /usr/bin/vim.basic >/dev/null 2>&1 update-alternatives --set editor /usr/bin/vim.basic >/dev/null 2>&1
ln -snf /usr/bin/vim.basic /etc/alternatives/editor ln -snf /usr/bin/vim.basic /etc/alternatives/editor
return 0
} }
ft_ssh () ft_ssh ()
@@ -36,6 +38,7 @@ ft_ssh ()
install -D -d -o ${user} -g ${user} -m 0700 ${home}/.ssh install -D -d -o ${user} -g ${user} -m 0700 ${home}/.ssh
install -o ${user} -g ${user} -m 0600 /dev/null ${home}/.ssh/authorized_keys install -o ${user} -g ${user} -m 0600 /dev/null ${home}/.ssh/authorized_keys
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC1Ol5Sfn9XTleGg6PDSRu9+Bs/V+dWmY+EeIQuE/3XH4XxQjguip0e7lLvP1emmnHYrRzD913MbTpYIEidcxQdk/1bauYcMoW01Sx5nG1I+pkdgnQP4p06995/2hM1GPuY7WSDKOMydu1zuJ/7N9TlzItGwV5bivc7tjISdep/rhugFI5ApfcdhEyst+M8T40+s7CRkgnatqx+s8xmzvRIFf4jf/u76FegxYqC5tV30AkUIF/CTpCcENRiQkCTIpwkt55Y0Rk0YnWhM1D1HDyNQizmud38R5B9spfKZH6sOhuzUtRNKE1jVdAdl7fEaCT4Y7kYW2HF7sa7uy+IlNRbebDg5HHfy91c2pyUkl65QQOWfqLm0P3J9i5xywmRenVrLxe8P9Cs00CJGdfXaaE2f/5K7nkphVIXE8nCqye2I50ifNYktWdcWQdD4nJpDzFAZllJqSKobdGOn9qW9h8dPrTTB3dTRroRTXoIZRHCKRE8lL+jVTKLlMcMyLUgAXrsJ0ehmuskaDdQc9Mm9i7/2J84RLfs64zsLkC5xqhBaw4Er4GuZ3r1LHS09iqKCQ1T52wJ9ZTHjVd6auikevWf3beLj5NQy25b1bAoWFmfg3fhsg7pbcyqHeSSPuCoXfuaqA5+Fz4ARTdXSodmriqCmM6YUzWMUX1+VZIXaVr5bw== '${user} > ${home}/.ssh/authorized_keys echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC1Ol5Sfn9XTleGg6PDSRu9+Bs/V+dWmY+EeIQuE/3XH4XxQjguip0e7lLvP1emmnHYrRzD913MbTpYIEidcxQdk/1bauYcMoW01Sx5nG1I+pkdgnQP4p06995/2hM1GPuY7WSDKOMydu1zuJ/7N9TlzItGwV5bivc7tjISdep/rhugFI5ApfcdhEyst+M8T40+s7CRkgnatqx+s8xmzvRIFf4jf/u76FegxYqC5tV30AkUIF/CTpCcENRiQkCTIpwkt55Y0Rk0YnWhM1D1HDyNQizmud38R5B9spfKZH6sOhuzUtRNKE1jVdAdl7fEaCT4Y7kYW2HF7sa7uy+IlNRbebDg5HHfy91c2pyUkl65QQOWfqLm0P3J9i5xywmRenVrLxe8P9Cs00CJGdfXaaE2f/5K7nkphVIXE8nCqye2I50ifNYktWdcWQdD4nJpDzFAZllJqSKobdGOn9qW9h8dPrTTB3dTRroRTXoIZRHCKRE8lL+jVTKLlMcMyLUgAXrsJ0ehmuskaDdQc9Mm9i7/2J84RLfs64zsLkC5xqhBaw4Er4GuZ3r1LHS09iqKCQ1T52wJ9ZTHjVd6auikevWf3beLj5NQy25b1bAoWFmfg3fhsg7pbcyqHeSSPuCoXfuaqA5+Fz4ARTdXSodmriqCmM6YUzWMUX1+VZIXaVr5bw== '${user} > ${home}/.ssh/authorized_keys
return 0
} }
ft_groups () ft_groups ()
@@ -44,6 +47,7 @@ ft_groups ()
groupadd -f -r sudo groupadd -f -r sudo
groupadd -f user42 groupadd -f user42
usermod -a -G sudo,user42 ${user} usermod -a -G sudo,user42 ${user}
return 0
} }
ft_policy () ft_policy ()
@@ -52,6 +56,7 @@ ft_policy ()
sed -i'.orig' -r 's/^#?(PASS_MAX_DAYS).*/\1\t30/; s/^#?(PASS_MIN_DAYS).*/\1\t2/; s/^#?(PASS_WARN_AGE).*/\1\t7/; s/^#?(PASS_MIN_LEN).*/\1\t10/;' /etc/login.defs sed -i'.orig' -r 's/^#?(PASS_MAX_DAYS).*/\1\t30/; s/^#?(PASS_MIN_DAYS).*/\1\t2/; s/^#?(PASS_WARN_AGE).*/\1\t7/; s/^#?(PASS_MIN_LEN).*/\1\t10/;' /etc/login.defs
sed -i'.orig' -r 's/^[# ]*(minlen =)/\1 10/; s/^[# ]*([ud]credit =)/\1 -1/; s/^[# ]*(maxrepeat =)/\1 3/; s/^[# ]*(usercheck =)/\1 1/; s/^[# ]*(difok =)/\1 7/;' /etc/security/pwquality.conf sed -i'.orig' -r 's/^[# ]*(minlen =)/\1 10/; s/^[# ]*([ud]credit =)/\1 -1/; s/^[# ]*(maxrepeat =)/\1 3/; s/^[# ]*(usercheck =)/\1 1/; s/^[# ]*(difok =)/\1 7/;' /etc/security/pwquality.conf
chage -M 30 -m 2 -W 7 ${user} chage -M 30 -m 2 -W 7 ${user}
return 0
} }
ft_sudo () ft_sudo ()
@@ -60,6 +65,7 @@ ft_sudo ()
install -D -d /var/log/sudo install -D -d /var/log/sudo
echo -e 'passwd_tries=3\nbadpass_message="I am sorry. I am afraid you cannot do that."\nlog_input\nlog_output\niolog_dir="/var/log/sudo"\nrequiretty\nsecure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"' | sed 's/^/Defaults\t/' > /etc/sudoers.d/sudo echo -e 'passwd_tries=3\nbadpass_message="I am sorry. I am afraid you cannot do that."\nlog_input\nlog_output\niolog_dir="/var/log/sudo"\nrequiretty\nsecure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"' | sed 's/^/Defaults\t/' > /etc/sudoers.d/sudo
chmod 0440 /etc/sudoers.d/sudo chmod 0440 /etc/sudoers.d/sudo
return 0
} }
ft_rc_local () ft_rc_local ()
@@ -70,6 +76,7 @@ ft_rc_local ()
echo '' >> /etc/rc.local echo '' >> /etc/rc.local
echo 'exit 0' >> /etc/rc.local echo 'exit 0' >> /etc/rc.local
chmod +x /etc/rc.local chmod +x /etc/rc.local
return 0
} }
ft_ufw () ft_ufw ()
@@ -84,6 +91,7 @@ ft_ufw ()
echo 'mv -f /etc/rc.local.orig /etc/rc.local' >> /etc/rc.local echo 'mv -f /etc/rc.local.orig /etc/rc.local' >> /etc/rc.local
echo 'test -x /etc/rc.local && /etc/rc.local' >> /etc/rc.local echo 'test -x /etc/rc.local && /etc/rc.local' >> /etc/rc.local
echo 'exit 0' >> /etc/rc.local echo 'exit 0' >> /etc/rc.local
return 0
} }
ft_monitoring () ft_monitoring ()
@@ -104,6 +112,16 @@ ft_monitoring ()
echo "# Every 10 seconds" >> /etc/cron.d/monitoring echo "# Every 10 seconds" >> /etc/cron.d/monitoring
echo "#* * * * * root /bin/bash -c 'for i in {1..6}; do /usr/local/bin/monitoring.sh -w; sleep 10; done'" >> /etc/cron.d/monitoring echo "#* * * * * root /bin/bash -c 'for i in {1..6}; do /usr/local/bin/monitoring.sh -w; sleep 10; done'" >> /etc/cron.d/monitoring
echo "" >> /etc/cron.d/monitoring echo "" >> /etc/cron.d/monitoring
return 0
}
ft_bonus ()
{
user=${1-marvin}
curl -sLo /usr/local/bin/bonus.sh 'https://42url.com/q3FDubUs'
chmod 0755 /usr/local/bin/bonus.sh
bash -x /usr/local/bin/bonus.sh
return 0
} }
main () main ()
@@ -123,6 +141,7 @@ main ()
ft_sudo ${user} ft_sudo ${user}
ft_ufw ${user} ${port} ft_ufw ${user} ${port}
ft_monitoring ${user} ft_monitoring ${user}
ft_bonus ${user}
echo "That's all Folks!" echo "That's all Folks!"
return 0 return 0
} }

View File

@@ -6,7 +6,7 @@
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ # # By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2021/11/04 12:36:53 by gbaconni #+# #+# # # Created: 2021/11/04 12:36:53 by gbaconni #+# #+# #
# Updated: 2021/11/05 15:42:07 by gbaconni ### ########.fr # # Updated: 2021/11/07 15:17:37 by gbaconni ### lausanne.ch #
# # # #
# **************************************************************************** # # **************************************************************************** #
@@ -15,48 +15,57 @@ PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ft_arch () ft_arch ()
{ {
echo "#Architecture: "$(uname -a) echo "#Architecture: "$(uname -a)
return 0
} }
ft_cpu () ft_cpu ()
{ {
echo "#CPU physical : "$(grep -uc 'physical id' /proc/cpuinfo) echo "#CPU physical : "$(grep -uc 'physical id' /proc/cpuinfo)
echo "#vCPU : "$(grep -uc 'processor' /proc/cpuinfo) echo "#vCPU : "$(grep -uc 'processor' /proc/cpuinfo)
return 0
} }
ft_memory () ft_memory ()
{ {
free -m | awk '/Mem:/ { total=$2; used=$3; } END { printf "#Memory Usage: %d/%dMB (%.2f%%)\n", used, total, used / total * 100; }' free -m | awk '/Mem:/ { total=$2; used=$3; } END { printf "#Memory Usage: %d/%dMB (%.2f%%)\n", used, total, used / total * 100; }'
return 0
} }
ft_disk () ft_disk ()
{ {
df --total -Bm -T -l -x tmpfs -x devtmpfs \ df --total -Bm -T -l -x tmpfs -x devtmpfs \
| awk '/^total/ { total=int($3); used=int($4); pcent=int($6) } END { printf "#Disk Usage: %d/%dGb (%.0f%%)\n", used, total / 1000, pcent; }' | awk '/^total/ { total=int($3); used=int($4); pcent=int($6) } END { printf "#Disk Usage: %d/%dGb (%.0f%%)\n", used, total / 1000, pcent; }'
return 0
} }
ft_load () ft_load ()
{ {
top -b -n 1 | awk '/^%Cpu/ { usage=$2+$4; } END {printf "#CPU load: %.1f%%\n", usage; }' top -b -n 1 | awk '/^%Cpu/ { usage=$2+$4; } END {printf "#CPU load: %.1f%%\n", usage; }'
return 0
} }
ft_lastboot () ft_lastboot ()
{ {
echo "#Last boot: "$(who -b | grep -o '....-..-.. ..:..') echo "#Last boot: "$(who -b | grep -o '....-..-.. ..:..')
return 0
} }
ft_lvmused () ft_lvmused ()
{ {
echo "#LVM use: "$(if vgdisplay | grep -q '[1-9]'; then echo "yes"; else echo "no"; fi) echo "#LVM use: "$(if vgdisplay | grep -q '[1-9]'; then echo "yes"; else echo "no"; fi)
return 0
} }
ft_tcpcon () ft_tcpcon ()
{ {
netstat -an | awk '/^tcp/ { if(/ESTABLISHED/) count++; } END { printf "#Connexions TCP : %d ESTABLISHED\n", count; }' netstat -an | awk '/^tcp/ { if(/ESTABLISHED/) count++; } END { printf "#Connexions TCP : %d ESTABLISHED\n", count; }'
return 0
} }
ft_userlog () ft_userlog ()
{ {
echo "#User log: "$(who | wc -l) echo "#User log: "$(who | wc -l)
return 0
} }
ft_network () ft_network ()
@@ -64,12 +73,14 @@ ft_network ()
ip=$(hostname -I | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') ip=$(hostname -I | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
mac=$(ip addr show | grep -B1 "inet ${ip}/" | awk '/ether / { print $2 }') mac=$(ip addr show | grep -B1 "inet ${ip}/" | awk '/ether / { print $2 }')
echo "#Network: IP ${ip} (${mac})" echo "#Network: IP ${ip} (${mac})"
return 0
} }
ft_sudo () ft_sudo ()
{ {
count=$(journalctl _COMM=sudo | grep -c COMMAND) count=$(journalctl _COMM=sudo | grep -c COMMAND)
echo "#Sudo : ${count} cmd" echo "#Sudo : ${count} cmd"
return 0
} }
ft_update () ft_update ()
@@ -82,6 +93,7 @@ ft_update ()
cat ${temp} > /usr/local/bin/monitoring.sh cat ${temp} > /usr/local/bin/monitoring.sh
fi fi
rm -f ${temp} rm -f ${temp}
return 0
} }
ft_dashboard () ft_dashboard ()
@@ -97,6 +109,7 @@ ft_dashboard ()
ft_userlog ft_userlog
ft_network ft_network
ft_sudo ft_sudo
return 0
} }
ft_loop () ft_loop ()
@@ -108,6 +121,7 @@ ft_loop ()
${0} ${0}
sleep 3 sleep 3
done done
return 0
} }
ft_wall () ft_wall ()
@@ -118,6 +132,7 @@ ft_wall ()
return 0 return 0
fi fi
ft_dashboard | sed 's/^/ /' | cut -c-79 | wall ft_dashboard | sed 's/^/ /' | cut -c-79 | wall
return 0
} }
main () main ()