r567 - x86/trunk/scripts

justin at linuxfromscratch.org justin at linuxfromscratch.org
Thu Aug 11 16:16:52 PDT 2005


Author: justin
Date: 2005-08-11 17:16:51 -0600 (Thu, 11 Aug 2005)
New Revision: 567

Modified:
   x86/trunk/scripts/net-setup
Log:
Added GPRS modem configure, dial and hangup options to net-setup script.  Next up is normal modem ppp setup.

Modified: x86/trunk/scripts/net-setup
===================================================================
--- x86/trunk/scripts/net-setup	2005-08-11 16:57:06 UTC (rev 566)
+++ x86/trunk/scripts/net-setup	2005-08-11 23:16:51 UTC (rev 567)
@@ -120,7 +120,66 @@
 	fi
 }
 
-# 
+# GPRS Device options
+set_gprs_cfg(){
+        # Default values (only apply on first run-through, meaning GPRS_OK doesn't exist)
+        if [ -z "$GPRS_OK" ] ; then
+                F_DEVICE=\/dev\/ttyS1
+                F_SPEED=115200
+		F_SETTING=1
+        fi
+
+        DLG_COMMAND="dialog --title \"GPRS Device Configuration\" --no-cancel \
+        --form \"Please enter the GPRS device details below. The default value for the setting number is 1.\" 0 0 4 \
+        \"APN:\" 1 1 \"$F_APN\" 1 25 30 0 \
+        \"Device:\" 2 1 \"$F_DEVICE\" 2 25 20 0 \
+        \"Speed:\" 3 1 \"$F_SPEED\" 3 25 10 0 \
+	\"Setting Number:\" 4 1 \"$F_SETTING\" 4 25 4 0"
+        SELECTION=`eval $DLG_COMMAND 3>&2 2>&1 1>&3`
+
+        STATUS=$?
+        if [ "$STATUS" -ne 0 ] ; then
+                exit 1
+        fi
+
+	unset F_APN F_DEVICE F_SPEED F_SETTING
+        eval "`echo "$SELECTION" | sed -e '1s,^,F_APN=",' -e '2s,^,F_DEVICE=",' \
+              -e '3s,^,F_SPEED=",' -e '4s,^,F_SETTING=",' | sed -e 's,$,",'`"
+
+        # Validate entries (All values are required.)
+        GPRS_OK=1
+	if [ -z "$F_APN" -o -z "$F_DEVICE" -o -z "$F_SPEED" -o -z "$F_SETTING" ] ; then
+		GPRS_OK=0
+		GPRS_ERRMSG="All fields are required to setup your GPRS device."
+	fi
+
+        if [ "$GPRS_OK" -eq 1 ] ; then
+		# Make a backup and restore before changes, so the sed's work correctly.
+		[ -f /etc/ppp/peers/gprs.orig ] || cp /etc/ppp/peers/gprs /etc/ppp/peers/gprs.orig
+		[ -f /etc/ppp/gprs.chat.orig ] || cp /etc/ppp/gprs.chat /etc/ppp/gprs.chat.orig
+		cp /etc/ppp/peers/gprs.orig /etc/ppp/peers/gprs
+		cp /etc/ppp/gprs.chat.orig /etc/ppp/gprs.chat
+
+		# Alter /etc/ppp/peers/gprs file.
+		sed -i -e "s at inet.example.com@$F_APN at g" -e "s@/dev/ttyS1@$F_DEVICE at g" \
+		       -e "s at 115200@$F_SPEED at g" /etc/ppp/peers/gprs
+
+		# Alter /etc/ppp/gprs.chat (advanced setting)
+		sed -i -e "s at CGDCONT=1 at CGDCONT=$F_SETTING at g" \
+                       -e "s@\*\*\*1@\*\*\*$F_SETTING at g" /etc/ppp/gprs.chat
+
+                unset F_APN F_DEVICE F_SPEED F_SETTING DLG_COMMAND STATUS
+                unset SELECTION GPRS_OK GPRS_ERRMSG
+        else
+                DLG_COMMAND="dialog --title \"GPRS Validation Error\" \
+                --msgbox \"$GPRS_ERRMSG\" 6 60"
+                eval $DLG_COMMAND
+                set_gprs_cfg;
+        fi
+}
+
+
+# Main Menu for Network Devices
 net_service_menu(){
 	# Remove previous config, so ifup won't get confused.
 	rm -f $ETHXCFG
@@ -168,11 +227,54 @@
 			adsl-setup
 			;;
 		*)
-			exit 0;
+			exit 0
 			;;
 	esac
 }
 
+# Main Menu for ppp modem devices
+ppp_modem_menu(){
+	echo "Modems will be supported soon."
+}
+
+# Main Menu for ppp gprs devices
+ppp_gprs_menu(){
+        unset ARGS
+        ARGS="$ARGS configure \"Configure your GPRS device.\""
+        ARGS="$ARGS dial \"Dial GPRS device and exit.\""
+        ARGS="$ARGS hangup \"Hang up GPRS device and exit.\""
+
+        DLG_COMMAND="dialog --title \"GPRS Device - Actions\" --default-item configure \
+                --menu \"Select the action to perform for your GPRS device:\" \
+                0 0 0 $ARGS"
+        SERVICE=`eval $DLG_COMMAND 3>&2 2>&1 1>&3`
+
+        unset DLG_COMMAND ARGS
+
+        case "$SERVICE" in
+
+                configure)
+			set_gprs_cfg;
+                        ;;
+
+                dial)
+			[ -e /dev/ppp ] || mknod /dev/ppp c 108 0 
+			modprobe ppp-generic ; pppd call gprs
+			exit 0
+                        ;;
+
+                hangup)
+			killall pppd
+			exit 0
+                        ;;
+                *)
+                        exit 0
+                        ;;
+        esac
+
+	ppp_gprs_menu;
+}
+
 # Script starts here. Check for root user.
 if [ `whoami` != "root" ] ; then
 	echo "You must be root to use $0"
@@ -193,7 +295,8 @@
 		EDEVSTATUS="DOWN"
 	fi
 	DEVLIST="$DEVLIST `basename $EDEV` \"$EDEVSTATUS\""
-done		
+done
+DEVLIST="$DEVLIST ppp-modem \"Configure a dial-up Modem\" ppp-gprs \"Configure a GPRS Modem\""
 
 DLG_COMMAND="dialog --title \"Network Configuration\" --default-item eth0 \
        	--timeout 20 --menu \"Select the network device to configure:\" \
@@ -203,6 +306,16 @@
 
 # Continue if device was selected, exit if otherwise.
 if [ -n "$DEV" ] ; then
+	if [ "$DEV" == "ppp-modem" ] ; then
+		ppp_modem_menu;
+		exit 0
+	fi
+	if [ "$DEV" == "ppp-gprs" ] ; then
+		ppp_gprs_menu;
+		exit 0
+	fi
+	
+	# If not ppp-modem or ppp-gprs, then network device to configure
 	set_devvars;
 
 	if [ -n "$LINKTEST" ] ; then




More information about the livecd mailing list