From 599627407583832f1d6f8df4123ddc1506a39c4f Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 24 Sep 2020 15:11:50 +0200 Subject: [PATCH] [fix] .bashrc disappeared... --- files/root/.bashrc | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 files/root/.bashrc diff --git a/files/root/.bashrc b/files/root/.bashrc new file mode 100644 index 0000000..e05a090 --- /dev/null +++ b/files/root/.bashrc @@ -0,0 +1,88 @@ +cd /opt/LJ +echo -e "\n\e[1;31m" +cat << HEREDOC + \ \ / | | | | + \ \ \ / _ \ | __| _ \ __ \__ \ _ \ __| _ \ | | + \ \ \ / __/ | ( ( | | | | __/ | ( | | \ | + \_/\_/ \___| _| \___| \___/ _| _| _| \___| \__| \___/ _____| \___/ +HEREDOC +echo -e "\e[0m\n" + +# Check the ip address on the machine +checkNetwork(){ + + + echo -e "\Checking network connectivity..." + ping=$( ping 1.1.1.1 -c 1 -W 2 &>/dev/null; echo $?;) + + # Net is working, escape + if [[ 0 -eq $ping ]] ; then + echo -e "\n OK, Use this IP Address for GUEST_IP : $( ip address show | grep global | awk '{print $2}'|sed -e 's=/.*==' ) \n" + return + fi + + echo -e "\nSeems you can't reach internet..." + + # Get the ethernet interface + # 772 is the loopback device, cf. http://lxr.linux.no/linux+v3.0/include/linux/if_arp.h#L67 + for f in /sys/class/net/* ; do + [[ 772 != $(cat "$f/type" ) ]] && interface=$(basename $f) + done + + if [[ -z "$interface" ]] ; then + echo -e "\e[31mFatal Error : no network interface configured."; + # Eventually, use nm-tui for a graphical (ncurses install) + read -e -p "(Experts only) Do you want to set up network via network-manager UI? [yN]: " + [[ "${REPLY^^}" == "Y" ]] && { nmtui; return; } + + else + echo "OK, network interface '$interface' found" + fi + + # Ensure the interface is up + ip l set $interface up + + ipList=$( ip address show | grep global ) + ipRoute=$( ip route show | grep default ) + + [[ -z "$ipList" ]] && { + echo -e "\nNo IP address configured. Please set one." + read -e -i '192.168.1.90/24' -p "Which address and range do you want to use (or 'x' to skip)? " ipAddr + [[ 'x' != "$ipAddr" ]] && { + ip address add $ipAddr dev $interface + } + } + [[ -z "$ipRoute" ]] && { + echo -e "\nNo IP route configured. Please set one." + read -e -i '192.168.1.1' -p "Which routing address do you want to use (or 'x' to skip)? " ipAddr + [[ 'x' != "$ipAddr" ]] && { + ip route add default via $ipAddr dev $interface + } + } + + +} +checkNetwork +[[ ! -f /tmp/.first_run ]] && { + touch /tmp/.first_run ; + echo -e "\e[1mCaution! configuring the server and lasers network is mandatory for the app to work." + echo -e "Type the "c" key immediately to start the configuration." + echo -e "\e[0m" + echo -e "Everytime you will login, the configure and documentation options will be offered to you." + echo -e "Or use the commands 'config' or 'usage' any time to access the same functions." + echo -e "\e[0m" +} +config(){ cd /opt/LJ ; /usr/bin/python3 configure.py; } +usage(){ cat /opt/LJ/README.md; } + +echo -e "\e[1m" +read -e -n 1 -p "Do you want to (c)onfigure the app, (r)ead documentation, or (n)othing: " +echo -e "\e[0m" +case $REPLY in + (c): + config + ;; + (r): + usage + ;; +esac