Submitted scripts and programs
Forum rules
Your own work only.
-
machinebacon
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
-
Contact:
Unread post
by machinebacon » Fri Apr 18, 2014 4:35 pm
Problem: you have a netbook or laptop and need to switch network profiles (for example, wifi at home and at work/school) and you are a lazy ass who does not want to enter the passwords all the fucking time.
Solution: netpro - it lets you save and switch profiles. All interface profiles are saved in /etc/network/ and not readable as normal user.
Code: Select all
#!/bin/bash
ROOT_UID=0
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "You must be root to run this script."
exit 87
fi
saveprofile()
{
echo "Enter name for profile: "
read proname
echo
echo "Saved as /etc/network/net.$proname"
cp /etc/network/interfaces /etc/network/net.$proname
}
loadprofile()
{
ls /etc/network/net.*
echo "Enter net. profile to load without prefix: "
read proname
echo
cp /etc/network/interfaces /etc/network/interfaces.backup
echo "Current profile saved as /etc/network/interfaces.backup"
cp /etc/network/net.$proname /etc/network/interfaces
# The next lines are optional, they automatically restart the active interface.
# snip ------------------------------------
iface=$(cat /etc/network/interfaces |grep iface|cut -d" " -f2|sed 's/lo//g')
echo "$proname loaded! Restarting $iface"
ifdown $iface
ifup $iface
# ------------------------------------ snap
}
editprofile()
{
nano /etc/network/interfaces
}
echo "[s]ave current network profile as ..."
echo "[l]oad profile from list"
echo "[e]dit current interfaces file"
echo "[q]uit"
read -n1 -s sel
if [ $sel = 's' ]; then
saveprofile
elif [ $sel = 'l' ]; then
loadprofile
elif [ $sel = 'q' ]; then
exit 0
elif [ $sel = 'e' ]; then
editprofile
fi
for the even more lazy+
..gnutella..
-
machinebacon
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
-
Contact:
Unread post
by machinebacon » Fri Apr 18, 2014 4:36 pm
Oh right, please test if it works for you. Thanks ;)
..gnutella..
-
rust collector
- Motörhead
- Posts: 536
- Joined: Mon Jan 13, 2014 3:56 pm
- Location: no_nb
Unread post
by rust collector » Fri Apr 18, 2014 5:26 pm
This is not much of a test, but at least it shows the correct stuff for the network I am on.
I don't have any other networks to connect to, at the moment.
-
GekkoP
- Emacs Sancho Panza
- Posts: 5878
- Joined: Tue Sep 03, 2013 7:05 am
Unread post
by GekkoP » Fri Apr 18, 2014 6:18 pm
Nice, very nice.
-
wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
-
Contact:
Unread post
by wuxmedia » Sat Apr 19, 2014 7:00 pm
Very handy indeed!
Will test, this is what I spend a lot of time doing, go to work - change wifi, go home, change wifi... go home, home- change wifi.
-
wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
-
Contact:
Unread post
by wuxmedia » Wed Apr 30, 2014 9:00 pm
I forgot... to post that this works *perfectly*, hot swapping from work, to home, my flat, on the road.
For convenience I've, aliased the 'sudo' line and put into the sudoers file there's no password needed.
even works for my phone hotspot function, excellent work.
-
machinebacon
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
-
Contact:
Unread post
by machinebacon » Wed May 21, 2014 8:36 am
That's great to know, thanks wux. I tried it on two PCs with 3 different locations and it does work for me, too.
..gnutella..
-
wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
-
Contact:
Unread post
by wuxmedia » Wed May 21, 2014 10:38 am
It currently holds:
work, home, home2, home3, on-call flat, and the phone.
The sudoers trick makes it nice and quick.
Now, if one could pass it the saved name as an argument, that would be ultra sweet (and I suppose even xkeybound?) 8)
not related to your script, but I though ceni was supposed to support this 'roaming' - I never got it to work, surprise... 8)
-
machinebacon
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
-
Contact:
Unread post
by machinebacon » Wed May 21, 2014 1:29 pm
oh that would be nice indeed. I look into it...
..gnutella..
-
wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
-
Contact:
Unread post
by wuxmedia » Wed Dec 10, 2014 3:28 pm
Code: Select all
#!/bin/bash
# ripped off from bacon linuxbbq.org
# Rainbow edition 8)
ROOT_UID=0
if [ "$UID" -ne "$ROOT_UID" ]
then
echo -e "\E[31mYou must be root to run this script.\033[0m"
exit 87
fi
saveprofile()
{
echo -e "\E[35mEnter name for profile:\033[0m "
read proname
echo
echo -e "\E[32mSaved as /etc/network/net.$proname\033[0m"
cp /etc/network/interfaces /etc/network/net.$proname
}
loadprofile()
{
#echo "killing wlan0, for some reason or other"
#ifdown wlan0 > /dev/null 2>&1 && ifdown wlan0 > /dev/null 2>&1
clear
ls -1 /etc/network/net.* | cut -d . -f2
echo -e "\E[33mEnter net. profile to load:\033[0m "
read proname
echo
#echo "nameserver 8.8.8.8" >> /etc/resolv.conf
cp /etc/network/interfaces /etc/network/interfaces.backup
echo -e "\E[35mCurrent profile saved as /etc/network/interfaces.backup\033[0m"
cp /etc/network/net.$proname /etc/network/interfaces
# The next lines are optional, they automatically restart the active interface.
# snip ------------------------------------
iface=$(cat /etc/network/interfaces |grep iface|cut -d" " -f2|sed 's/lo//g')
echo -e "\E[32m$proname loaded!\033[0m \E[33mRestarting:\033[0m \E[34m$iface\033[0m"
ifdown $iface > /dev/null 2>&1
echo -e "\E[33mWorking...\033[0m"
ifup $iface > /dev/null 2>&1
echo -e "\E[32mDone!\033[0m"
# ------------------------------------ snap
}
editprofile()
{
nano /etc/network/interfaces
}
clear
echo -e "\E[36;40mType a key to choose your option:\033[0m"
echo -e "\E[34m[r]un CENI to config network\033[0m"
echo -e "\E[32m[s]ave current network profile as ...\033[0m"
echo -e "\E[33m[l]oad profile from list\033[0m"
echo -e "\E[35m[e]dit current interfaces file\033[0m"
echo -e "\E[31m[q]uit\033[0m"
read -n1 -s sel
if [ $sel = 's' ]; then
saveprofile
elif [ $sel = 'l' ]; then
loadprofile
elif [ $sel = 'q' ]; then
exit 0
elif [ $sel = 'e' ]; then
editprofile
elif [ $sel = 'r' ]; then
ceni
fi
All my own work *zazehem* - hmm might look into getting it to read the conf as an argument, now I more or less understand the layout.
-
machinebacon
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
-
Contact:
Unread post
by machinebacon » Wed Dec 10, 2014 4:47 pm
completely forgot about this one... I'll do something that reads the conf without looking at your version, and then we compare penis length :D
..gnutella..
-
wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
-
Contact:
Unread post
by wuxmedia » Wed Dec 10, 2014 7:01 pm
Heh, not a problem, works perfectly well right now, I was bored and decided to rainbow it clean the presets and just /dev/null the output, just ricing :)
-
wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
-
Contact:
Unread post
by wuxmedia » Tue Apr 21, 2015 7:20 am
more boredness:
Code: Select all
#!/bin/bash
# ripped off from bacon linuxbbq.org
# Rainbow edition 8)
# Pass config arg direct?
proname=("$@")
ROOT_UID=0
if [ "$UID" -ne "$ROOT_UID" ]
then
echo -e "\E[31mYou must be root to run this script.\033[0m"
exit 87
fi
saveprofile()
{
echo -e "\E[35mEnter name for profile:\033[0m "
read proname
echo
echo -e "\E[32mSaved as /etc/network/net.$proname\033[0m"
cp /etc/network/interfaces /etc/network/net.$proname
}
loadprofile()
{
#echo "killing wlan0, for some reason or other"
#ifdown wlan0 > /dev/null 2>&1 && ifdown wlan0 > /dev/null 2>&1
clear
ls -1 /etc/network/net.* | cut -d . -f2
echo -e "\E[33mEnter net. profile to load:\033[0m "
read proname
echo
cp /etc/network/interfaces /etc/network/interfaces.backup
echo -e "\E[35mCurrent profile saved as /etc/network/interfaces.backup\033[0m"
cp /etc/network/net.$proname /etc/network/interfaces
# The next lines are optional, they automatically restart the active interface.
# snip ------------------------------------
iface=$(cat /etc/network/interfaces |grep iface|cut -d" " -f2|sed 's/lo//g')
echo -e "\E[32m$proname loaded!\033[0m \E[33mRestarting:\033[0m \E[34m$iface\033[0m"
ifdown $iface > /dev/null 2>&1
echo -e "\E[33mWorking...\033[0m"
ifup $iface > /dev/null 2>&1
ping -c2 google.com > /dev/null
if [ $? -eq 0 ]
then
echo -e "\E[32mAll Done!\033[0m"
else
echo -e "\E[31mFailed :(\033[0m"
fi
# ------------------------------------ snap
}
editprofile()
{
nano /etc/network/interfaces
}
if [ -z ${proname+x} ]; then
clear
echo -e "\E[36;40mType a key to choose your option:\033[0m"
echo -e "\E[34m[r]un CENI to config network\033[0m"
echo -e "\E[32m[s]ave current network profile as ...\033[0m"
echo -e "\E[33m[l]oad profile from list\033[0m"
echo -e "\E[35m[e]dit current interfaces file\033[0m"
echo -e "\E[31m[q]uit\033[0m"
read -n1 -s sel
if [ $sel = 's' ]; then
saveprofile
elif [ $sel = 'l' ]; then
loadprofile
elif [ $sel = 'q' ]; then
exit 0
elif [ $sel = 'e' ]; then
editprofile
elif [ $sel = 'r' ]; then
ceni
fi
else
cp /etc/network/interfaces /etc/network/interfaces.backup
echo -e "\E[35mCurrent profile saved as /etc/network/interfaces.backup\033[0m"
cp /etc/network/net.$proname /etc/network/interfaces
# The next lines are optional, they automatically restart the active interface.
# snip ------------------------------------
iface=$(cat /etc/network/interfaces |grep iface|cut -d" " -f2|sed 's/lo//g')
echo -e "\E[32m$proname loaded!\033[0m \E[33mRestarting:\033[0m \E[34m$iface\033[0m"
ifdown $iface > /dev/null 2>&1
echo -e "\E[33mWorking...\033[0m"
ifup $iface > /dev/null 2>&1
ping -c2 google.com > /dev/null
if [ $? -eq 0 ]
then
echo -e "\E[32mAll Done!\033[0m"
else
echo -e "\E[31mFailed :(\033[0m"
fi
fi
It's dirty and nasty and doesn't reuse code, doesn't check to see if your $filename exists, however although a bit messy looking because bacon coded the original so robustly, it doesn't matter; just loads the backup or something :)
So anyway now it accepts command line config:
-
machinebacon
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
-
Contact:
Unread post
by machinebacon » Tue Apr 21, 2015 9:22 am
Oh nice, thanks, it does what it should do!
..gnutella..
-
wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
-
Contact:
Unread post
by wuxmedia » Tue Apr 21, 2015 10:29 am
well you are welcome :) I just bolted on a variable and reused your code.
I only move around a few places, so makes sense to pass an argument.
Was thinking of bloating it to grep the wifi SSID's available on 'resuming' then pass that to connect. then a fancy icon, then a signal strength... ten... I stopped myself :)
-
machinebacon
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
-
Contact:
Unread post
by machinebacon » Tue Apr 21, 2015 12:53 pm
Well, there are some points to improve or change or worsen, as long as it does what its user wants it to do, it's OK :D and yes, we could have an icon/applet for it - provided we want to have GTK2 dependencies. :) Nice little exercise.
..gnutella..
-
wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
-
Contact:
Unread post
by wuxmedia » Sat Jul 18, 2020 11:20 am
I would like to get this roam, I think that would be nice. not 100% sure how though
-
catfood
- Bad Advice Dog
- Posts: 146
- Joined: Tue Oct 04, 2016 1:25 am
- Location: F google
-
Contact:
Unread post
by catfood » Mon Aug 10, 2020 12:08 am
wuxmedia wrote: ↑Wed Dec 10, 2014 7:01 pm
Heh, not a problem, works perfectly well right now, I was bored and decided to rainbow it clean the presets and just /dev/null the output, just ricing :)
I appreciate your rainbow terminal ricing, and also
Code: Select all
"# ripped off from bacon linuxbbq.org"
Any script I do finally get working is gonna have to say
#Bloated by leet haxxor
#Stolen from Pidsley, Machinebacon, and or both
#Even less warranty than original!
Thank You!
(I remember when debian "non-gui" installer scared me. #never-forget)