From afe1e76690bca197d4108e2810d5308a58d465b5 Mon Sep 17 00:00:00 2001 From: Matias Barcenas Date: Mon, 21 Aug 2017 22:56:41 -0500 Subject: [PATCH] Completed implementation & integration of installer. The installer has been defined as a utility & is incorporated into fluxion. The installer is now responsible for checking & installing updates. The installer is now responsible for checking & installing dependencies. Package managers can now be defined within fluxion/lib/installer/managers. Dependencies are now flexible, and will attempt alternative installs. --- fluxion.sh | 13 ++++++--- lib/installer/InstallerUtils.sh | 47 +++++++++++++++++-------------- lib/installer/managers/apt-get.sh | 30 -------------------- lib/installer/managers/apt.sh | 33 ++++++++++++++++++++++ lib/installer/managers/emerge.sh | 4 ++- lib/installer/managers/pacman.sh | 4 ++- lib/installer/managers/yum.sh | 4 ++- lib/installer/managers/zypp.sh | 4 ++- 8 files changed, 80 insertions(+), 59 deletions(-) delete mode 100644 lib/installer/managers/apt-get.sh create mode 100644 lib/installer/managers/apt.sh diff --git a/fluxion.sh b/fluxion.sh index b6e079e..bd13a92 100755 --- a/fluxion.sh +++ b/fluxion.sh @@ -50,6 +50,8 @@ InstallerUtilsWorkspacePath="$FLUXIONWorkspacePath" InstallerUtilsOutputDevice="$FLUXIONOutputDevice" InstallerUtilsNoticeMark="$FLUXIONVLine" +PackageManagerLog="$InstallerUtilsWorkspacePath/package_manager.log" + IOUtilsHeader="fluxion_header" IOUtilsQueryMark="$FLUXIONVLine" IOUtilsPrompt="$FLUXIONPrompt" @@ -244,10 +246,13 @@ if [ ! $FLUXIONDebug ]; then then installer_utils_run_update "https://github.com/FluxionNetwork/fluxion/archive/master.zip" "FLUXION-V$FLUXIONVersion.$FLUXIONRevision" "`dirname "$FLUXIONPath"`" fi - FLUXIONCLIToolsRequired=("aircrack-ng" "awk" "curl" "dhcpd" "hostapd" "lighttpd" "iwconfig" "macchanger" "mdk3" "nmap" "openssl" "php-cgi" "pyrit" "xterm" "rfkill" "unzip" "net-tools" "fuser") - FLUXIONCLIToolsMissing=("software-properties-common" "") - while ! installer_utils_check_dependencies FLUXIONCLIToolsRequired[@] FLUXIONCLIToolsMissing[@] - do installer_utils_run_dependencies FLUXIONCLIToolsMissing[@] + echo + + FLUXIONCLIToolsRequired=("aircrack-ng" "awk:awk|gawk|mawk" "curl" "dhcpd:isc-dhcp-server" "hostapd" "lighttpd" "iwconfig:wireless-tools" "macchanger" "mdk3" "nmap" "openssl" "php-cgi" "pyrit" "xterm" "rfkill" "unzip" "route:net-tools" "fuser:psmisc" "killall:psmisc") + FLUXIONCLIToolsMissing=() + + while ! installer_utils_check_dependencies FLUXIONCLIToolsRequired[@] + do installer_utils_run_dependencies InstallerUtilsCheckDependencies[@] done fi diff --git a/lib/installer/InstallerUtils.sh b/lib/installer/InstallerUtils.sh index 5a0740c..ce74ab0 100644 --- a/lib/installer/InstallerUtils.sh +++ b/lib/installer/InstallerUtils.sh @@ -9,6 +9,8 @@ InstallerUtilsOutputDevice="/dev/stdout" InstallerUtilsNoticeMark="*" +PackageManagerLog="$InstallerUtilsWorkspacePath/package_manager.log" + function installer_utils_run_spinner() { local pid=$1 local delay=0.15 @@ -68,15 +70,17 @@ function installer_utils_check_update() { if [ -f "$InstallerUtilsWorkspacePath/latest_version" -a \ -s "$InstallerUtilsWorkspacePath/latest_version" ]; then - mapfile __installer_utils_check_update__vInfo < "$InstallerUtilsWorkspacePath/latest_version" + local __installer_utils_check_update__vInfo + mapfile -tn 2 __installer_utils_check_update__vInfo < "$InstallerUtilsWorkspacePath/latest_version" + + sandbox_remove_workfile "$InstallerUtilsWorkspacePath/latest_version" + __installer_utils_check_update__version=${__installer_utils_check_update__vInfo[0]} __installer_utils_check_update__revision=${__installer_utils_check_update__vInfo[1]} fi echo -e "$CClr [$__installer_utils_check_update__version.$__installer_utils_check_update__revision$CClr]" - echo - if [ "$__installer_utils_check_update__version" != "?" -a "$__installer_utils_check_update__revision" != "?" ]; then if [ "$__installer_utils_check_update__version" -gt "$__installer_utils_check_update__localVersion" -o \ "$__installer_utils_check_update__version" -eq "$__installer_utils_check_update__localRevision" -a \ @@ -159,36 +163,35 @@ function installer_utils_run_update() { # Parameters: $1 - CLI Tools required array $2 - CLI Tools missing array (will be populated) function installer_utils_check_dependencies() { - if [ ${#@} -ne 2 ]; then return 1; fi + if [ ! "$1" ]; then return 1; fi - local __installer_utils_run_dependencies__CLITools=("${!1}") - local __installer_utils_run_dependencies__CLIToolsMissing=("${!2}") + local __installer_utils_run_dependencies__CLIToolsInfo=("${!1}") + InstallerUtilsCheckDependencies=() - local __installer_utils_run_dependencies__CLITool - for __installer_utils_run_dependencies__CLITool in "${__installer_utils_run_dependencies__CLITools[@]}"; do + local __installer_utils_run_dependencies__CLIToolInfo + for __installer_utils_run_dependencies__CLIToolInfo in "${__installer_utils_run_dependencies__CLIToolsInfo[@]}"; do + local __installer_utils_run_dependencies__CLITool=${__installer_utils_run_dependencies__CLIToolInfo/:*/} local __installer_utils_run_dependencies__identifier="`printf "%-44s" "$__installer_utils_run_dependencies__CLITool"`" local __installer_utils_run_dependencies__state=".....$CGrn OK.$CClr" if ! hash "$__installer_utils_run_dependencies__CLITool" 2>/dev/null; then __installer_utils_run_dependencies__state="$CRed Missing!$CClr" - __installer_utils_run_dependencies__CLIToolsMissing+=("$__installer_utils_run_dependencies__CLITool") + InstallerUtilsCheckDependencies+=("$__installer_utils_run_dependencies__CLIToolInfo") fi format_center_literals "$InstallerUtilsNoticeMark ${__installer_utils_run_dependencies__identifier// /.}$__installer_utils_run_dependencies__state" echo -e "$FormatCenterLiterals" done - if [ ${#__installer_utils_run_dependencies__CLIToolsMissing[@]} -gt 0 ]; then return 2; fi + if [ ${#InstallerUtilsCheckDependencies[@]} -gt 0 ]; then return 2; fi } # Parameters: $1 - CLI Tools missing array (will be installed) $2 - substitutes array function installer_utils_run_dependencies() { - if [ "${#@}" -ne 2 ]; then return 1; fi + if [ ! "$1" ]; then return 1; fi # The array below holds all the packages that will be installed. - local __installer_utils_run_dependencies__packages=("${!1}") - # The array below holds packages and their substitution. - local __installer_utils_run_dependencies__substitutes=("${!2}") + local __installer_utils_run_dependencies__dependenciesInfo=("${!1}") local __installer_utils_run_dependencies__managers=(lib/installer/managers/*) @@ -206,13 +209,15 @@ function installer_utils_run_dependencies() { prep_package_manager - for __installer_utils_run_dependencies__package in "${__installer_utils_run_dependencies__packages[@]}"; do - clear - local __installer_utils_run_dependencies__target=$__installer_utils_run_dependencies__package - if [ "${__installer_utils_run_dependencies__substitutes[$__installer_utils_run_dependencies__package]}" - then __installer_utils_run_dependencies__target=${__installer_utils_run_dependencies__substitutes[$__installer_utils_run_dependencies__package]} - fi - $PackageManagerCLT $PackageManagerCLTInstallOptions $__installer_utils_run_dependencies__target + for __installer_utils_run_dependencies__dependencyInfo in "${__installer_utils_run_dependencies__dependenciesInfo[@]}"; do + local __installer_utils_run_dependencies__target=${__installer_utils_run_dependencies__dependencyInfo/:*/} + local __installer_utils_run_dependencies__packages=${__installer_utils_run_dependencies__dependencyInfo/*:/} + for __installer_utils_run_dependencies__package in ${__installer_utils_run_dependencies__packages//|/ }; do + clear + if $PackageManagerCLT $PackageManagerCLTInstallOptions $__installer_utils_run_dependencies__package + then break + fi + done done unprep_package_manager diff --git a/lib/installer/managers/apt-get.sh b/lib/installer/managers/apt-get.sh deleted file mode 100644 index 2c5ebda..0000000 --- a/lib/installer/managers/apt-get.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -if [ -f "/etc/debian_version" ] - PackageManagerCLT="apt-get" - PackageManagerCLTInstallOptions="install -y" - PackageManagerCLTRemoveOptions="remove -y" - - PackageManagerOutputDevice="/dev/stdout" - - function unprep_package_manager() { - echo "$(cat /etc/apt/sources.list | grep -v 'deb http://http.kali.org/kali kali-rolling main contrib non-free # Installed By FLUXION')" > /etc/apt/sources.list - } - - function prep_package_manager() { - if [ ! "`(cat /etc/apt/sources.list | grep 'deb http://http.kali.org/kali kali-rolling main contrib non-free'`" ]; then - gpg --keyserver hkp://keys.gnupg.net --recv-key 7D8D0BF6 - apt-key adv --keyserver pgp.mit.edu --recv-keys ED444FF07D8D0BF6 - echo "deb http://http.kali.org/kali kali-rolling main contrib non-free # Installed By FLUXION" >> /etc/apt/sources.list - fi - - # Cleanup package manager - sudo apt-get install -f -y | tee -a $PackageManagerOutputDevice - sudo apt-get autoremove -y | tee -a $PackageManagerOutputDevice - sudo apt-get autoclean -y | tee -a $PackageManagerOutputDevice - sudo apt-get clean -y | tee -a $PackageManagerOutputDevice - sudo apt-get update | tee -a $PackageManagerOutputDevice - } -fi - -# FLUXSCRIPT END diff --git a/lib/installer/managers/apt.sh b/lib/installer/managers/apt.sh new file mode 100644 index 0000000..bddd297 --- /dev/null +++ b/lib/installer/managers/apt.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +if [ -f "/etc/debian_version" ]; then + PackageManagerCLT="apt" + PackageManagerCLTInstallOptions="install -y" + PackageManagerCLTRemoveOptions="remove -y" + + PackageManagerOutputDevice="/dev/stdout" + + PackageManagerLog="/tmp/lib_package_manager.log" + + function unprep_package_manager() { + echo "`cat /etc/apt/sources.list | grep -v 'deb http://http.kali.org/kali kali-rolling main non-free contrib # Installed By FLUXION'`" > /etc/apt/sources.list + } + + function prep_package_manager() { + if [ ! "`cat /etc/apt/sources.list | egrep 'deb http://http.kali.org/kali ((kali-rolling|main|contrib|non-free) )*'`" ]; then + echo "Doesn't have kali..." + gpg --keyserver hkp://keys.gnupg.net --recv-key 7D8D0BF6 + apt-key adv --keyserver pgp.mit.edu --recv-keys ED444FF07D8D0BF6 + echo "deb http://http.kali.org/kali kali-rolling main non-free contrib # Installed By FLUXION" >> /etc/apt/sources.list + fi + + # Cleanup package manager + sudo apt-get install -f -y | tee -a $PackageManagerLog + sudo apt-get autoremove -y | tee -a $PackageManagerLog + sudo apt-get autoclean -y | tee -a $PackageManagerLog + sudo apt-get clean -y | tee -a $PackageManagerLog + sudo apt-get update | tee -a $PackageManagerLog + } +fi + +# FLUXSCRIPT END diff --git a/lib/installer/managers/emerge.sh b/lib/installer/managers/emerge.sh index 59533df..22ada1b 100644 --- a/lib/installer/managers/emerge.sh +++ b/lib/installer/managers/emerge.sh @@ -1,12 +1,14 @@ #!/bin/bash -if [ -f "/etc/gentoo-release" ] +if [ -f "/etc/gentoo-release" ]; then PackageManagerCLT="emerge" PackageManagerCLTInstallOptions="-s" PackageManagerCLTRemoveOptions="" PackageManagerOutputDevice="/dev/stdout" + PackageManagerLog="/tmp/lib_package_manager.log" + function unprep_package_manager() { echo "Nothing to unprepare." > $PackageManagerOutputDevice } diff --git a/lib/installer/managers/pacman.sh b/lib/installer/managers/pacman.sh index 4465535..ea176e3 100644 --- a/lib/installer/managers/pacman.sh +++ b/lib/installer/managers/pacman.sh @@ -1,12 +1,14 @@ #!/bin/bash -if [ -f "/etc/arch-release" ] +if [ -f "/etc/arch-release" ]; then PackageManagerCLT="pacman" PackageManagerCLTInstallOptions="-S -y" PackageManagerCLTRemoveOptions="-Rs" PackageManagerOutputDevice="/dev/stdout" + PackageManagerLog="/tmp/lib_package_manager.log" + function unprep_package_manager() { echo "Nothing to unprepare." > $PackageManagerOutputDevice } diff --git a/lib/installer/managers/yum.sh b/lib/installer/managers/yum.sh index 46a1f7b..2343611 100644 --- a/lib/installer/managers/yum.sh +++ b/lib/installer/managers/yum.sh @@ -1,12 +1,14 @@ #!/bin/bash -if [ -f "/etc/redhat-release" ] +if [ -f "/etc/redhat-release" ]; then PackageManagerCLT="yum" PackageManagerCLTInstallOptions="-y install" PackageManagerCLTRemoveOptions="remove" PackageManagerOutputDevice="/dev/stdout" + PackageManagerLog="/tmp/lib_package_manager.log" + function unprep_package_manager() { echo "Nothing to unprepare." > $PackageManagerOutputDevice } diff --git a/lib/installer/managers/zypp.sh b/lib/installer/managers/zypp.sh index 2d26121..25f9db2 100644 --- a/lib/installer/managers/zypp.sh +++ b/lib/installer/managers/zypp.sh @@ -1,12 +1,14 @@ #!/bin/bash -if [ -f "/etc/SuSE-release" ] +if [ -f "/etc/SuSE-release" ]; then PackageManagerCLT="zypp" PackageManagerCLTInstallOptions="install" PackageManagerCLTRemoveOptions="remove" PackageManagerOutputDevice="/dev/stdout" + PackageManagerLog="/tmp/lib_package_manager.log" + function unprep_package_manager() { echo "Nothing to unprepare." > $PackageManagerOutputDevice }