diff --git a/network/config-interfaces b/network/config-interfaces new file mode 100755 index 0000000..7f0d69b --- /dev/null +++ b/network/config-interfaces @@ -0,0 +1,101 @@ +#!/bin/sh + +# [1] Manage missing parameter +if [ $# -lt 1 ]; then + echo "missing argument {interface_path}" && exit; +fi; + +# variables +path=`realpath $1`; +CONFIG=""; + +# [2] create current config backup (safe) +cp $path $path.save \ + && echo "config backup created" \ + || ( echo "cannot create config backup" && exit ); + +# [3] Data / Option choice +echo "\n== REQUIRED =="; + + # (1) Manage interface choice + read -p "Interface name: " iface_name; + + test -z "$iface_name" && echo "empty interface name !\naborting" && exit; + + CONFIG="auto $iface_name"; + + + + + + read -p "Use dhcp or static config (d/s) [d]" config_type; + + test -z "$config_type" && config_type="d"; + + ## (1) STATIC IP ## + if [ $config_type = "s" ]; then + + CONFIG="$CONFIG\niface $iface_name inet static"; + + echo "\nNetwork configuration (leave blank not to mention a field)"; + read -p "ip address: " s_address; + read -p "network mask: " s_netmask; + read -p "network address: " s_network; + read -p "gateway address: " s_gateway; + read -p "broadcast address: " s_broadcast; + + test -n "$s_address" && CONFIG="$CONFIG\n\taddress\t$s_address"; + test -n "$s_netmask" && CONFIG="$CONFIG\n\tnetmask\t$s_netmask"; + test -n "$s_network" && CONFIG="$CONFIG\n\tnetwork\t$s_network"; + test -n "$s_gateway" && CONFIG="$CONFIG\n\tgateway\t$s_gateway"; + test -n "$s_broadcast" && CONFIG="$CONFIG\n\tbroadcast\t$s_broadcast"; + + ## (2) DHCP ## + else + CONFIG="$CONFIG\niface $iface_name inet dhcp"; + fi; + + + + + + + # (3) Set wpa if wanted + read -p "is it a wireless interface ? (y/n) [n]" is_wireless; + + test -z "$is_wireless" && is_wireless="n"; + + ## Set Wireless credentials + if [ -n "$is_wireless" -a $is_wireless = "y" ]; then + read -p "Wifi SSID:" w_ssid; + read -p "Wifi PASSWORD:" w_pass; + + w_psk=$( wpa_passphrase "$w_ssid" "$w_pass" | grep -E "^\spsk" | sed 's/^\spsk=//' ); + + # add ssid/psk to config + CONFIG="$CONFIG\n\twpa-ssid\t$w_ssid\n\twpa-psk\t$w_psk"; + fi; + + + + +echo "\n== OPTIONAL =="; + + # (4) Add pre/post scripts + read -p "add 'pre-up' script:" pre_up; + test -n "$pre_up" && test -a $pre_up && CONFIG="$CONFIG\n\tpre-up\t$pre_up"; + + read -p "add 'up' script:" up; + test -n "$up" && test -a $up && CONFIG="$CONFIG\n\tup\t$up"; + + read -p "add 'down' script:" up; + test -n "$down" && test -a $down && CONFIG="$CONFIG\n\tdown\t$down"; + + read -p "add 'post-down' script:" up; + test -n "$post_down" && test -a $post_down && CONFIG="$CONFIG\n\tpost-down\t$post_down"; + + + + +echo $CONFIG > $path; +echo "\n== WRITTEN TO FILE ==";