Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #-------------------------------------------------------------------------------
- # Script Created by Vincent - EZ-Arch Project (ezarchproject@gmail.com)
- # Distro Sourceforge - https://sourceforge.net/projects/ezarchlinux/
- # Distro Youtube - E-Z Arch Project.
- #
- # About these Scripts. Some were inspired from AUI Installer on ARCH Linux
- # and some came out of FreeBSD too and couple of commerical UNIX such as dfspace
- #
- #-------------------------------------------------------------------------------
- #This program 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.
- #
- #This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
- #-------------------------------------------------------------------------------
- # Run this script after your first boot with archlinux (as root)
- #--------------------------------------------------------------------------------
- # Explaination of the Script:
- #
- # This is for Networking side of things on Arch Linux
- #
- # I have only used DHCP and havent really dealt with other types of
- # Networking to deal with the installation of this OS.
- #
- #
- # This servs perpose at work
- #
- # -----------------------------------------------------------------------------------
- #
- #
- #
- INSTALLDIR=/usr/INSTALLER/lib # New Location of this Installer
- if [[ -f $INSTALLDIR/gfuncs.sh ]]; then
- source $INSTALLDIR/gfuncs.sh
- # if [[ -f ./gfuncs.sh ]]; then
- # source ./gfuncs.sh
- else
- echo "Error missing file: gfuncs.sh - Required for installer"
- echo "Installer's Directory is $INSTALLDIR"
- exit 1
- fi
- #-------------------------------------------------------------------------------
- #Examples in /etc/netctl/examples
- EDITOR=nano
- NETCTLDIR=/etc/netctl
- NETCTLEX=/etc/netctl/examples
- # Network Tasks
- NTASK1='-'
- NTASK2='-'
- NTASK3='-'
- NTASK4='-'
- # Configure Network Cards
- ############################### Config Network Devices
- # 1st NIC
- Config1NIC()
- {
- # 1st Network Devices if more than 1 is installed
- WIRED_DEV=`ip link | grep enp | awk '{print $2}' | sed 's/://' | sed '1!d'`
- WIRELESS_DEV=`ip link | grep wlp | awk '{print $2}' | sed 's/://' | sed '1!d'`
- #
- echo "Configuring 1st wired NIC, (if any installed): ${BCyan}$WIRED_DEV${Reset}"
- echo "Configuring 1st wireless NIC, (if any installed): ${BYellow}$WIRELESS_DEV ${Reset}"
- echo
- echo " Wired Automatic is DHCP, Wired Manual is Static IPs,"
- echo
- Connection_Type_list=("Wired Automatic" "Wired Manual" "Wireless" "Configure Proxy" "Skip");
- PS3="${BYellow}Select network connection type planning to use: ${Reset}"
- select CONNECTIONTYP in "${Connection_Type_list[@]}"
- do
- case "$REPLY" in
- 1)
- echo
- echo "Starting Systemctl DHCP"
- systemctl start dhcpcd@${WIRED_DEV}.service
- break
- ;;
- 2)
- echo
- echo "Stopping Systemctl DHCP"
- systemctl stop dhcpcd@${WIRED_DEV}.service
- read -p "IP Address: " IP_ADDR
- read -p "Subnet Mask: " SUBNET_MSK
- read -p "Gateway: " GATEWAY
- echo "Setting up Network"
- ip link set ${WIRED_DEV} up # Puts network card up
- ip addr add ${IP_ADDR}/${SUBNET_MSK} dev ${WIRED_DEV} # Assigns IP address to NIC
- ip route add default via ${GATEWAY}
- echo
- echo "Editing the /etc/resolve.conf"
- echo
- sleep 4
- $EDITOR /etc/resolve.conf
- break
- ;;
- 3)
- ip link set ${WIRELESS_DEV} up
- wifi-menu ${WIRELESS_DEV}
- break
- ;;
- 4)
- read -p "Enter your proxy e.g. Protocol://address:port " OPTION
- export http_proxy=$OPTION
- export https_proxy=$OPTION
- export ftp_proxy=$OPTION
- echo "proxy = $OPTION" > ~/.curlrc
- break
- ;;
- 5)
- break
- ;;
- *)
- invaild_option
- ;;
- esac
- done
- echo "You may test it out using the pings in the main menu"
- pause_function
- }
- Config2NIC()
- {
- # 2nd Network Devices if more than 1 is installed
- WIRED_DEV=`ip link | grep enp | awk '{print $2}' | sed 's/://' | sed '2!d'`
- WIRELESS_DEV=`ip link | grep wlp | awk '{print $2}' | sed 's/://' | sed '2!d'`
- #
- echo "Configuring 2nd wired NIC, (if any installed): ${BCyan}$WIRED_DEV${Reset}"
- echo "Configuring 2nd wireless NIC, (if any installed): ${BYellow}$WIRELESS_DEV ${Reset}"
- echo
- echo " Wired Automatic is DHCP, Wired Manual is Static IPs,"
- echo
- Connection_Type_list=("Wired Automatic" "Wired Manual" "Wireless" "Configure Proxy" "Skip");
- PS3="${BYellow}Select network connection type planning to use: ${Reset}"
- select CONNECTIONTYP in "${Connection_Type_list[@]}"
- do
- case "$REPLY" in
- 1)
- echo
- echo "Starting Systemctl DHCP"
- echo "systemctl start dhcpcd@${WIRED_DEV}.service"
- break
- ;;
- 2)
- echo
- echo "Stopping Systemctl DHCP"
- echo "systemctl stop dhcpcd@${WIRED_DEV}.service"
- read -p "IP Address: " IP_ADDR
- read -p "Subnet Mask: " SUBNET_MSK
- read -p "Gateway: " GATEWAY
- echo "Setting up Network"
- ip link set ${WIRED_DEV} up # Puts network card up
- ip addr add ${IP_ADDR}/${SUBNET_MSK} dev ${WIRED_DEV} # Assigns IP address to NIC
- ip route add default via ${GATEWAY}
- echo
- echo "Editing the /etc/resolve.conf"
- echo
- sleep 4
- $EDITOR /etc/resolve.conf
- break
- ;;
- 3)
- ip link set ${WIRELESS_DEV} up
- wifi-menu ${WIRELESS_DEV}
- break
- ;;
- 4)
- read -p "Enter your proxy e.g. Protocol://address:port " OPTION
- export http_proxy=$OPTION
- export https_proxy=$OPTION
- export ftp_proxy=$OPTION
- echo "proxy = $OPTION" > ~/.curlrc
- break
- ;;
- 5)
- break
- ;;
- *)
- invaild_option
- ;;
- esac
- done
- echo "You may test it out using the pings in the main menu"
- pause_function
- }
- ################################### Select Netctl example files and copy it
- SelectNetctlex()
- {
- PS3="${BYellow}Select netctl example file to copy or Quit: ${Reset}"
- local netexfiles=(`ls $NETCTLEX | sed 's/\/.*$//' | uniq `);
- echo "Viewing netctl example files directory: ($NETCTLEX)"
- echo
- select NTCTLEXFILE in "${netexfiles[@]}" "Quit"
- do
- if [[ $NTCTLEXFILE == "Quit" ]]; then
- echo "Quit"
- return 1
- elif contains_element "$NTCTLEXFILE" "${netexfiles[@]}"
- then
- echo "Copying $NETCTLEX/$NTCTLEXFILE to $NETCTLDIR"
- cp -v $NETCTLEX/$NTCTLEXFILE $NETCTLDIR
- sleep 1
- break
- else
- invalid_option
- fi
- done
- EditExampleFile
- }
- #############################################################################
- Shell() {
- echo "You are entering the live filesystem's console"
- echo "Any changes made will only apply to the live"
- echo "filesystem. This may be useful for those who"
- echo "as to configure a network manually"
- echo
- echo "Usual Exit when finished."
- bash
- }
- ##################################################################################
- UseNetctlEx()
- {
- PS3="${BYellow}Select netctl file to use or Quit: ${Reset}"
- local netctlfiles=(`ls $NETCTLDIR | sed 's/\/.*$//' | uniq `);
- echo "Viewing copied files directory: ($NETCTLDIR)"
- echo
- echo -e "${BRed}examples, hooks and interfaces are directories${Reset}"
- echo
- select NETCTLFILE in "${netctlfiles[@]}" "Quit"
- do
- if [[ $NETCTLFILE == "Quit" ]]; then
- echo "Quit"
- return 1
- elif [[ $NETCTLFILE == "examples" ]]; then
- echo "That is a directory"
- sleep 2
- elif [[ $NETCTLFILE == "hooks" ]]; then
- echo "That is a directory"
- sleep 2
- elif [[ $NETCTLFILE == "interfaces" ]]; then
- echo "That is a directory"
- sleep 2
- elif contains_element "$NETCTLFILE" "${netctlfiles[@]}"
- then
- # EditExampleFile
- echo "starting ntctl $NETCTLDIR/$NETCTLFILE"
- netctl start $NETCTLDIR/$NETCTLFILE
- sleep 10
- break
- else
- invalid_option
- fi
- done
- }
- ##############################################################################
- EditExampleFile () # Allows editing of an Example file that was copied.
- {
- while :
- do
- print_confirmedit
- read ConfirmNYN
- case $ConfirmNYN in
- [Yy][Ee][Ss]|[Yy][Ee]|[Yy])
- echo "Editing $NETCTLDIR/$NTCTLEXFILE "
- sleep 1
- $EDITOR $NETCTLDIR/$NTCTLEXFILE
- break
- ;;
- [Nn][Oo]|[Nn])
- break # Returns to the Menu
- ;;
- *)
- invalid_option
- ;;
- esac
- done
- }
- ################################################################################
- EditMenu()
- {
- while :
- do
- print_title "**** Edit network files ****"
- echo "Not Quite Implented"
- echo
- echo
- echo "1. Edit /etc/hosts"
- echo "2. Edit /etc/resolv.conf"
- echo "3. Edit /etc/hostname"
- echo "4. Edit /etc/netconfig"
- print_line
- echo "Q. Quit"
- echo
- print_askopt
- read NWANS
- case $NWANS in
- 1)
- $EDITOR /etc/hosts
- ;;
- 2)
- $EDITOR /etc/resolv.conf
- ;;
- 3)
- $EDITOR /etc/hostname
- ;;
- 4)
- $EDITOR /etc/netconfig
- ;;
- Q|q)
- break
- ;;
- esac
- done
- }
- ##################################################################################
- MainNetworkMenu() {
- while :
- do
- print_title "*** Network Configuration ***"
- echo print_line
- echo
- print_askopt
- read NETOPTS
- case $NETOPTS in
- 1)
- echo "This will ping google.com 5 times and then pause"
- echo
- ping -c 5 www.google.com
- PINGEXIT=$?
- pause_function
- if [[ "$PINGEXIT" -ne 0 ]]
- then
- PINGSTATUS="${BRed}Failed${Reset}"
- NTASK1="${BRed}*${Reset}"
- else
- PINGSTATUS="${BGreen}Passed${Reset}"
- NTASK1="${BGreen}X${Reset}"
- fi
- ;;
- 2)
- echo
- echo "You can ping a router, another PC or Internet Server. "
- echo "If option 1 failed, this may be useful to test on"
- echo "on Static IPs"
- echo
- echo
- echo -en "${Bold}Type in the IP of a router or another PC to ping${Reset}: "
- read IP
- echo
- ping -c 5 $IP
- PINGSIPEXIT=$?
- pause_function
- if [[ "$PINGSIPEXIT" -ne 0 ]]
- then
- PINGSTATIP="${BRed}Failed${Reset}"
- NTASK2="${BRed}*${Reset}"
- else
- PINGSTATIP="${BGreen}Passed${Reset}"
- NTASK2="${BGreen}X${Reset}"
- fi
- ;;
- 3)
- Config1NIC
- ;;
- 4)
- Config2NIC
- ;;
- 5)
- SelectNetctlex
- ;;
- 6)
- while :
- do
- print_confirmedit "1st"
- read EDYN
- case $EDYN in
- Y|y|yes|YES)
- echo "Editing $NETCTLDIR/$NTCTLEXFILE "
- sleep 1
- $EDITOR $NETCTLDIR/$NTCTLEXFILE
- UseNetctlEx
- break
- ;;
- [Nn][Oo]|[Nn])
- UseNetctlEx
- break # Returns to the Menu
- ;;
- *)
- invalid_option
- ;;
- esac
- done
- ;;
- e|E)
- EditMenu
- ;;
- s|S)
- Shell
- ;;
- Q|q)
- return 1
- ;;
- *)
- invalid_option
- ;;
- esac
- done
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement