Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Gluon SSID Changer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
firmware
Gluon SSID Changer
Commits
e2b04ae6
Commit
e2b04ae6
authored
7 years ago
by
rubo77
Browse files
Options
Downloads
Patches
Plain Diff
fixed indentins and all comments in single lines
parent
995190da
Branches
2017.1.x
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
files/lib/gluon/ssid-changer/ssid-changer.sh
+44
-36
44 additions, 36 deletions
files/lib/gluon/ssid-changer/ssid-changer.sh
with
44 additions
and
36 deletions
files/lib/gluon/ssid-changer/ssid-changer.sh
+
44
−
36
View file @
e2b04ae6
...
...
@@ -23,14 +23,19 @@ SETTINGS_SUFFIX="$(uci get ssid-changer.settings.suffix -q)"
if
[
$SETTINGS_SUFFIX
=
'nodename'
]
;
then
SUFFIX
=
"
$(
uname
-n
)
"
if
[
${#
SUFFIX
}
-gt
$((
30
-
${#
PREFIX
}))
]
;
then
# 32 would be possible as well
HALF
=
$((
(
28
-
${#
PREFIX
}
)
/
2
))
# calculate the length of the first part of the node identifier in the offline-ssid
SKIP
=
$((
${#
SUFFIX
}
-
$HALF
))
# jump to this charakter for the last part of the name
SUFFIX
=
${
SUFFIX
:0:
$HALF
}
...
${
SUFFIX
:
$SKIP
:
${#
SUFFIX
}}
# use the first and last part of the nodename for nodes with long name
# 32 would be possible as well
if
[
${#
SUFFIX
}
-gt
$((
30
-
${#
PREFIX
}))
]
;
then
# calculate the length of the first part of the node identifier in the offline-ssid
HALF
=
$((
(
28
-
${#
PREFIX
}
)
/
2
))
# jump to this charakter for the last part of the name
SKIP
=
$((
${#
SUFFIX
}
-
$HALF
))
# use the first and last part of the nodename for nodes with long name
SUFFIX
=
${
SUFFIX
:0:
$HALF
}
...
${
SUFFIX
:
$SKIP
:
${#
SUFFIX
}}
fi
elif
[
$SETTINGS_SUFFIX
=
'mac'
]
;
then
SUFFIX
=
"
$(
uci get network.bat0.macaddr
-q
)
"
else
# 'none'
else
# 'none'
SUFFIX
=
''
fi
...
...
@@ -39,52 +44,55 @@ OFFLINE_SSID="$PREFIX$SUFFIX"
# TODO: ffac tq limits has to be implemented here if enabled
ONLINE_SSID
=
"
$(
uci get wireless.client_radio0.ssid
-q
)
"
:
${
ONLINE_SSID
:
=
"FREIFUNK"
}
# if for whatever reason ONLINE_SSID is NULL
# if for whatever reason ONLINE_SSID is NULL
:
${
ONLINE_SSID
:
=
"FREIFUNK"
}
CHECK
=
"
$(
batctl gwl
-H
|grep
-v
"gateways in range"
|wc
-l
)
"
HUP_NEEDED
=
0
if
[
"
$CHECK
"
-gt
0
]
||
[
"
$DISABLED
"
=
'1'
]
;
then
echo
"node is online"
for
HOSTAPD
in
$(
ls
/var/run/hostapd-phy
*
)
;
do
# check status for all physical devices
CURRENT_SSID
=
"
$(
grep
"^ssid=
$ONLINE_SSID
"
$HOSTAPD
|
cut
-d
"="
-f2
)
"
if
[
"
$CURRENT_SSID
"
=
"
$ONLINE_SSID
"
]
then
echo
"SSID
$CURRENT_SSID
is correct, nothing to do"
break
fi
CURRENT_SSID
=
"
$(
grep
"^ssid=
$OFFLINE_SSID
"
$HOSTAPD
|
cut
-d
"="
-f2
)
"
if
[
"
$CURRENT_SSID
"
=
"
$OFFLINE_SSID
"
]
;
then
logger
-s
-t
"gluon-ssid-changer"
-p
5
"SSID is
$CURRENT_SSID
, change to
$ONLINE_SSID
"
sed
-i
"s~^ssid=
$CURRENT_SSID
~ssid=
$ONLINE_SSID
~"
$HOSTAPD
HUP_NEEDED
=
1
# HUP here would be to early for dualband devices
else
logger
-s
-t
"gluon-ssid-changer"
-p
5
"could not set to online state: did neither find SSID '
$ONLINE_SSID
' nor '
$OFFLINE_SSID
'. Please reboot"
fi
done
# check status for all physical devices
for
HOSTAPD
in
$(
ls
/var/run/hostapd-phy
*
)
;
do
CURRENT_SSID
=
"
$(
grep
"^ssid=
$ONLINE_SSID
"
$HOSTAPD
|
cut
-d
"="
-f2
)
"
if
[
"
$CURRENT_SSID
"
=
"
$ONLINE_SSID
"
]
;
then
echo
"SSID
$CURRENT_SSID
is correct, nothing to do"
break
fi
CURRENT_SSID
=
"
$(
grep
"^ssid=
$OFFLINE_SSID
"
$HOSTAPD
|
cut
-d
"="
-f2
)
"
if
[
"
$CURRENT_SSID
"
=
"
$OFFLINE_SSID
"
]
;
then
logger
-s
-t
"gluon-ssid-changer"
-p
5
"SSID is
$CURRENT_SSID
, change to
$ONLINE_SSID
"
sed
-i
"s~^ssid=
$CURRENT_SSID
~ssid=
$ONLINE_SSID
~"
$HOSTAPD
# HUP here would be to early for dualband devices
HUP_NEEDED
=
1
else
logger
-s
-t
"gluon-ssid-changer"
-p
5
"could not set to online state: did neither find SSID '
$ONLINE_SSID
' nor '
$OFFLINE_SSID
'. Please reboot"
fi
done
elif
[
"
$CHECK
"
-eq
0
]
;
then
echo
"node is considered offline"
UP
=
$(
cat
/proc/uptime |
sed
's/\..*//g'
)
if
[
$((
$UP
/
60
))
-lt
$FIRST
]
||
[
$((
$UP
/
60
%
$MINUTES
))
-eq
0
]
;
then
for
HOSTAPD
in
$(
ls
/var/run/hostapd-phy
*
)
;
do
CURRENT_SSID
=
"
$(
grep
"^ssid=
$OFFLINE_SSID
"
$HOSTAPD
|
cut
-d
"="
-f2
)
"
if
[
"
$CURRENT_SSID
"
=
"
$OFFLINE_SSID
"
]
;
then
echo
"SSID
$CURRENT_SSID
is correct, nothing to do"
break
fi
CURRENT_SSID
=
"
$(
grep
"^ssid=
$ONLINE_SSID
"
$HOSTAPD
|
cut
-d
"="
-f2
)
"
if
[
"
$CURRENT_SSID
"
=
"
$ONLINE_SSID
"
]
;
then
logger
-s
-t
"gluon-ssid-changer"
-p
5
"SSID is
$CURRENT_SSID
, change to
$OFFLINE_SSID
"
sed
-i
"s~^ssid=
$ONLINE_SSID
~ssid=
$OFFLINE_SSID
~"
$HOSTAPD
HUP_NEEDED
=
1
else
logger
-s
-t
"gluon-ssid-changer"
-p
5
"could not set to offline state: did neither find SSID '
$ONLINE_SSID
' nor '
$OFFLINE_SSID
'. Please reboot"
fi
CURRENT_SSID
=
"
$(
grep
"^ssid=
$OFFLINE_SSID
"
$HOSTAPD
|
cut
-d
"="
-f2
)
"
if
[
"
$CURRENT_SSID
"
=
"
$OFFLINE_SSID
"
]
;
then
echo
"SSID
$CURRENT_SSID
is correct, nothing to do"
break
fi
CURRENT_SSID
=
"
$(
grep
"^ssid=
$ONLINE_SSID
"
$HOSTAPD
|
cut
-d
"="
-f2
)
"
if
[
"
$CURRENT_SSID
"
=
"
$ONLINE_SSID
"
]
;
then
logger
-s
-t
"gluon-ssid-changer"
-p
5
"SSID is
$CURRENT_SSID
, change to
$OFFLINE_SSID
"
sed
-i
"s~^ssid=
$ONLINE_SSID
~ssid=
$OFFLINE_SSID
~"
$HOSTAPD
HUP_NEEDED
=
1
else
logger
-s
-t
"gluon-ssid-changer"
-p
5
"could not set to offline state: did neither find SSID '
$ONLINE_SSID
' nor '
$OFFLINE_SSID
'. Please reboot"
fi
done
fi
fi
if
[
$HUP_NEEDED
=
1
]
;
then
killall
-HUP
hostapd
# send HUP to all hostapd to load the new SSID
# send HUP to all hostapd to load the new SSID
killall
-HUP
hostapd
HUP_NEEDED
=
0
echo
"HUP!"
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment