fix: fixed race condition (again) on override files

This commit is contained in:
Simone Margaritelli 2019-11-04 17:33:35 +01:00
parent 00e7c04980
commit e336fca0de
2 changed files with 34 additions and 1 deletions

View File

@ -4,7 +4,7 @@ source /usr/bin/pwnlib
# start mon0
start_monitor_interface
if is_auto_mode; then
if is_auto_mode_no_delete; then
/usr/bin/bettercap -no-colors -caplet pwnagotchi-auto -iface mon0
else
/usr/bin/bettercap -no-colors -caplet pwnagotchi-manual -iface mon0

View File

@ -32,6 +32,13 @@ is_interface_up() {
# returns 0 if conditions for AUTO mode are met
is_auto_mode() {
# check override file first
if [ -f /root/.pwnagotchi-manual ]; then
# remove the override file if found
rm -rf /root/.pwnagotchi-manual
return 1
fi
# check override file first
if [ -f /root/.pwnagotchi-auto ]; then
# remove the override file if found
@ -52,3 +59,29 @@ is_auto_mode() {
# no override, but none of the interfaces is up -> AUTO
return 0
}
# returns 0 if conditions for AUTO mode are met
is_auto_mode_no_delete() {
# check override file first
if [ -f /root/.pwnagotchi-manual ]; then
return 1
fi
# check override file first
if [ -f /root/.pwnagotchi-auto ]; then
return 0
fi
# if usb0 is up, we're in MANU
if is_interface_up usb0; then
return 1
fi
# if eth0 is up (for other boards), we're in MANU
if is_interface_up eth0; then
return 1
fi
# no override, but none of the interfaces is up -> AUTO
return 0
}