<commit_before>#!/bin/bash
# vim: tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
###############################################################################
# This is the Linux installation script for the King Phisher Client and
# Server on supported distributions.
#
# Project Home Page: https://github.com/securestate/king-phisher/
# Authors:
#   <NAME>
#   <NAME>
#
# Quick run command:
#   wget -q https://github.com/securestate/king-phisher/raw/master/tools/install.sh && sudo bash ./install.sh
#
# Supported Linux Distributions:
#   Linux Flavor    | Client | Server |
#   ----------------|--------|--------|
#   BackBox         | yes    | yes    |
#   CentOS          | no     | yes    |
#   Debian          | yes    | yes    |
#   Fedora          | yes    | yes    |
#   Kali            | yes    | yes    |
#   Red Hat         | no     | yes    |
#   Ubuntu          | yes    | yes    |
#   Arch            | yes    | yes    |
#
###############################################################################

E_USAGE=64
E_SOFTWARE=70
E_NOTROOT=87
FILE_NAME="$(dirname $(readlink -e $0) 2>/dev/null)/$(basename $0)"
GIT_CLONE_URL="https://github.com/securestate/king-phisher.git"
if [ -z "$KING_PHISHER_DIR" ]; then
	KING_PHISHER_DIR="/opt/king-phisher"
fi
KING_PHISHER_GROUP="king-phisher"
KING_PHISHER_USE_POSTGRESQL="no"
KING_PHISHER_WEB_ROOT="/var/www"
LINUX_VERSION=""
BACKUP=false
POSTGRES_BACKUP=""

answer_all_no=false
answer_all_yes=false

function prompt_yes_or_no {
	# prompt the user to answer a yes or no question, defaulting to yes if no
	# response is entered
	local __prompt_text=$1
	local __result_var=$2
	if [ "$answer_all_no" == "true" ]; then
		$__result_var="no";
		return 0;
	elif [ "$answer_all_yes" == "true" ]; then
		eval $__result_var="yes";
		return 0;
	fi
	while true; do
		read -p "$__prompt_text [Y/n] " _response
		case $_response in
			"" ) eval $__result_var="yes"; break;;
			[Yy]* ) eval $__result_var="yes"; break;;
			[Nn]* ) eval $__result_var="no";  break;;
			* ) echo "Please answer yes or no.";;
		esac
	done
	return 0;
}

function show_help {
	echo "Usage: $(basename $0) [-h] [-n/-y]"
	echo ""
	echo "King Phisher Install Script"
	echo ""
	echo "optional arguments"
	echo "  -h, --help            show this help message and exit"
	echo "  -u, --update          update an existing installation"
	echo "  -n, --no              answer no to all questions"
	echo "  -y, --yes             answer yes to all questions"
	echo "  --skip-client         skip installing client components"
	echo "  --skip-server         skip installing server components"
	return 0;
}

function select_nix_distro {
	read answer
	case $answer in
		1) LINUX_VERSION="Debian";;
		2) LINUX_VERSION="Ubuntu";;
		3) LINUX_VERSION="Kali";;
		4) LINUX_VERSION="Fedora";;
		5) LINUX_VERSION="Arch";;
		6) LINUX_VERSION="BackBox";;
		7) LINUX_VERSION="CentOS"
			KING_PHISHER_SKIP_CLIENT="x";;
		8) LINUX_VERSION="RedHat"
			KING_PHISHER_SKIP_CLIENT="x";;
		*) echo "ERROR: Invalid Linux selection, must be 1-8"
			exit 0;;
	esac
}

