diff options
author | Jouke Witteveen <j.witteveen@gmail.com> | 2013-04-18 09:14:08 +0200 |
---|---|---|
committer | Jouke Witteveen <j.witteveen@gmail.com> | 2013-04-18 09:14:08 +0200 |
commit | e95c9680e0632d835a1786a74c1d2bb2fc5b4a60 (patch) | |
tree | f77638a0edf689fd78a42766c049f20fe106d214 /src/lib/connections/mobile_ppp | |
parent | e1ae4c56483ee2664a5448a305019b43f1b10ad9 (diff) | |
download | netctl-e95c9680e0632d835a1786a74c1d2bb2fc5b4a60.tar.gz netctl-e95c9680e0632d835a1786a74c1d2bb2fc5b4a60.tar.xz |
Small review of PPP related connections
The most important change is that we now bring the interface down
correctly in pppoe_down.
Diffstat (limited to 'src/lib/connections/mobile_ppp')
-rw-r--r-- | src/lib/connections/mobile_ppp | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/lib/connections/mobile_ppp b/src/lib/connections/mobile_ppp index 19d63f9..d117367 100644 --- a/src/lib/connections/mobile_ppp +++ b/src/lib/connections/mobile_ppp @@ -3,11 +3,11 @@ # Also see <https://wiki.archlinux.org/index.php/3G_and_GPRS_modems_with_pppd> for more information. : ${PPPD:=pppd} -# Set the interface route : ${InterfaceRoot=dev/} -_quotestring() { - echo "\"${1/\"/\\\"}\"" +quote_word() { + set -- "${@//\\/\\\\}" + printf '"%s"\n' "${@/\"/\\\"}" } mobile_ppp_up() { @@ -18,11 +18,9 @@ mobile_ppp_up() { chmod 700 "$STATE_DIR/mobile_ppp.${Interface}.${Profile}/" cfg="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/options" chat="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/modem.chat" - : > "${cfg}" + echo "linkname $(quote_word "${Profile}")" > "${cfg}" chmod 600 "${cfg}" - echo "linkname $(_quotestring "${Profile}")" >> "${cfg}" - cat >> "${cfg}" << EOF ${Interface} 921600 @@ -53,8 +51,8 @@ EOF # Writes username and password echo "noauth" >> "${cfg}" echo "hide-password" >> ${cfg} - [[ -n ${User} ]] && echo "user $(_quotestring "${User}")" >> "${cfg}" - [[ -n ${Password} ]] && echo "password $(_quotestring "${Password}")" >> "${cfg}" + [[ -n ${User} ]] && echo "user $(quote_word "${User}")" >> "${cfg}" + [[ -n ${Password} ]] && echo "password $(quote_word "${Password}")" >> "${cfg}" #echo "'OK' @/etc/ppp/chatscripts/pin" >> "${chat}" if [ -n "${Pin}" ]; then @@ -116,11 +114,7 @@ EOF # Add the chat script line to the configuration echo "connect \"/usr/sbin/chat -v -t15 -f ${chat}\"" >> "${cfg}" - ip link set dev "${Interface}" up - #$PPPD call "$Peer" updetach child-timeout "$PPPTimeout" linkname "$Peer" - $PPPD file "${cfg}" - - if [[ $? -ne 0 ]]; then + if ! $PPPD file "${cfg}"; then rmdir "$STATE_DIR/mobile_ppp.${Interface}.${Profile}/" report_error "Couldn't make pppd connection." return 1 @@ -128,19 +122,17 @@ EOF } mobile_ppp_down() { - local cfg - local chat + local cfg chat pidfile pid cfg="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/options" chat="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/modem.chat" - PIDFILE="/var/run/ppp-${Profile}.pid" + pidfile="/var/run/ppp-${Profile}.pid" - if [[ -e $PIDFILE ]]; then - read PID < "$PIDFILE" - [[ "$PID" ]] && kill "$PID" + if [[ -e $pidfile ]]; then + read pid < "$pidfile" + [[ "$pid" ]] && kill "$pid" fi - rm "${cfg}" - rm "${chat}" + rm "${cfg}" "${chat}" rmdir "$STATE_DIR/mobile_ppp.${Interface}.${Profile}/" } |