#! /bin/bash
# Depends: aircrack-ng, xterm|urxvt|gnome-terminal, awk, macchanger, grep, bash >= 4
# Recommends: mdk3, wlandecrypter, jazzteldecrypter

# Copyright (C) 2008 Daouid
# Copyright (C) 2009, 2010 David Francos Cuartero
# See Authors for a more detailed authors spec.
#        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 2
#        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, write to the Free Software
#        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

declare -a enabled_plugins
declare -a p_menu

_source(){
    for cfile in $@; do
        if [ -f $cfile ] && [ -O $cfile ]; then source $cfile; echo "${mark}Loading $cfile";
        else if [ "$debug" == 1 ]; then echo "Could not load $cfile"; sleep 0.2 ;fi; fi
    done
}

[[ ! $path ]] && {
    [[ -e /usr/share/airoscript-ng/ ]] && path=/usr/share/airoscript-ng || { 
        [[ -e /usr/local/share/airoscript-ng/ ]] && path=/usr/local/share/airoscript-ng 
    }
}

# We preload functions, configs and themes in a cool way.
_source "./airoscript-ng.conf.devel ~/.airoscript-ng/airoscript-ng.conf /etc/airoscript-ng.conf /usr/local/etc/airoscript-ng.conf"
_source "./airoscript-ng_advanced.conf.devel ~/.airoscript-ng_advanced/airoscript-ng_advanced.conf /etc/airoscript-ng_advanced.conf /usr/local/etc/airoscript-ng_advanced.conf"
_source "$path/_internal $path/menu $path/interface" 
_source  "$path/themes/$theme" || default_theme
_source ${enabled_plugins[@]};

# Setup wordlist
[[ ! -e $DUMP_PATH/wordlist.txt ]] && { cp $WORDLIST $DUMP_PATH &>/dev/null; WORDLIST="DUMP_PATH/`basename $WORDLIST`"; }

# For locale debugging
_debug "Text domain dir is $TEXTDOMAINDIR and textdomain is $TEXTDOMAIN"

# Whoah, this looks chaotic. I like it ^^
setaircrackpaths
rootwarn
setps

clear=""
[[ $show_startup_goodie ]] && { airoscript_ascii_art 2>/dev/null ; }
warn "${mark}Welcome to airoscript, have a nice day"
reso
check_cardctl; #debug
setargs $@
clear=clear;
cleanautovars

temporary_switch_clear
setinterface "start"
temporary_switch_clear

[[ "$noscan" != 1 ]] && autoscan
mainmenu