function sync_dependencies {
	echo "INFO: Synchronizing $LINUX_VERSION OS dependencies"
	if [ "$LINUX_VERSION" == "RedHat" ]; then
		if [ ! "$(command -v python3)" ]; then
			echo "INFO: Synchronizing Python3.5 for Red Hat 7"
			# manually add rpms for easy python35 install
			yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
			rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
			yum -y install https://rhel7.iuscommunity.org/ius-release.rpm
			rpm --import /etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY
			yum install -y python35u python35u-devel python35u-pip
			echo "INFO: Symlinking $(which python3.5) -> /usr/bin/python3"
			ln -s $(which python3.5) /usr/bin/python3
		fi
		yum install -y freetype-devel gcc gcc-c++ libpng-devel make \
			openssl-devel postgresql-devel
		if [ "$KING_PHISHER_USE_POSTGRESQL" == "yes" ]; then
			yum install -y postgresql-server
			# manually init the database
			postgresql-setup initdb
		fi
	fi
	if [ "$LINUX_VERSION" == "CentOS" ]; then
		if [ ! "$(command -v python3)" ]; then
			# manually install python3.5 on CentOS 7 and symlink it to python3
			echo "INFO: Synchronizing Python3.5 for CentOS 7"
			yum install -y https://centos7.iuscommunity.org/ius-release.rpm
			yum install -y python35u python35u-devel python35u-pip
			echo "INFO: Symlinking $(which python3.5) -> /usr/bin/python3"
			ln -s $(which python3.5) /usr/bin/python3
		fi
		yum install -y epel-release
		yum install -y freetype-devel gcc gcc-c++ libpng-devel make \
			openssl-devel postgresql-devel
		if [ "$KING_PHISHER_USE_POSTGRESQL" == "yes" ]; then
			yum install -y postgresql-server
			# manually init the database
			postgresql-setup initdb
		fi
	elif [ "$LINUX_VERSION" == "Fedora" ]; then
		dnf install -y freetype-devel gcc gcc-c++ gtk3-devel \
			libpng-devel postgresql-devel python3-devel python3-pip \
			libffi-devel openssl-devel
		if [ -z "$KING_PHISHER_SKIP_CLIENT" ]; then
			dnf install -y geos geos-devel gtksourceview3 gobject-introspection-devel
			# vte3 not available in Fedora29. Try to install it in case its an older versions.
			dnf install -y vte3<commit_msg>Update a simple install version comment<commit_after>#!/bin/bash
# vim: tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
###############################################################################
# This is the Linux installation script for the King Phisher Client and
# Server on supported distributions.
#
# Project Home Page: https://github.com/securestate/king-phisher/
# Authors:
#   <NAME>
#   <NAME>
#
# Quick run command:
#   wget -q https://github.com/securestate/king-phisher/raw/master/tools/install.sh && sudo bash ./install.sh
#
# Supported Linux Distributions:
#   Linux Flavor    | Client | Server |
#   ----------------|--------|--------|
#   BackBox         | yes    | yes    |
#   CentOS          | no     | yes    |
#   Debian          | yes    | yes    |
#   Fedora          | yes    | yes    |
#   Kali            | yes    | yes    |
#   Red Hat         | no     | yes    |
#   Ubuntu          | yes    | yes    |
#   Arch            | yes    | yes    |
#
###############################################################################

E_USAGE=64
E_SOFTWARE=70
E_NOTROOT=87
FILE_NAME="$(dirname $(readlink -e $0) 2>/dev/null)/$(basename $0)"
GIT_CLONE_URL="https://github.com/securestate/king-phisher.git"
if [ -z "$KING_PHISHER_DIR" ]; then
	KING_PHISHER_DIR="/opt/king-phisher"
fi
KING_PHISHER_GROUP="king-phisher"
KING_PHISHER_USE_POSTGRESQL="no"
KING_PHISHER_WEB_ROOT="/var/www"
LINUX_VERSION=""
BACKUP=false
POSTGRES_BACKUP=""

answer_all_no=false
answer_all_yes=false

function prompt_yes_or_no {
	# prompt the user to answer a yes or no question, defaulting to yes if no
	# response is entered
	local __prompt_text=$1
	local __result_var=$2
	if [ "$answer_all_no" == "true" ]; then
		$__result_var="no";
		return 0;
	elif [ "$answer_all_yes" == "true" ]; then
		eval $__result_var="yes";
		return 0;
	fi
	while true; do
		read -p "$__prompt_text [Y/n] " _response
		case $_response in
			"" ) eval $__result_var="yes"; break;;
			[Yy]* ) eval $__result_var="yes"; break;;
			[Nn]* ) eval $__result_var="no";  break;;
			* ) echo "Please answer yes or no.";;
		esac
	done
	return 0;
}

