All pastes #1263427 Raw Edit

WizzyConf.sh

public shellscript v1 · immutable
#1263427 ·published 2008-11-21 12:25 UTC
rendered paste body
#!/bin/msh# wizzyconf.sh - DSLinux configuration wizard - part of the wizzy-suite# Licence: GNU GPL v3 or later at your option# Author:  Florian Bruhin (The Compiler) <florianbruh@gmail.com># Version: 0.01r081121# Copyright 2008, 2009 Florian Bruhin# This program is part of the Wizzy-suite## The Wizzy-suite is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## The Wizzy-suite is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with the Wizzy-suite.  If not, see <http://www.gnu.org/licenses/>.# FIXME: Add copyright-box (and donation, postcard) [almost done, do some cleaning]# FIXME TODO: re-add adduser [needs heavy testing and bugfixing]# FIXME TODO: Check $? etc. for errors#=============================================================##=============================================================#NEWLINE=""OLDIFS="$IFS"dialog --infobox "Please wait...${NEWLINE}Bitte warten..." 0 0 # FIXME add other languages if there're moreif [ ! -e "/etc/lang" ]; then	dialog --stdout --backtitle "WizzyConf" --title "Warning" --ok-label "Damn!" --msgbox "No language-file found, falling back to English." 0 0	echo "lang=\"en\"" > /etc/lang	lang="de"else	lang=`cat /etc/lang`fiif [ ! -e "/usr/share/wizzy/langs/$lang/lang" ]; then	dialog --stdout --backtitle "WizzyConf" --title "Warning" --ok-label "Damn!" --msgbox "Language-file /usr/share/wizzy/langs/$lang/lang not found, something went terribly wrong. Aborting." 0 0	exit 1else	. "/usr/share/wizzy/langs/$lang/lang"fia=`/bin/false`if [ $? != 1 ]then	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --ok-label "$t_damn" --msgbox "$t_unpatched" 0 0	exit 1fiif [ ! -e "/etc/rc.conf" ]then	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --no-label "$t_no" --yes-label "$t_yes" --yesno "$t_rcconf_does_not_exist" 0 0	if [ "$?" = "1" ]	then		dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --ok-label "$ok" --msgbox "$t_cancelling"		exit 1	else		cp /etc/rc.defaults /etc/rc.conf	fififunc=startwhile :do#echo $func # FIXME comment out testing only#sleep 1 # FIXME comment out testing onlycase $func in#==============================================================#start)#==============================================================#	dlginput=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_mainmenu" --ok-label "$t_ok" --cancel-label "$t_exit" --help-label "$help" --menu "$t_what_do_you_want_to_configure" 0 0 0 \	"1)" "$t_users" \	"2)" "$t_network" \	"3)" "$t_misc" \	"" "" \	"" "$t_about_wizzy"`	case $? in		1|255)			clear			exit			;;	esac	case $dlginput in		1\)) func=users ;;		2\)) func=network ;;		3\)) func=misc ;;		"") func=about ;;	esac	;;#==============================================================#users)#==============================================================#	dlginput=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$help" --title "$t_users" --menu "" 0 0 0 \	"1)" "$t_add_user" \	"2)" "$t_del_user" \	"3)" "$t_edit_user" \	"4)" "$t_list_users" \	"5)" "$t_autologin" \	--infobox "$t_please_wait" 0 0`	case $? in		1|255) func=start ;;	esac	case $dlginput in		1\)) func="adduser" ;;		2\)) func="deluser" ;;		3\)) func="edituser" ;;		4\)) func="lsusers" ;;		5\)) func="autologin" ;;	esac	dlginput=	;;#===========================#edituser)#===========================#	dialog --yesno "This feature is still in development. Enter anyway?" 0 0 # FIXME comment out development only	case $? in # FIXME comment out development only	1|255) func=users ;; # FIXME comment out development only	*) # FIXME comment out development only		if [ "$list_done" != "1" ]		then			nouser="0"			prev_list="edituser"			autologin_title="$t_edit_user"			func="listusers"		else			IFS=":"			line=`cat /etc/passwd | grep "^$c_user"`			set -- $line			IFS="$OLDIFS"						auto=`cat /etc/autologin.conf | grep "AUTOLOGIN.*$"`			if [ "$auto" = "yes" ]; then				dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_edit_user" --no-label "$t_no" --yes-label "$t_yes" --yesno "$t_autologin_changed" 0 0				if [ $? != 1 ]; then					if [ $? != 255 ]; then						mv /etc/autologin.conf /etc/autologin.conf.bak						sed "s/USER.*$/USER='$user'/" /etc/autologin.conf.bak > /etc/autologin.conf					fi				fi				hadouto=				fi									# Example: root:xxSVJVBe8UDn2:0:0:Tim Bisley:/home:/bin/sh			dlginput_user=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_add_user_text" --inputbox "$t_username" 0 0 "$1"`			dlginput_uid=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_add_user" --inputbox "UID$NEWLINE$t_dont_change_this" 0 0 "$3"`			if  [ "$uid" -lt 1000 ]; then				dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_edit_user" --ok-label "$ok" --msgbox "$t_uid_is_less_than_1000" 0 0				skip="1"			fi						if [ "$skip" != "1" ]; then				dlginput_gid=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_add_user" --inputbox "GID$NEWLINE$t_dont_change_this" 0 0 "$4"`				dlginput_realname=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_add_user" --inputbox "$t_realname" 0 0`				dlginput_home=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_add_user" --inputbox "$t_home$NEWLINE$t_dont_change_this" 0 0 "$6"`				dlginput_shell=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_add_user" --inputbox "$t_shell$NEWLINE$t_dont_change_this" 0 0 "$7"`				user_tmp=`echo "$dlginput_user" | sed "s/[:\\\\\"#,=\/?\']//g"`				user=`echo "$user_tmp" | sed 's/^[+@~ -]//g'`				user_tmp=`echo "$user" | sed 's/ALL//g'`				user=`echo "$user_tmp" | sed 's/default//g'`				user_tmp=								echo "DEBUG: $dlginput_user ist $user" # FIXME testing only				sleep 5 # FIXME testing only				# TODO: check if new home exists and ask for creating [done as of 302208, testing!!!]				# FIXME: TEST Test if updating of /etc/group acts correctly [is it even necessary?]				# FIXME: nothing changes... [maybe fixed as of 081116?]				# FIXME sed has an error, realname is empty, ... [maybe fixed as of 081116?]				# FIXME: Ask if it should adjust autologin [should be done as of 081120, needs testing]				# FIXME cancel doesn't work				# TODO: comment what sed does				echo "$dlginput_user:$2:$dlginput_uid:$dlginput_gid:$dlginput_realname:$dlginput_home:$dlginput_shell" >> /etc/passwd				# FIXME is that needed? Does DSLinux have an /etc/group?				#if [ "$c_user" != "$dlginput_user" ] # If user has changed, update /etc/group				#then				#	mv /etc/group /etc/group.bak				#	groups=`cat /etc/group.bak | grep "$c_user"`				#	IFS=":"				#	set -- $c_user				#	tmp=`echo $4 | grep ","`				#	if [ "$tmp" = "" ]				#	then				#		sed s/"$4"/"$4,$dlginput_user"/ /etc/group.bak > /etc/group				#			else				#		sed s/"$4"/"$dlginput_user"/ /etc/group.bak > /etc/group				#	fi				#fi				dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_edit_user" --no-label "$t_no" --yes-label "$t_yes" --yesno "$t_do_you_want_to_set_a_new_password" 0 0 && passwd "$dlginput_user"			fi			dlginput_user=			dlginput_uid=			dlginput_gid=			dlginput_realname=			dlginput_home=			dlginput_shell=			dlginput=			func="users"			prev_list=			c_user=			cmd=			list_done=0			autologin_title=			skip=		fi	esac # FIXME comment out development only  ;;#===========================#adduser)#===========================#	dialog --yesno "This feature is still in development. Enter anyway?" 0 0 # FIXME comment out development only	case $? in # FIXME comment out development only	1|255) func=users ;; # FIXME comment out development only	*) # FIXME comment out development only		# Example: root:xxSVJVBe8UDn2:0:0:Tim Bisley:/home:/bin/sh		lastuser=`echo /etc/passwd | sed -n -e '1 p'`	# that looks		IFS=":"						# rather strange		set -- $lastuser				# does that		IFS="$OLDIFS"					# work? FIXME				if [ "$3" -ge 1000 ]		then			uid=`expr "$3" + 1`		else			uid=1000		fi		dlginput_user=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_add_user" --inputbox "$t_username_text" 0 0` && \		dlginput_realname=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_add_user" --inputbox "$t_realname" 0 0` && \		dlginput_uid=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_add_user" --inputbox "UID$NEWLINE$t_dont_change_this" 0 0 "$uid"` && \		dlginput_home=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_add_user" --inputbox "$t_home$NEWLINE$t_dont_change_this" 0 0 "/home"` && \		dlginput_shell=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_add_user" --inputbox "$t_shell$NEWLINE$t_dont_change_this" 0 0 "/bin/sh"`		case $? in	# does it what it should		1|255)		# because of the &&s (FIXME)			dlginput_user=			dlginput_realname=			dlginput_home=			dlginput_shell=			dlginput_uid=			uid=			lastuser=			func=users			;;		*)			# TODO: check if new home exists and ask for creating [done as of 302208, testing!!!]			# FIXME: TEST Test if updating of /etc/group acts correctly [is it even necessary?]			# FIXME: Ask if it should adjust autologin [should be done as of 081120, needs testing]			# FIXME cancel doesn't work			# TODO: comment what sed does						user_tmp=`echo "$dlginput_user" | sed "s/[:\\\\\"#,=\/?\']//g"`			user=`echo "$user_tmp" | sed 's/^[+@~ -]//g'`			user_tmp=`echo "$user" | sed 's/ALL//g'`			user=`echo "$user_tmp" | sed 's/default//g'`			user_tmp=			echo "DEBUG: $dlginput_user ist $user" # FIXME testing only			sleep 5 # FIXME testing only			echo "$user:xxSVJVBe8UDn2:$dlginput_uid:0:$dlginput_realname:$dlginput_home:$dlginput_shell" >> /etc/passwd			dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_set_password" --ok-label "$t_ok" --msgbox "$t_password_explanation" 0 0 && passwd "$dlginput_user"			uid=			user=			dlginput_user=			dlginput_realname=			dlginput_home=			dlginput_shell=			dlginput=			lastuser=			func="users"		esac	esac	;;#===========================#deluser)#===========================#	if [ "$list_done" != "1" ]	then		nouser="0"		prev_list="deluser"		autologin_title="$t_del_user"		func="listusers"	else		dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_del_user" --no-label "$t_no" --yes-label "$t_yes" --yesno "$t_really_del_user_1 $c_user $t_really_del_user_2" 0 0 && deluser "$c_user"		func="users"		prev_list=		c_user=		list_done=0		autologin_title=	fi	;;#===========================#lsusers)#===========================#	IFS=":"	cat /etc/passwd | while read line	do		set -- $line		allusers="$allusers|$1"		allusers="$allusers/$5"	done	line=	IFS="|"	i=1	for j in $allusers	do		IFS="/"		set -- $j		cmd="$cmd \"$i\) $1\" \"$2\""		i=`expr $i + 1`	done	allusers=	dlginput=	j=	i=	eval dlginput=\`dialog --stdout  --backtitle \""$t_dslinux_conf_wizard"\" --title \""$t_list_users"\" --ok-label \""$t_more_info"\" --cancel-label \""$t_cancel"\" --menu \"\" 0 0 0 "$cmd"\`	case $? in	1|255)		cmd=		func=start		;;	*)		cmd=		IFS=" "		set -- $dlginput		user="$2"		infos=`cat /etc/passwd | grep "^$user"`		IFS=":"		set -- $infos		[ "$1" = "nobody" ] && sysuser="$t_sysuser"		[ "$1" = "bin" ] && sysuser="$t_sysuser"		[ "$1" = "daemon" ] && sysuser="$t_sysuser"		[ "$1" = "root" ] && sysuser="$t_root"		dlginput2=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_userinfo_to_user $user $t_userinfo_to_user2" --ok-label "$t_ok" --msgbox "$t_username: $1$NEWLINE$t_passwordhash: $2${NEWLINE}UID: $3${NEWLINE}GID: $4$NEWLINE$t_realname: $5$NEWLINE$t_home: $6$NEWLINE$t_shell: $7$NEWLINE$sysuser" 0 0`		infos=		sysuser=		user=		dlginput2=		IFS="$OLDIFS"		func=lsusers		;;	esac	;;#===========================#listusers)#===========================#	IFS=":"	cat /etc/passwd | while read line	do		set -- $line		allusers="$allusers|$1"		allusers="$allusers/$5"	done	IFS="|"	i=1	for j in $allusers	do		IFS="/"		set -- $j		[ "$1" = "nobody" ] && no=1		[ "$1" = "bin" ] && no=1		[ "$1" = "daemon" ] && no=1		if [ "$no" != "1" ]		then			cmd="$cmd \"$i\) $1\" \"$2\""			i=`expr $i + 1`		else			no=		fi	done	i="$i\)"	if [ "$nouser" = "1" ]	then		eval dlginput=\`dialog --stdout  --backtitle \""$t_dslinux_conf_wizard"\" --title \""$userlist_title"\" --ok-label \""$t_ok"\" --cancel-label \""$t_cancel"\" --help-label \""$t_help"\" --menu \"\" 0 0 0 "$cmd" \""$i" ----\" \""$t_no_autologin"\" --infobox \""$t_please_wait"\" 0 0\` || { func=start; continue; } # test what || does, maybe other function as start?	else		eval dlginput=\`dialog --stdout  --backtitle \""$t_dslinux_conf_wizard"\" --title \""$userlist_title"\" --ok-label \""$t_ok"\" --cancel-label \""$t_cancel"\" --help-label \""$t_help"\" --menu \"\" 0 0 0 "$cmd" --infobox \""$t_please_wait"\" 0 0\` || { func=start; continue; } # same here	fi	case $? in		1|255) func="$prev_list" ;;	esac	cmd=	c_user=""	if [ "$i ----" != "$dlginput" ] # $i has the lastest user in it, ---- is the menutext if no user is choosen.	then		IFS=" "		set -- $dlginput		c_user="$2"	fi	i=	j=	line=	IFS="$OLDIFS"	allusers=	cmd=	dlginput=	nouser=0	list_done=1	no=0	func="$prev_list"	;;#===========================#autologin)#===========================#	if [ "$list_done" != "1" ]	then		nouser="1"		prev_list="autologin"		userlist_title="$t_autologin"		func="listusers"	else		if [ "$c_user" = "" ]		then			mv /etc/autologin.conf /etc/autologin.conf.bak			sed 's/AUTOLOGIN.*$/AUTOLOGIN=no/' /etc/autologin.conf.bak > /etc/autologin.conf		else			mv /etc/autologin.conf /etc/autologin.conf.bak			sed 's/AUTOLOGIN.*$/AUTOLOGIN=yes/' /etc/autologin.conf.bak > /etc/autologin.conf			mv /etc/autologin.conf /etc/autologin.conf.tmp			sed 's/USER.*$/USER='$c_user'/' /etc/autologin.conf.tmp > /etc/autologin.conf			rm /etc/autologin.conf.tmp		fi		func="users"		prev_list=		c_user=		list_done=0	fi	;;#==============================================================#network)#==============================================================#	dlginput=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_network" --title "$t_network" --menu "" 0 0 0 \	"1)" "WiFi" \	"2)" "esd" \	"3)" "DynDNS" \	"4)" "Boa" \	"5)" "Hostname" \	"6)" "SSH" \	"7)" "telnet" \	"8)" "FTP" \	"9)" "Samba"`	case $? in		1|255) func=start ;;	esac	case $dlginput in		1\)) func=wifi ;;		2\)) func=esd ;;		3\)) func=dns ;;		4\)) func=boa ;;		5\)) func=hostname ;;		6\)) func=ssh ;;		7\)) func==telnet ;;		8\)) func=ftp ;;		9\)) func=samba ;;	esac	;;#===========================#wifi)#===========================#	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "WiFi" --no-label "$t_no" --yes-label "$t_yes" --yesno "$t_start_wnc_now" 0 0 && wnc	func=network	;;#===========================#esd)#===========================#	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --no-label "$t_no" --yes-label "$t_yes" --yesno "$t_function_doesn_exist_yet" 0 0	func=network	;;#===========================#dns)#===========================#	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --no-label "$t_no" --yes-label "$t_yes" --yesno "$t_function_doesn_exist_yet" 0 0	func=network	;;#===========================#boa)#===========================#	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --no-label "$t_no" --yes-label "$t_yes" --yesno "$t_function_doesn_exist_yet" 0 0	func=network	;;#===========================# Needs testing! FIXMEhostname)#===========================#	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --infobox "$t_please_wait" 0 0	hostname=`cat /etc/rc.conf | grep hostname= | sed "s/hostname=//" | sed "s/\"//p"`	dlginput=`dialog --stdout --backtitle "$t_dslinux_conf_wizard" --ok-label "$t_ok" --cancel-label "$t_cancel" --help-label "$t_help" --title "$t_hostname_of_the_nds" --inputbox "$t_hostname_explanation" 0 0 $hostname` 	case $? in		1|255) func=network ;;	esac	# FIXME BUG sed gives an error (fixed?)	mv /etc/rc.conf /etc/rc.conf.bak	hostname=`echo "$dlginput" | sed s/[^a-zA-Z0-9-]//g`	if [ "$hostname" = "" ]	then		dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --ok-label "$t_damn" "$t_hostname_is_empty" 0 0	else			sed 's/hostname=.*$/hostname=\""$hostname"\"/' /etc/rc.conf.bak > /etc/rc.conf # TODO: delete non-allowed chars	fi	hostname=	func=network	;;#===========================#ssh)#===========================#	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --ok-label "$t_damn" --msgbox "$t_function_doesn_exist_yet" 0 0	func=network	;;#===========================#telnet)#===========================#	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --ok-label "$t_8damn" --msgbox "$t_function_doesn_exist_yet" 0 0	func=network	;;#===========================#ftp)#===========================#	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --ok-label "$t_damn" --msgbox "$t_function_doesn_exist_yet" 0 0	func=network	;;#===========================#samba)#===========================#	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --ok-label "$t_damn" --msgbox "$t_function_doesn_exist_yet" 0 0	func=network	;;#==============================================================#misc)#==============================================================#	dialog --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_warning" --ok-label "$t_damn" --msgbox "$t_function_doesn_exist_yet" 0 0	func=start	;;#==============================================================#about)#==============================================================#	# FIXME Intro => Credits => Lizenz per Buttons switchbar	dialog --ok-label "$t_credits" --extra-button --extra-label "$t_licence" --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_about_wizzy" --textbox /usr/share/wizzy/about 0 0	case $? in		1|255) func=start ;;		0) func=credits ;;		3) func=licence ;;	esac	;;#===========================#licence)#===========================#	dialog --ok-label "$t_about" --extra-button --extra-label "$t_credits" --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_about_wizzy" --textbox /usr/share/wizzy/copying 0 0	case $? in		1|255) func=start ;;		0) func=about ;;		3) func=credits ;;	esac	;;#===========================#credits)#===========================#	dialog --ok-label "$t_about" --extra-button --extra-label "$t_licence" --stdout --backtitle "$t_dslinux_conf_wizard" --title "$t_about_wizzy" --textbox /usr/share/wizzy/credits 0 0	case $? in		1|255) func=start ;;		0) func=about ;;		3) func=licence ;;	esac	;;#===========================#help)#===========================#[ "$helptopic" = irssi ]  && helptext="$helptext_irssi" # helptext_irssi is in lang-filefunc="$help_prev";;#=============================================================##=============================================================#esacdone