make sshcmd, scpcmd, ssh_copy_id_cmd global to so-functions;

This commit is contained in:
m0duspwnens
2021-01-05 13:49:51 -05:00
parent c93dfa7b33
commit 0f9bf9deb6
2 changed files with 16 additions and 40 deletions

View File

@@ -110,10 +110,6 @@ analyze_system() {
} }
accept_salt_key_remote() { accept_salt_key_remote() {
local automated=$1
local sshcmd=get_ssh_cmd $automated
systemctl restart salt-minion systemctl restart salt-minion
echo "Accept the key remotely on the manager" >> "$setup_log" 2>&1 echo "Accept the key remotely on the manager" >> "$setup_log" 2>&1
@@ -558,9 +554,6 @@ check_requirements() {
} }
compare_versions() { compare_versions() {
local automated=$1
local sshcmd=get_ssh_cmd $automated
manager_ver=$("$sshcmd" -i /root/.ssh/so.key soremote@"$MSRV" cat /etc/soversion) manager_ver=$("$sshcmd" -i /root/.ssh/so.key soremote@"$MSRV" cat /etc/soversion)
if [[ $manager_ver == "" ]]; then if [[ $manager_ver == "" ]]; then
@@ -675,10 +668,6 @@ copy_salt_master_config() {
copy_minion_tmp_files() { copy_minion_tmp_files() {
local automated=$1
local sshcmd=get_ssh_cmd $automated
local scpcmd=get_scp_cmd $automated
case "$install_type" in case "$install_type" in
'MANAGER' | 'EVAL' | 'HELIXSENSOR' | 'MANAGERSEARCH' | 'STANDALONE' | 'IMPORT') 'MANAGER' | 'EVAL' | 'HELIXSENSOR' | 'MANAGERSEARCH' | 'STANDALONE' | 'IMPORT')
echo "Copying pillar and salt files in $temp_install_dir to $local_salt_dir" echo "Copying pillar and salt files in $temp_install_dir to $local_salt_dir"
@@ -706,9 +695,6 @@ copy_minion_tmp_files() {
copy_ssh_key() { copy_ssh_key() {
local automated=$1
local sshcopyidcmd=get_ssh_copy_id_cmd $automated
echo "Generating SSH key" echo "Generating SSH key"
# Generate SSH key # Generate SSH key
mkdir -p /root/.ssh mkdir -p /root/.ssh
@@ -985,9 +971,6 @@ docker_seed_registry() {
} }
download_repo_tarball() { download_repo_tarball() {
local automated=$1
local sshcmd=get_ssh_cmd $automated
local scpcmd=get_scp_cmd $automated
mkdir -p /root/manager_setup/securityonion mkdir -p /root/manager_setup/securityonion
{ {
@@ -1101,36 +1084,31 @@ get_scp_cmd() {
local automated=$1 local automated=$1
if [ $automated == yes ]; then if [ $automated == yes ]; then
local scpcmd='sshpass -p "automation" scp -o StrictHostKeyChecking=no' scpcmd='sshpass -p "automation" scp -o StrictHostKeyChecking=no'
else else
local scpcmd='scp' scpcmd='scp'
fi fi
echo $scpcmd
} }
get_ssh_cmd() { get_ssh_cmd() {
local automated=$1 local automated=$1
if [ $automated == yes ]; then if [ $automated == yes ]; then
local sshcmd='sshpass -p "automation" ssh -o StrictHostKeyChecking=no' sshcmd='sshpass -p "automation" ssh -o StrictHostKeyChecking=no'
else else
local sshcmd='ssh' sshcmd='ssh'
fi fi
echo $sshcmd
} }
get_ssh_copy_id_cmd() { get_ssh_copy_id_cmd() {
local automated=$1 local automated=$1
if [ $automated == yes ]; then if [ $automated == yes ]; then
local sshcopyidcmd='sshpass -p "automation" ssh-copy-id -o StrictHostKeyChecking=no' sshcopyidcmd='sshpass -p "automation" ssh-copy-id -o StrictHostKeyChecking=no'
else else
local sshcopyidcmd='ssh-copy-id' sshcopyidcmd='ssh-copy-id'
fi fi
echo $sshcopyidcmd
} }
host_pillar() { host_pillar() {
@@ -1680,9 +1658,6 @@ remove_package() {
# - securityonion/salt/salt/minion.defaults.yaml # - securityonion/salt/salt/minion.defaults.yaml
saltify() { saltify() {
local automated=$1
local scpcmd=get_scp_cmd $automated
# Install updates and Salt # Install updates and Salt
if [ $OS = 'centos' ]; then if [ $OS = 'centos' ]; then
set_progress_str 5 'Installing Salt repo' set_progress_str 5 'Installing Salt repo'
@@ -2108,8 +2083,6 @@ set_hostname() {
set_initial_firewall_policy() { set_initial_firewall_policy() {
set_main_ip set_main_ip
local automated=$1
local sshcmd=get_ssh_cmd $automated
if [ -f $default_salt_dir/pillar/data/addtotab.sh ]; then chmod +x $default_salt_dir/pillar/data/addtotab.sh; fi if [ -f $default_salt_dir/pillar/data/addtotab.sh ]; then chmod +x $default_salt_dir/pillar/data/addtotab.sh; fi
if [ -f $default_salt_dir/salt/common/tools/sbin/so-firewall ]; then chmod +x $default_salt_dir/salt/common/tools/sbin/so-firewall; fi if [ -f $default_salt_dir/salt/common/tools/sbin/so-firewall ]; then chmod +x $default_salt_dir/salt/common/tools/sbin/so-firewall; fi

View File

@@ -108,6 +108,9 @@ if [[ -f automation/$automation && $(basename $automation) == $automation ]]; th
echo "Preselecting variable values based on automated setup: $automation" >> $setup_log 2>&1 echo "Preselecting variable values based on automated setup: $automation" >> $setup_log 2>&1
source automation/$automation source automation/$automation
automated=yes automated=yes
get_scp_cmd $automated
get_ssh_cmd $automated
get_ssh_copy_id_cmd $automated
attempt=1 attempt=1
attempts=60 attempts=60
@@ -296,7 +299,7 @@ if ! [[ -f $install_opt_file ]]; then
fi fi
if [[ $is_minion ]]; then if [[ $is_minion ]]; then
copy_ssh_key $automated >> $setup_log 2>&1 copy_ssh_key >> $setup_log 2>&1
fi fi
if [[ $is_minion ]] && ! (compare_versions $automated); then if [[ $is_minion ]] && ! (compare_versions $automated); then
@@ -307,7 +310,7 @@ if ! [[ -f $install_opt_file ]]; then
"HOSTNAME=$HOSTNAME" \ "HOSTNAME=$HOSTNAME" \
"MSRV=$MSRV" \ "MSRV=$MSRV" \
"MSRVIP=$MSRVIP" > "$install_opt_file" "MSRVIP=$MSRVIP" > "$install_opt_file"
download_repo_tarball $automated download_repo_tarball
exec bash /root/manager_setup/securityonion/setup/so-setup "${original_args[@]}" exec bash /root/manager_setup/securityonion/setup/so-setup "${original_args[@]}"
fi fi
@@ -562,7 +565,7 @@ set_redirect >> $setup_log 2>&1
if [[ $is_minion ]]; then if [[ $is_minion ]]; then
set_progress_str 1 'Configuring firewall' set_progress_str 1 'Configuring firewall'
set_initial_firewall_policy $automated >> $setup_log 2>&1 set_initial_firewall_policy >> $setup_log 2>&1
fi fi
set_progress_str 2 'Updating packages' set_progress_str 2 'Updating packages'
@@ -582,7 +585,7 @@ set_redirect >> $setup_log 2>&1
fi fi
set_progress_str 5 'Installing Salt and dependencies' set_progress_str 5 'Installing Salt and dependencies'
saltify $automated 2>> $setup_log saltify 2>> $setup_log
set_progress_str 6 'Installing Docker and dependencies' set_progress_str 6 'Installing Docker and dependencies'
docker_install >> $setup_log 2>&1 docker_install >> $setup_log 2>&1
@@ -635,7 +638,7 @@ set_redirect >> $setup_log 2>&1
if [[ $is_minion ]]; then if [[ $is_minion ]]; then
set_progress_str 20 'Accepting Salt key on manager' set_progress_str 20 'Accepting Salt key on manager'
accept_salt_key_remote $automated >> $setup_log 2>&1 accept_salt_key_remote >> $setup_log 2>&1
fi fi
if [[ $is_manager || $is_import || $is_helix ]]; then if [[ $is_manager || $is_import || $is_helix ]]; then
@@ -644,7 +647,7 @@ set_redirect >> $setup_log 2>&1
fi fi
set_progress_str 21 'Copying minion pillars to manager' set_progress_str 21 'Copying minion pillars to manager'
copy_minion_tmp_files $automated >> $setup_log 2>&1 copy_minion_tmp_files >> $setup_log 2>&1
if [[ $is_minion ]]; then if [[ $is_minion ]]; then
set_progress_str 22 'Checking if the Salt Minion needs to be updated' set_progress_str 22 'Checking if the Salt Minion needs to be updated'
@@ -656,7 +659,7 @@ set_redirect >> $setup_log 2>&1
if [[ $is_manager || $is_helix || $is_import ]]; then if [[ $is_manager || $is_helix || $is_import ]]; then
set_progress_str 25 'Configuring firewall' set_progress_str 25 'Configuring firewall'
set_initial_firewall_policy $automated >> $setup_log 2>&1 set_initial_firewall_policy >> $setup_log 2>&1
# create these so the registry state can add so-registry to /opt/so/conf/so-status/so-status.conf # create these so the registry state can add so-registry to /opt/so/conf/so-status/so-status.conf
mkdir -p /opt/so/conf/so-status/ >> $setup_log 2>&1 mkdir -p /opt/so/conf/so-status/ >> $setup_log 2>&1