Annotation of elwix/config/etc/rc.initial, revision 1.2.2.6

1.1       misho       1: #!/bin/sh
                      2: #
1.2       misho       3: # ELWIX Initial RC Menu script
1.1       misho       4: #
1.2.2.6 ! misho       5: # $Id: rc.initial,v 1.2.2.5 2013/01/24 12:59:22 misho Exp $
1.1       misho       6: #
                      7: 
                      8: trap : 2
                      9: trap : 3
                     10: trap : 18
1.2.2.6 ! misho      11: exec </dev/console >/dev/console 2>/dev/console
1.2.2.1   misho      12: MAGIC_MENU="menu"
1.1       misho      13: 
                     14: menu()
                     15: {
                     16:        echo
                     17:        echo
1.2       misho      18:        echo "ELWIX - console setup"
1.1       misho      19:        echo "*********************"
                     20:        echo "0) Logout"
                     21:        echo "1) Interfaces: assign network ports"
1.2.2.2   misho      22:        echo "2) Reset root password"
1.1       misho      23:        echo "3) Reset webGUI password"
                     24:        echo "4) Reset to factory defaults"
                     25:        echo "5) Reboot system"
                     26:        echo "6) Ping host"
                     27:        echo "7) SSH to host"
                     28:        echo "8) Go to shell"
1.2.2.6 ! misho      29:        echo "9) Clone system on other drive";
1.1       misho      30:        echo
                     31: 
                     32:        read -p "Enter number: " opcode
                     33: 
                     34:        case ${opcode} in
                     35:                0)
                     36:                        exit
                     37:                        ;;
                     38:                1)
1.2.2.2   misho      39:                        IFACES=$(ifconfig -l)
                     40:                        echo
                     41:                        echo "Available interfaces: $IFACES"
                     42:                        read -p " +Which from them: " iface
                     43:                        read -p " +Name of interface $iface []: " name
                     44:                        read -p " +Setup management vlan 4093 on $iface? [no|yes]: " mgmt
                     45:                        read -p " +IPv4 address/mask of interface $iface [dhcp|x.x.x.x/x]: " ip4
                     46:                        read -p " +IPv6 address/mask of interface $iface [auto|x:x:x::x/x]: " ip6
                     47:                        if [ X"$mgmt" = X"yes" -o X"$mgmt" = "y" ]; then
1.2.2.3   misho      48:                                cfexec sh -c "echo $iface >/etc/mylan"
1.2.2.2   misho      49:                        fi
                     50:                        ifconfig $iface description "$name" up
                     51:                        if [ -n "$ip4" ]; then
                     52:                                if [ X"$ip4" != X"dhcp" ]; then
                     53:                                        ifconfig $iface inet alias $ip4
                     54:                                else
                     55:                                        dhclient $iface
                     56:                                fi
                     57:                        fi
                     58:                        if [ -n "$ip6" ]; then
                     59:                                ifconfig $iface inet6 auto_linklocal -ifdisabled
                     60:                                if [ X"$ip6" != X"auto" ]; then
                     61:                                        ifconfig $iface inet6 -accept_rtadv
                     62:                                        ifconfig $iface inet6 alias $ip6
                     63:                                else
                     64:                                        ifconfig $iface inet6 accept_rtadv
                     65:                                fi
                     66:                        fi
1.1       misho      67:                        ;;
                     68:                2)
1.2.2.2   misho      69:                        passwd root
1.1       misho      70:                        ;;
                     71:                3)
1.2.2.5   misho      72:                        echo
                     73:                        read -p "New system webGUI password: " pass
                     74:                        read -p "Confirm system webGUI password: " confirm
                     75:                        if [ X"$pass" = X"$confirm" ]; then
                     76:                                cfexec xmler -s /elwix/system/password /elwix/etc/config.xml \
                     77:                                        $(md5 -qs "$pass")
                     78:                        else
                     79:                                echo "Error:: passwords are different ..."
                     80:                        fi
1.1       misho      81:                        ;;
                     82:                4)
1.2.2.3   misho      83:                        echo
                     84:                        echo "Restore factory defaults ..."
                     85:                        cfexec rm -rf /elwix/etc/rc.S /elwix/etc/rc.s /elwix/etc/rc.t
                     86:                        cfexec tar -xzpf /elwix/backup/.var.tgz -C /elwix/altroot
                     87:                        cfexec tar -xzpf /elwix/altroot/backup/.etc.tgz -C /elwix
1.1       misho      88:                        ;;
                     89:                5)
                     90:                        reboot
                     91:                        ;;
                     92:                6)
                     93:                        read -p " +Address: " host
                     94:                        read -p " +Number packets [4]: " cx
                     95:                        ping -n -c ${cx:-4} ${host:-localhost}
                     96:                        ;;
                     97:                7)
                     98:                        read -p " +Address: " host
                     99:                        read -p " +Port [22]: " port
                    100:                        read -p " +User [$USER]: " user
                    101:                        ssh -p ${port:-22} -l ${user:-$USER} ${host:-localhost}
                    102:                        ;;
                    103:                8)
                    104:                        $SHELL
                    105:                        ;;
                    106:                9)
1.2.2.3   misho     107:                        echo
                    108:                        camcontrol devlist
                    109:                        echo
                    110:                        read -p " +Select drive [like: ada1]: " dev
                    111:                        if [ -n "$dev" ]; then
                    112:                                if `disklabel $dev`; then
                    113:                                        read -p " +This is right choice? [no|yes]: " ask
                    114:                                        if [ X"$ask" = X"yes" -o X"$ask" = X"y" ]; then
1.2.2.4   misho     115:                                                sysctl -w kern.geom.debugflags=16
                    116:                                                dd if=/dev/ufs/elwix of=/dev/$dev
                    117:                                                sysctl -w kern.geom.debugflags=0
1.2.2.3   misho     118:                                        fi
                    119:                                fi
                    120:                        fi
1.1       misho     121:                        ;;
                    122:        esac
                    123: }
                    124: 
                    125: ### main()
                    126: 
                    127: while : ; do
                    128:        if [ -r /etc/disablemenu ]; then
                    129:                echo
                    130:                echo
                    131:                echo "*** Console menu disabled. ***"
                    132:                echo
                    133: 
                    134:                stty -echo
                    135:                read tmp
                    136:                stty echo
                    137:                if [ X"${tmp}" = X"${MAGIC_MENU}" ]; then
                    138:                        echo
                    139:                        echo "> OK, temporary unhide menu ..."
                    140:                        echo
                    141: 
                    142:                        menu
                    143:                fi
                    144:        else
                    145:                menu
                    146:        fi
                    147: done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>