File:  [ELWIX - Embedded LightWeight unIX -] / elwix / config / etc / default / rc.initial
Revision 1.7: download - view: text, annotated - select for diffs - revision graph
Thu Mar 11 13:59:50 2021 UTC (3 years, 9 months ago) by misho
Branches: MAIN
CVS tags: elwix2_8, elwix2_7, HEAD, ELWIX2_7, ELWIX2_6
ver 2.6

#!/bin/sh
#
# ELWIX Initial RC Menu script
#
# $Id: rc.initial,v 1.7 2021/03/11 13:59:50 misho Exp $
#

trap : 2
trap : 3
trap : 18
#exec </dev/console >/dev/console 2>/dev/console
MAGIC_MENU="menu"

menu()
{
	echo
	echo
	echo "ELWIX - console setup"
	echo "*********************"
	echo "0) Logout"
	echo "1) Interfaces: assign network ports"
	echo "2) Reset root password"
	echo "3) Reset webGUI password"
	echo "4) Reset to factory defaults"
	echo "5) Reboot system"
	echo "6) Ping host"
	echo "7) SSH to host"
	echo "8) Go to shell"
	echo "9) Clone system on other drive";
	echo

	read -p "Enter number: " opcode

	case ${opcode} in
		0)
			exit
			;;
		1)
			IFACES=$(ifconfig -l)
			echo
			echo "Available interfaces: $IFACES"
			read -p " +Which from them: " iface
			if [ -z "$iface" ]; then
				return 1
			fi
			read -p " +Name of interface $iface []: " name
			read -p " +Setup management vlan 4093 on $iface? [no|yes]: " mgmt
			read -p " +IPv4 address/mask of interface $iface [dhcp|x.x.x.x/x]: " ip4
			read -p " +IPv6 address/mask of interface $iface [auto|x:x:x::x/x]: " ip6
			if [ X"$mgmt" = X"yes" -o X"$mgmt" = X"y" ]; then
				cfexec sh -c "echo $iface >/etc/mylan"
			fi
			ifconfig $iface description "$name" up
			if [ -n "$ip4" ]; then
				if [ X"$ip4" != X"dhcp" ]; then
					ifconfig $iface inet alias $ip4
				else
					dhclient $iface
				fi
			fi
			if [ -n "$ip6" ]; then
				ifconfig $iface inet6 auto_linklocal -ifdisabled
				if [ X"$ip6" != X"auto" ]; then
					ifconfig $iface inet6 -accept_rtadv
					ifconfig $iface inet6 alias $ip6
				else
					ifconfig $iface inet6 accept_rtadv
				fi
			fi
			;;
		2)
			passwd root
			;;
		3)
			echo
			read -p "New system webGUI password: " pass
			read -p "Confirm system webGUI password: " confirm
			if [ X"$pass" = X"$confirm" ]; then
				cfexec xmler -s /elwix/system/password /elwix/etc/config.xml \
					$(md5 -qs "$pass")
			else
				echo "Error:: passwords are different ..."
			fi
			;;
		4)
			echo
			echo "Restore factory defaults ..."
			read -p " +Are you sure for restore and clear all changes? [no|yes]: " ans
			if [ X"$ans" = X"yes" -o X"$ans" = X"y" ]; then
				cfexec -L "Locked by rc.initial for restore factory defaults"
				tar -xzpf /elwix/altroot/backup/.var.tgz -C /elwix/altroot
				tar -xzpf /elwix/altroot/backup/.etc.tgz -C /elwix
				cfexec -U
			fi
			;;
		5)
			reboot
			;;
		6)
			read -p " +Address: " host
			read -p " +Number packets [4]: " cx
			ping -n -c ${cx:-4} ${host:-localhost}
			;;
		7)
			read -p " +Address: " host
			read -p " +Port [22]: " port
			read -p " +User [$USER]: " user
			ssh -p ${port:-22} -l ${user:-$USER} ${host:-localhost}
			;;
		8)
			exec $SHELL
			;;
		9)
			echo
			camcontrol devlist
			echo
			read -p " +Select copy from drive [like: ada0]: " src
			read -p " +Select copy to drive [like: ada1]: " dst
			if [ -n "$src" -a -n "$dst" ]; then
				if [ -x /usr/sbin/diskinfo ]; then
					diskinfo $dst
					if [ $? -eq 0 ]; then
						read -p " +This is right choice? [no|yes]: " ask
						if [ X"$ask" = X"yes" -o X"$ask" = X"y" ]; then
							dd if=/dev/$src of=/dev/$dst
						fi
					fi
				fi
			fi
			;;
	esac
}

### main()

while : ; do
	if [ -r /etc/disablemenu ]; then
		echo
		echo
		echo "*** Console menu disabled. ***"
		echo

		stty -echo
		read tmp
		stty echo
		if [ X"${tmp}" = X"${MAGIC_MENU}" ]; then
			echo
			echo "> OK, temporary unhide menu ..."
			echo

			menu
		fi
	else
		menu
	fi
done

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