diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/ifplugd.action | 49 | ||||
-rwxr-xr-x | scripts/netcfg | 106 | ||||
-rwxr-xr-x | scripts/netcfg-daemon | 102 | ||||
-rwxr-xr-x | scripts/netcfg-menu | 55 | ||||
-rwxr-xr-x | scripts/netcfg-wpa_actiond | 87 | ||||
-rwxr-xr-x | scripts/netcfg-wpa_actiond-action | 56 | ||||
-rwxr-xr-x | scripts/pm-utils | 26 | ||||
-rwxr-xr-x | scripts/wifi-menu | 263 |
8 files changed, 0 insertions, 744 deletions
diff --git a/scripts/ifplugd.action b/scripts/ifplugd.action deleted file mode 100755 index ea3a16c..0000000 --- a/scripts/ifplugd.action +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -# -# ifplugd.action script for netcfg - -. /usr/lib/network/network - -case "$2" in - up) - # Look for a dhcp based profile to try first - # dhcp can actually outright fail, whereas - # it's difficult to tell if static succeeded - # Also check profile is same iface and is right connection - echo "up" - declare -a preferred_profiles - declare -a dhcp_profiles - declare -a static_profiles - for profile in $(list_profiles); do - ( - echo "loading $profile" - load_profile "$profile" - [[ "$INTERFACE" == "$1" && "$CONNECTION" == "ethernet" ]] || continue - checkyesno "${AUTO_WIRED:-no}" && exit 1 # user preferred AUTO profile - [[ "$IP" == "dhcp" ]] && exit 2 # dhcp profile - exit 3 # static profile - ) - case $? in - 1) preferred_profiles+=("$profile");; - 2) dhcp_profiles+=("$profile");; - 3) static_profiles+=("$profile");; - esac - done - if [[ ${#preferred_profiles[@]} > 1 ]]; then - echo "AUTO_WIRED flag for $1 set in more than one profile (${preferred_profiles[*]})" - fi - for profile in "${preferred_profiles[@]}" "${dhcp_profiles[@]}" "${static_profiles[@]}"; do - profile_up "$profile" && exit 0 - done - ;; - down) - if check_iface "$1"; then - interface_down "$1" && exit 0 - fi - ;; - *) - echo "Wrong arguments" > /dev/stderr - ;; -esac - -exit 1 diff --git a/scripts/netcfg b/scripts/netcfg deleted file mode 100755 index f1d79e8..0000000 --- a/scripts/netcfg +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/bash - -. /usr/lib/network/network - -NETCFG_VER=2-notpackaged - -version() -{ - echo "netcfg v$NETCFG_VER" -} - -usage() -{ - version - cat << END -Usage: - Start specified profile: netcfg profile - Other functions: netcfg argument profile -Arguments: - current Report currently running profiles --a, all-down Take all active profiles down --c, check-iface Do not start profile if interface is already up --d, down Take specified profile down --D, iface-down Take down profile active on specified interface --h, help This help message --l, list List all available profiles --r, reconnect Disconnect and reconnect specified profile --R, iface-recon Reconnect profile active on specified interface --u, up Start specified profile --v, version Output version information and exit - all-resume Resume previously suspended profiles and reconnect them - all-suspend Store a list of current running profiles and suspend them -END -} - -# TODO: Re-add ROOT check and rewrite with getopts from BashFAQ - -case "$1" in - --version|-v|version) - version - exit 0;; - --help|-h|help) - usage - exit 0;; - list|-l) - list_profiles - exit 0;; - current|-s|status) - if [[ -d "$STATE_DIR/profiles/" ]]; then - ls "$STATE_DIR/profiles/" - exit 0 - else - exit_stderr "No active profiles." - fi;; -esac - -if [[ $(id -u) -gt 0 ]]; then - exit_stderr "This script should be run as root." -fi - -# Ensure cwd is not in a transient directory, which may prevent unmounting due to netcfg children -cd / - -case "$1" in - -c|check-iface|-u|up) - CHECK="YES" - profile_up "$2";; - -d|down) - profile_down "$2";; - -D|iface-down) - interface_down "$2";; - -a|all-down) - all_down;; - -r|reconnect) - profile_down "$2" - profile_up "$2";; - -R|iface-recon) - interface_reconnect "$2";; - all-resume) - all_resume;; - all-suspend) - all_suspend;; - clean) - rm "$STATE_DIR/interfaces"/* 2> /dev/null - rm "$STATE_DIR/profiles"/* 2> /dev/null - rm "$STATE_DIR/suspend"/* 2> /dev/null - rm "$STATE_DIR/netcfg-daemon" 2> /dev/null - killall wpa_supplicant 2> /dev/null - killall dhcpcd 2> /dev/null - killall dhclient 2> /dev/null - ;; - -*|--*) - usage - exit 1;; - *) - if [[ -n "$1" ]]; then - profile_up "$1" - else - usage - exit 1 - fi - ;; -esac -exit $? - -# vim: ft=sh ts=4 et sw=4: diff --git a/scripts/netcfg-daemon b/scripts/netcfg-daemon deleted file mode 100755 index b3111da..0000000 --- a/scripts/netcfg-daemon +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash -# -# This script implements support for the NETWORKS array in /etc/conf.d/netcfg. - -. /usr/lib/network/globals -. /etc/conf.d/netcfg -STATE_FILE="$STATE_DIR/netcfg-daemon" -LAST_STATE="/var/lib/netcfg/netcfg.state" - -case "$1" in - start) - (( $(id -u) )) && exit_stderr "This script should be run as root." - [[ -e $STATE_FILE ]] && exit_err "netcfg-daemon is already started" - [[ ${NETWORKS+x} != x ]] && exit_err "NETWORKS is not set in /etc/conf.d/netcfg" - - if [[ ${#NETWORKS[@]} -eq 1 ]]; then - case $NETWORKS in - last) - if [[ ! -e $LAST_STATE ]]; then - report_err "No recorded netcfg state to restore" - # This counts as successful startup since the daemon - # should be stopped on shutdown. - exit 0 - fi - - # The order in LAST_STATE is meaningless so we can just as - # well start the profiles in parallel. - while read profile; do - if /usr/bin/netcfg up "$profile"; then - echo "$profile" >> "$STATE_FILE" - fi & - done < "$LAST_STATE" - wait - exit $? ;; - menu) - /usr/bin/netcfg-menu ${NETWORKS_MENU_TIMEOUT-5} && \ - mv "$STATE_DIR/menu" "$STATE_FILE" - exit $? ;; - esac - fi - - for profile in "${NETWORKS[@]}"; do - if [[ "$profile" = "${profile#@}" ]]; then - if /usr/bin/netcfg check-iface "$profile"; then - echo "$profile" >> "$STATE_FILE" - fi - else - # It is up to the user to make sure no backgrounded profile - # uses an interface that is used by another active profile. - if /usr/bin/netcfg up "${profile#@}"; then - echo "$profile" >> "$STATE_FILE" - fi >/dev/null & - PROFILE_BKGD=1 - fi - done - # Generate a return value. - [[ -f $STATE_FILE || -n $PROFILE_BKGD ]] - ;; - stop) - (( $(id -u) )) && exit_stderr "This script should be run as root." - - if [[ ${#NETWORKS[@]} -eq 1 && $NETWORKS = last ]]; then - mkdir -p "$(dirname "$LAST_STATE")" - /usr/bin/netcfg current > "$LAST_STATE" - /usr/bin/netcfg all-down - exit $? - fi - - [[ ! -e $STATE_FILE ]] && exit_err "netcfg-daemon was not started" - # Stop the profiles in the reverse order they were started. - tac "$STATE_FILE" | ( - while read profile; do - if [[ -e "$STATE_DIR/profiles/${profile#@}" ]]; then - if [[ "$profile" = "${profile#@}" ]]; then - /usr/bin/netcfg down "$profile" || exit $? - else - /usr/bin/netcfg down "${profile#@}" & - fi - fi - done - rm "$STATE_FILE" - # Generate a return value and make sure we are good to restart. - wait - ) - ;; - restart) - "$0" stop - sleep 1 - "$0" start - ;; - status) - if [[ -e $STATE_FILE ]]; then - report_notice "profiles started by netcfg-daemon:" - sed 's/^@//' "$STATE_FILE" - else - report_notice "netcfg-daemon was not started" - fi - ;; - *) - echo "Usage: $0 {start|stop|restart|status}" -esac - diff --git a/scripts/netcfg-menu b/scripts/netcfg-menu deleted file mode 100755 index 9a875ae..0000000 --- a/scripts/netcfg-menu +++ /dev/null @@ -1,55 +0,0 @@ -#! /bin/bash - -. /usr/lib/network/network - -if ! type dialog &> /dev/null; then - echo "Please install 'dialog' to use netcfg-menu" - exit 1 -fi - -check_make_state_dir -# JP: we'll use $STATE_DIR/menu to record what profile is being connected in this way -rm -f "$STATE_DIR/menu" - -# Set timeout -TIMEOUT=${1-0} - -# Scan all profiles -i=0 -# JP: change for prof to while read prof to avoid assumption that profile names are always single tokens (no spaces etc.) -while read prof; do - # if there is a profile called "main", Use as default - [[ "$prof" = "main" ]] && DEFAULT="main" - profiles[i++]="$prof" - profiles[i++]=$(. "$PROFILE_DIR/$prof"; echo "$DESCRIPTION") -done < <(list_profiles | sort) # JP: re-use list_profiles instead of duplicating it; avoid subshell we'd get by piping it to the while read... - -if [[ ${#profiles} -eq 0 ]]; then - exit_err "No profiles were found in $PROFILE_DIR" -fi - -[[ -n "$NETWORKS_MENU_DEFAULT" ]] && DEFAULT="$NETWORKS_MENU_DEFAULT" -# if no default yet, use the first entry -[[ -z "$DEFAULT" ]] && DEFAULT="${profiles[0]}" - -# Display Dialog -PROFILE=$(dialog --timeout "$TIMEOUT" --default-item "$DEFAULT" --stdout \ - --menu 'Select the network profile you wish to use' \ - 13 50 6 "${profiles[@]}") -ret=$? -case $ret in - 1) ;; # Cancel - do nothing - 255|0) # Timeout (use default) or user selection - [[ -z "$PROFILE" ]] && PROFILE="$DEFAULT" - profile_up "$PROFILE" - ret=$? - (( ret == 0 )) && echo "$PROFILE" > "$STATE_DIR/menu" - ;; - *) # Should not happen - exit_err "Abnormal return code from dialog: $ret" - ;; -esac - -exit $ret # JP: exit with caught $? - -# vim: ft=sh ts=4 et sw=4: diff --git a/scripts/netcfg-wpa_actiond b/scripts/netcfg-wpa_actiond deleted file mode 100755 index c6aaf67..0000000 --- a/scripts/netcfg-wpa_actiond +++ /dev/null @@ -1,87 +0,0 @@ -#! /bin/bash -. /usr/lib/network/network -. "$SUBR_DIR/8021x" -. "$SUBR_DIR/rfkill" -. /etc/conf.d/netcfg - -AUTOWIFI="/usr/sbin/wpa_actiond -p /run/wpa_supplicant" -ACTION_SCRIPT="/usr/bin/netcfg-wpa_actiond-action" - -case $1 in - help) - echo "netcfg-wpa_actiond <interface>" - echo "netcfg-wpa_actiond stop <interface>" - exit - ;; - stop) - [[ -z $2 ]] && echo "Please specify an interface to stop" && exit 1 - interface=$2 - PIDFILE="/run/wpa_actiond_${interface}.pid" - [[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface" - netcfg -D "$interface" - timeout_wait 1 '[[ ! -f "$PIDFILE" ]]' || kill "$(< "$PIDFILE")" - # only try to disable software rfkill switches (FS#25514) - if [[ "$RFKILL" == "soft" ]]; then - set_rf_state "$interface" disabled $RFKILL_NAME || exit $? - fi - exit - ;; - *) - interface=$1; shift - PIDFILE="/run/wpa_actiond_${interface}.pid" - EXTRA_AUTOWIFI_OPTIONS="$*" - ;; -esac - -if [[ -z $interface ]]; then - echo "No interface specified" - exit 1 -fi - -# Load interface specific config -[[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface" - -if [[ -f "$CONN_DIR/interfaces/$interface" ]]; then - netcfg -D "$interface" -fi - -if [[ -n "$RFKILL" ]]; then # Enable radio if necessary - enable_rf "$interface" "$RFKILL" "$RFKILL_NAME" || exit $? -fi - -WPA_CONF="$(make_wpa_config_file "$interface")" - -if [[ -n "${AUTO_PROFILES}" ]]; then - for prof in "${AUTO_PROFILES[@]}"; do echo "$prof"; done -else - list_profiles -fi | while read profile; do - echo "$profile" - ( - load_profile "$profile" - - [[ $CONNECTION != "wireless" ]] && exit 1 - [[ $INTERFACE != $interface ]] && exit 1 - # Exclude wpa-config, the wpa_conf is 'complete' and doesn't fit in this scheme - [[ -z "$SECURITY" ]] && SECURITY="none" - [[ $SECURITY == "wpa-config" ]] && exit 1 - - printf "%s\n" "network={" "$(make_wpa_config)" "id_str=\"$profile\"" "}" >> "$WPA_CONF" - ) -done - - -[[ -z $WPA_DRIVER ]] && WPA_DRIVER="nl80211,wext" -WPA_OPTS="-W $WPA_OPTS" - -# Kill any existing wpa_supplicant on this interface -stop_wpa "$interface" &> /dev/null - -if start_wpa "$interface" "$WPA_CONF" "$WPA_DRIVER" $WPA_OPTS; then - if $AUTOWIFI -i "$interface" -P "$PIDFILE" -a "$ACTION_SCRIPT" $EXTRA_AUTOWIFI_OPTIONS; then - exit 0 - fi -fi - -exit 1 - diff --git a/scripts/netcfg-wpa_actiond-action b/scripts/netcfg-wpa_actiond-action deleted file mode 100755 index 1f29364..0000000 --- a/scripts/netcfg-wpa_actiond-action +++ /dev/null @@ -1,56 +0,0 @@ -#! /bin/bash - -interface="$1" -ssid="$2" -profile="$3" -action="$4" - -. /usr/lib/network/network -[[ "$profile" ]] && load_profile "$profile" - -case $action in - CONNECT) - if [[ -z $profile ]]; then - # Load interface specific config - [[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface" - dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" -K $DHCP_OPTIONS "$interface" - exit $? - fi - if ! DHCPCD_INTERNAL_OPTIONS="-K" $CONN_DIR/ethernet up "$profile"; then - exit 1 # what to do if fail? - fi - - set_profile up "$profile" - - if ! ( eval $POST_UP ); then # JP: sandbox the eval - # failing POST_UP will take interface down - "$CONN_DIR/$ethernet" down "$profile" - exit 1 - fi - ;; - DISCONNECT) - if [[ -z $profile ]]; then - dhcpcd -k "$interface" - exit $? - fi - if ! ( eval $PRE_DOWN ); then # JP: sandbox the eval - exit 1 - fi - if ! "$CONN_DIR/ethernet" down "$profile"; then - exit 1 - fi - if ! ( eval $POST_DOWN ); then # JP: sandbox the eval - exit 1 - fi - set_profile down "$profile" - ;; - LOST|REESTABLISHED) - # Not handled. - exit 0 - ;; - *) - # ??? - exit 1 - ;; -esac - diff --git a/scripts/pm-utils b/scripts/pm-utils deleted file mode 100755 index 93ee763..0000000 --- a/scripts/pm-utils +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -. /usr/lib/pm-utils/functions - -suspend_netcfg() { - netcfg all-suspend -} - -resume_netcfg() { - netcfg all-resume -} - -if type netcfg > /dev/null; then - case "$1" in - hibernate|suspend) - suspend_netcfg - ;; - thaw|resume) - resume_netcfg - ;; - *) - ;; - esac -fi - -exit $? diff --git a/scripts/wifi-menu b/scripts/wifi-menu deleted file mode 100755 index f46db0d..0000000 --- a/scripts/wifi-menu +++ /dev/null @@ -1,263 +0,0 @@ -#! /bin/bash - -. /usr/lib/network/network -. "$SUBR_DIR/8021x" -. /etc/conf.d/netcfg - -usage() -{ - cat << END -Usage: wifi-menu [-o | --obscure] [-h | --help] [interface] - -Interactively connect to a wireless network. - -Arguments: - -o, --obscure Show asterisks for the characters of the password - and store the password as a hexadecimal string. - -h, --help Show this help. - interface The wireless interface to use. - (default: WIRELESS_INTERFACE from /etc/conf.d/netcfg) - -For choosing from all available profiles, use netcfg-menu. -END -} - -# Fills PROFILES and ESSIDS with the profile names and essids of the profiles -# for interface $1. -init_profiles() -{ - local i=0 essid profile - while read profile; do - essid=$( - unset INTERFACE ESSID - . "$PROFILE_DIR/$profile" &> /dev/null - if [[ "$INTERFACE" = "$1" && -n "$ESSID" ]]; then - printf "%s" "$ESSID" - if [[ "$DESCRIPTION" =~ "Automatically generated" ]]; then - return 2 - else - return 1 - fi - fi - return 0 - ) - case $? in - 2) - GENERATED+=("$profile") - ;& - 1) - PROFILES[i]=$profile - ESSIDS[i]=$essid - (( ++i )) - ;; - esac - done < <(list_profiles) -} - -# Builds ENTRIES as an argument list for dialog based on scan results in $1. -init_entries() -{ - local i=0 flags signal ssid - while IFS=$'\t' read signal flags ssid; do - ENTRIES[i++]="--" # $ssid might look like an option to dialog. - ENTRIES[i++]=$ssid - if inarray "$ssid" "${ESSIDS[@]}"; then - if inarray "$(ssid_to_profile "$ssid")" "${GENERATED[@]}"; then - ENTRIES[i]="+" # Automatically generated - else - ENTRIES[i]="*" # Handmade - fi - else - ENTRIES[i]="-" # Not present - fi - if [[ "$ssid" = "$CONNECTION" ]]; then - ENTRIES[i]="!" # Currently connected - fi - if [[ "$flags" =~ WPA2|WPA|WEP ]]; then - ENTRIES[i]+=":${BASH_REMATCH[0],,}" - else - ENTRIES[i]+=":none" - fi - ENTRIES[i]+=" :$signal" - (( ++i )) - done < "$1" -} - -# Finds a profile name for ssid $1. -ssid_to_profile() -{ - local i - for i in $(seq 0 $((${#ESSIDS[@]}-1))); do - if [[ "$1" = "${ESSIDS[i]}" ]]; then - printf "%s" "${PROFILES[i]}" - return 0 - fi - done - return 1 -} - -# Creates a profile for ssid $1. -create_profile() -{ - local box flags key msg security - PROFILE="$INTERFACE-${1//\//_}" - [[ -e "$PROFILE_DIR/$PROFILE" ]] && PROFILE+=".wifi-menu" - flags=$(grep -m 1 $'\t'"$1\$" "$NETWORKS" | cut -f 2) - if [[ "$flags" =~ WPA|WEP ]]; then - security=${BASH_REMATCH[0],,} - else - security=none - fi - if [[ "$flags" =~ PSK|WEP ]]; then - [[ "$OBSCURE" ]] && box="--insecure --passwordbox" || box="--inputbox" - msg="Enter $security security key for\n'$1'" - key=$(dialog $box "$msg" 10 40 --stdout) || return $? - if [[ "${#key}" -ge 8 && "${#key}" -le 63 ]]; then - if [[ "$OBSCURE" ]]; then - key=$(wpa_passphrase "$1" "$key" | grep -m 1 "^[[:space:]]*psk=") - key=${key#*psk=} - else - key=$(printf "%q" "$key") - fi - elif ! [[ "${#key}" -eq 64 && "$key" = +([[:xdigit:]]) ]]; then - return 4 - fi - fi - cat << EOF > "$PROFILE_DIR/$PROFILE" -CONNECTION='wireless' -DESCRIPTION='Automatically generated profile by wifi-menu' -INTERFACE='$INTERFACE' -SECURITY='$security' -ESSID=$(printf "%q" "$1") -IP='dhcp' -${key+KEY=$key} -EOF - printf "%s" "$PROFILE" - return 0 -} - -# Connects to ssid $1 using an available profile or an automatically created -# one if none exists. -connect_to_ssid() -{ - local msg - PROFILE=$(ssid_to_profile "$1") - if [[ $? -eq 0 ]]; then - clear - check_profile "$PROFILE" && profile_down "$PROFILE" - else - PROFILE=$(create_profile "$1") - RETURN=$? - (( RETURN == 0 )) || return $RETURN - SPAWNED_PROFILE=1 - clear - fi - if ! profile_up "$PROFILE"; then - if (( SPAWNED_PROFILE )); then - msg=" CONNECTING FAILED - -Do you want to keep the generated profile ('$PROFILE')?" - dialog --yesno "$msg" 10 40 --stdout || rm "$PROFILE_DIR/$PROFILE" - clear - fi - return 2 - fi - return 0 -} - -while [[ "$1" = -* ]]; do - case "$1" in - -h|--help) - usage - exit - ;; - -o|--obscure) - OBSCURE=1 - shift - ;; - -*) - report_err "Invalid option: $1" - usage - exit 255 - ;; - esac -done -if [[ $# -gt 1 ]]; then - report_err "Too many arguments" - usage - exit 255 -fi - -if [[ $(id -u) -ne 0 ]]; then - exit_stderr "This script needs to be run with root privileges" -fi -if ! type dialog &> /dev/null; then - exit_stderr "Please install 'dialog' to use wifi-menu" -fi - -INTERFACE=${1-$WIRELESS_INTERFACE} -if [[ -z "$INTERFACE" ]]; then - report_err "Missing interface specification" - usage - exit 255 -fi - -cd / # We do not want to spawn anything that can block unmounting -is_interface "$INTERFACE" || exit_fail "No such interface: $INTERFACE" -if ! interface_is_up "$INTERFACE"; then - [[ -f "$IFACE_DIR/$INTERFACE" ]] && . "$IFACE_DIR/$INTERFACE" - bring_interface up "$INTERFACE" || exit_fail "Interface unavailable" - SPAWNED_INTERFACE=1 -fi - -report_try "Scanning for networks" -CONNECTION=$(wpa_call "$INTERFACE" status 2> /dev/null | grep -m 1 "^ssid=") -CONNECTION=${CONNECTION#ssid=} -NETWORKS=$(wpa_supplicant_scan "$INTERFACE" 3,4,5) -if [[ $? -eq 0 ]]; then - trap 'rm -f "$NETWORKS"' EXIT - report_success - init_profiles "$INTERFACE" - init_entries "$NETWORKS" - MSG="Select the network you wish to use -Flags description: - * - handmade profile present - + - automatically generated profile present - - - no profile present - ! - active connection present" - CHOICE=$(dialog --column-separator : --menu "$MSG" 24 50 12 \ - "${ENTRIES[@]}" --stdout) - RETURN=$? - if (( RETURN == 0 )); then - connect_to_ssid "$CHOICE" - RETURN=$? - fi -else - report_fail - RETURN=3 -fi - -case $RETURN in - 0|2) # Connected | Connecting failed - ;; - 1) # Canceled - clear - ;; - 3) # No networks found - report_err "No networks found" - ;; - 4) # Invalid passphrase length (WEP keys have tighter restrictions) - clear - report_err "Passphrase must be 8..63 characters" - ;; - 255) # ESC or error - clear - report_err "Aborted" - ;; - *) # Should not happen - report_err "Unexpected return code from dialog: $RETURN" - RETURN=7 - ;; -esac -(( RETURN && SPAWNED_INTERFACE )) && bring_interface down "$INTERFACE" -exit $RETURN |