function show_help {
	echo "Usage: $(basename $0) [-h] [-n/-y]"
	echo ""
	echo "King Phisher Install Script"
	echo ""
	echo "optional arguments"
	echo "  -h, --help            show this help message and exit"
	echo "  -u, --update          update an existing installation"
	echo "  -n, --no              answer no to all questions"
	echo "  -y, --yes             answer yes to all questions"
	echo "  --skip-client         skip installing client components"
	echo "  --skip-server         skip installing server components"
	return 0;
}

function select_nix_distro {
	read answer
	case $answer in
		1) LINUX_VERSION="Debian";;
		2) LINUX_VERSION="Ubuntu";;
		3) LINUX_VERSION="Kali";;
		4) LINUX_VERSION="Fedora";;
		5) LINUX_VERSION="Arch";;
		6) LINUX_VERSION="BackBox";;
		7) LINUX_VERSION="CentOS"
			KING_PHISHER_SKIP_CLIENT="x";;
		8) LINUX_VERSION="RedHat"
			KING_PHISHER_SKIP_CLIENT="x";;
		*) echo "ERROR: Invalid Linux selection, must be 1-8"
			exit 0;;
	esac
}

function sync_dependencies {
	echo "INFO: Synchronizing $LINUX_VERSION OS dependencies"
	if [ "$LINUX_VERSION" == "RedHat" ]; then
		if [ ! "$(command -v python3)" ]; then
			echo "INFO: Synchronizing Python3.5 for Red Hat 7"
			# manually add rpms for easy python35 install
			yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
			rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
			yum -y install https://rhel7.iuscommunity.org/ius-release.rpm
			rpm --import /etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY
			yum install -y python35u python35u-devel python35u-pip
			echo "INFO: Symlinking $(which python3.5) -> /usr/bin/python3"
			ln -s $(which python3.5) /usr/bin/python3
		fi
		yum install -y freetype-devel gcc gcc-c++ libpng-devel make \
			openssl-devel postgresql-devel
		if [ "$KING_PHISHER_USE_POSTGRESQL" == "yes" ]; then
			yum install -y postgresql-server
			# manually init the database
			postgresql-setup initdb
		fi
	fi
	if [ "$LINUX_VERSION" == "CentOS" ]; then
		if [ ! "$(command -v python3)" ]; then
			# manually install python3.5 on CentOS 7 and symlink it to python3
			echo "INFO: Synchronizing Python3.5 for CentOS 7"
			yum install -y https://centos7.iuscommunity.org/ius-release.rpm
			yum install -y python35u python35u-devel python35u-pip
			echo "INFO: Symlinking $(which python3.5) -> /usr/bin/python3"
			ln -s $(which python3.5) /usr/bin/python3
		fi
		yum install -y epel-release
		yum install -y freetype-devel gcc gcc-c++ libpng-devel make \
			openssl-devel postgresql-devel
		if [ "$KING_PHISHER_USE_POSTGRESQL" == "yes" ]; then
			yum install -y postgresql-server
			# manually init the database
			postgresql-setup initdb
		fi
	elif [ "$LINUX_VERSION" == "Fedora" ]; then
		dnf install -y freetype-devel gcc gcc-c++ gtk3-devel \
			libpng-devel postgresql-devel python3-devel python3-pip \
			libffi-devel openssl-devel
		if [ -z "$KING_PHISHER_SKIP_CLIENT" ]; then
			dnf install -y geos geos-devel gtksourceview3 gobject-introspection-devel
			# vte3 is not available in Fedora 29, try to install it in case it's an older version.
			dnf install -y vte3
{'fraction_non_alphanumeric': 0.15670637970791698, 'fraction_numerical': 0.015372790161414296, 'mean_word_length': 3.161935225909636, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 12, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '573536', 'n_tokens_mistral': 4052, 'n_tokens_neox': 3645, 'n_words': 968}