From 415dd2b50e3bd4beb4cb13a94d20536c9cb002a8 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Wed, 9 Sep 2020 02:38:32 -0500 Subject: [PATCH 01/53] fix non pi user home-dir mass import --- installer/consolepi-image-creator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/consolepi-image-creator.sh b/installer/consolepi-image-creator.sh index cee19ac9..9b6174a0 100755 --- a/installer/consolepi-image-creator.sh +++ b/installer/consolepi-image-creator.sh @@ -315,7 +315,7 @@ do_import_configs() { elif [[ ! $f =~ "/home/pi" ]] && [[ $f =~ $MY_HOME ]]; then src="$f" # dst is in the stage dir for non pi/root users. After user creation installer will look for files in the stage dir - dst="${IMG_STAGE}${MY_HOME}" + dst="${IMG_STAGE}${f}" else src="$f" dst="/mnt/usb2${f}" From 268bc04952fb8b298bf00278a56bf48b41d73fcc Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Wed, 9 Sep 2020 22:41:52 -0500 Subject: [PATCH 02/53] disable ipv6 in dhcpcd.conf when ipv6 disabled in kernel fix missing -e - echo Predictable Console Port msg --- installer/update.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/installer/update.sh b/installer/update.sh index 1b1f3f55..ffb81120 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -557,7 +557,8 @@ gen_dnsmasq_conf () { gen_dhcpcd_conf () { process="dhcpcd.conf" logit "configure dhcp client and static fallback" - convert_template dhcpcd.conf /etc/dhcpcd.conf wlan_ip=${wlan_ip} wired_ip=${wired_ip} wired_dhcp=${wired_dhcp} + [ -f /etc/sysctl.d/99-noipv6.conf ] && noipv6=true || noipv6=false + convert_template dhcpcd.conf /etc/dhcpcd.conf wlan_ip=${wlan_ip} wired_ip=${wired_ip} wired_dhcp=${wired_dhcp} noipv6=${noipv6} unset process } @@ -801,7 +802,7 @@ get_serial_udev() { echo "- ttyUSB# or ttyACM# where the # starts with 0 and increments for each adapter of that type plugged in. The names -" echo "- won't necessarily be consistent between reboots nor will the TELNET port. This method is OK for temporary use -" echo -e "- of an adapter or if you only plan to use a single adapter. Otherwise setting predictable aliases is -" - echo "- ${_lred}highly recommended${_norm}. -" + echo -e "- ${_lred}highly recommended${_norm}. -" echo "- -" echo "- Defining the ports with this utility is also how device specific serial settings are configured. Otherwise -" echo "- they will use the default which is 9600 8N1 -" From 32109b489cee9a878d156144004ecc5ce59201ea Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Wed, 9 Sep 2020 22:42:32 -0500 Subject: [PATCH 03/53] update missing process updates (logging msg) --- installer/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/installer/install.sh b/installer/install.sh index 92b9e0f0..bc9d1495 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -191,6 +191,7 @@ pre_git_prep() { # Create additional Users (with appropriate rights for ConsolePi) + process="Add Users" if ! $silent; then sed -i "s/^EXTRA_GROUPS=.*/EXTRA_GROUPS=\"$extra_groups2\"/" /tmp/adduser.conf _res=true; while $_res; do @@ -221,6 +222,7 @@ pre_git_prep() { fi # if pi user exists ensure it has correct group memberships for ConsolePi + process="Verify pi user groups" if grep -q "^pi:" /etc/passwd; then _groups=('consolepi' 'dialout') for grp in "${_groups[@]}"; do From 31ebcdfa4a2c8b9054ee0b7adcd4219be42b800d Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Wed, 9 Sep 2020 22:42:51 -0500 Subject: [PATCH 04/53] Add conditional for noipv6 --- src/j2/dhcpcd.conf.j2 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/j2/dhcpcd.conf.j2 b/src/j2/dhcpcd.conf.j2 index dd094d83..27a74798 100644 --- a/src/j2/dhcpcd.conf.j2 +++ b/src/j2/dhcpcd.conf.j2 @@ -46,6 +46,12 @@ slaac private # Disable RFC3927 ipv4LL (169.) automatic addressing on dhcp failure noipv4ll +{% if noipv6 %} +# Disable IPv6 +noipv6rs +noipv6 +{% endif %} + # ConsolePi vendorclassid vendorclassid dhcpcd-ConsolePi From 50ae141ab1aebfb2d2a9ca37d78903c95951aca7 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Wed, 9 Sep 2020 23:58:06 -0500 Subject: [PATCH 05/53] get_serial_udev() now uses menu_print() fix cmd && good || bad sequence in misc_stuff() --- installer/update.sh | 54 ++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/installer/update.sh b/installer/update.sh index ffb81120..17e16bb4 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -768,8 +768,9 @@ misc_stuff() { if $hotspot && [ ${wlan_country^^} == "US" ]; then process="Set Keyboard Layout" logit "${process} - Starting" - sudo sed -i "s/gb/${wlan_country,,}/g" /etc/default/keyboard && logit "KeyBoard Layout changed to ${wlan_country,,}" - logit "${process} - Success" || logit "${process} - Failed ~ verify contents of /etc/default/keyboard" "WARNING" + sudo sed -i "s/gb/${wlan_country,,}/g" /etc/default/keyboard && + logit "Success - KeyBoard Layout changed to ${wlan_country,,}" || + logit "${process} - Failed ~ verify contents of /etc/default/keyboard" "WARNING" unset process fi @@ -792,29 +793,32 @@ get_serial_udev() { logit "${process} Starting" header + declare -a _msg=( + -L 116 -c '-' -head "${_green}Predictable Console ports${_norm}" + -nl + "Predictable Console ports allow you to configure ConsolePi so that each time you plug-in a specific adapter it" + "will have the same name in consolepi-menu and will be reachable via the same TELNET port." + -nl + "The behavior if you do ${_lred}not${_norm} define Predictable Console Ports is the adapters will use the root device names" + "ttyUSB# or ttyACM# where the # starts with 0 and increments for each adapter of that type plugged in. The names" + "won't necessarily be consistent between reboots nor will the TELNET port. This method is OK for temporary use" + "of an adapter or if you only plan to use a single adapter. Otherwise setting predictable aliases is" + "${_lred}highly recommended${_norm}." + -nl + "Defining the ports with this utility is also how device specific serial settings are configured. Otherwise" + "they will use the default (9600 8N1)." + -nl + -nl + "This function can be called anytime from the shell via ${_cyan}consolepi-addconsole${_norm} and is available from" + "${_cyan}consolepi-menu${_norm} via the 'rn' (rename) option." + -nl + -foot + ) + menu_print "${_msg[@]}" echo - echo -e "--------------------------------------------- ${_green}Predictable Console ports${_norm} ---------------------------------------------" - echo "- -" - echo "- Predictable Console ports allow you to configure ConsolePi so that each time you plug-in a specific adapter it -" - echo "- will have the same name in consolepi-menu and will be reachable via the same TELNET port. -" - echo "- -" - echo "- The behavior if you do *not* define Predictable Console Ports is the adapters will use the root device names -" - echo "- ttyUSB# or ttyACM# where the # starts with 0 and increments for each adapter of that type plugged in. The names -" - echo "- won't necessarily be consistent between reboots nor will the TELNET port. This method is OK for temporary use -" - echo -e "- of an adapter or if you only plan to use a single adapter. Otherwise setting predictable aliases is -" - echo -e "- ${_lred}highly recommended${_norm}. -" - echo "- -" - echo "- Defining the ports with this utility is also how device specific serial settings are configured. Otherwise -" - echo "- they will use the default which is 9600 8N1 -" - echo "- -" - echo "- -" - echo -e "- This function can be called anytime from the shell via ${_cyan}consolepi-addconsole${_norm} and is available from -" - echo -e "- ${_cyan}consolepi-menu${_norm} via the 'rn' (rename) option. -" - echo "- -" - echo "---------------------------------------------------------------------------------------------------------------------" - echo - echo "You need to have the serial adapters you want to map to specific telnet ports available" - prompt="Would you like to configure predictable serial ports now" + + echo "You need to have the serial adapters available" + prompt="Would you like to configure predictable serial port aliases now" $upgrade && user_input false "${prompt}" || user_input true "${prompt}" if $result ; then if [ -f ${consolepi_dir}src/consolepi-commands/consolepi-menu ]; then @@ -880,7 +884,7 @@ custom_post_install_script() { post_install_msg() { clear;echo declare -a _msg=( - -head "Installation Complete" + -head "${_green}Installation Complete${_norm}" "${_bold}Next Steps/Info${_norm}" -nl " ${_bold}Cloud Sync:${_norm}" From 686a6b9651d573e409d00b92baa657ee83cc558d Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Wed, 9 Sep 2020 23:58:45 -0500 Subject: [PATCH 06/53] enahance menu_print() logit now displays error detail on fatal exit --- installer/common.sh | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/installer/common.sh b/installer/common.sh index 34cebec3..68b52f1e 100755 --- a/installer/common.sh +++ b/installer/common.sh @@ -111,29 +111,35 @@ menu_print() { line_len=${line_len:=121} while (( "$#" )); do case "$1" in + -c) + style="$(echo $2 | cut -d'=' -f2)" + shift 2 + ;; -L|-len) line_len=$2 shift 2 ;; -head) + style=${style:-'*'} str=" $2 " len=${#str} - # ((line_len+=1)) #actual line_len ends up aw line_len +1 not sure why + [[ "$str" =~ "\e[" ]] && ((len-=11)) + [[ "$str" =~ ';1m' ]] && ((len-=2)) left=$(( ((line_len-len))/2 )) [[ $((left+len+left)) -eq $line_len ]] && right=$left || right=$((left+1)) - printf -v pad_left "%*s" $left && pad_left=${pad_left// /*} - printf -v pad_right "%*s" $right && pad_right=${pad_right// /*} - printf "%s%s%s\n" "$pad_left" "$str" "$pad_right" + printf -v pad_left "%*s" $left && pad_left=${pad_left// /$style} + printf -v pad_right "%*s" $right && pad_right=${pad_right// /$style} + printf "%s%b%s\n" "$pad_left" "$str" "$pad_right" shift 2 ;; -foot) - str="**$2" + [[ -z $2 ]] && str="${style}${style}${style}" || str="${style}${style}$2" len=${#str} right=$(( ((line_len-len)) )) - printf -v pad_right "%*s" $right && pad_right=${pad_right// /*} + printf -v pad_right "%*s" $right && pad_right=${pad_right// /$style} printf "%s%s\n" "$str" "$pad_right" - shift 2 - unset line_len + [[ -z $2 ]] && shift || shift 2 + unset line_len; unset style ;; -nl|-li|*) if [[ "$1" == "-nl" ]]; then @@ -149,7 +155,7 @@ menu_print() { [[ "$str" =~ ';1m' ]] && ((len-=2)) pad_len=$(( ((line_len-len-5)) )) printf -v pad "%*s" $pad_len # && pad=${pad// /-} - printf '* %b %s *\n' "$str" "$pad" + printf '%s %b %s %s\n' "$style" "$str" "$pad" "$style" shift ;; esac @@ -222,7 +228,11 @@ logit() { # if status was ERROR which means FATAL then log and exit script if $fatal ; then - echo -e "$(date +'%b %d %T') [$$][${status}][${process}] Last Error is fatal, script exiting Please review log ${log_file}" && exit 1 + echo -e "$(date +'%b %d %T') [$$][${status}][${process}] Last Error is fatal, script exiting Please review log ${log_file}" + echo -e "\n${_red}---- Error Detail ----${_norm}" + grep -A 999 "${log_start}" $log_file | grep -v "^WARNING: Retrying " | grep -v "apt does not have a stable CLI interface" | grep "ERROR" -B 10 | grep -v "INFO" + echo '--' + exit 1 fi } From 4fa741e8aa5f20ebc9a0fdd75b06adee251a4210 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 02:44:21 -0500 Subject: [PATCH 07/53] fix -c flag in menu_print --- installer/common.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installer/common.sh b/installer/common.sh index 68b52f1e..453d2809 100755 --- a/installer/common.sh +++ b/installer/common.sh @@ -112,7 +112,7 @@ menu_print() { while (( "$#" )); do case "$1" in -c) - style="$(echo $2 | cut -d'=' -f2)" + style=$2 shift 2 ;; -L|-len) @@ -133,12 +133,12 @@ menu_print() { shift 2 ;; -foot) - [[ -z $2 ]] && str="${style}${style}${style}" || str="${style}${style}$2" + str="${style}${style}$2" len=${#str} right=$(( ((line_len-len)) )) printf -v pad_right "%*s" $right && pad_right=${pad_right// /$style} printf "%s%s\n" "$str" "$pad_right" - [[ -z $2 ]] && shift || shift 2 + shift 2 unset line_len; unset style ;; -nl|-li|*) From c487df350c66316cbe88d5f9c13999001fed2e12 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 02:45:32 -0500 Subject: [PATCH 08/53] tweak get_serial_udev footer --- installer/update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/update.sh b/installer/update.sh index 17e16bb4..d3aa0582 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -812,7 +812,7 @@ get_serial_udev() { "This function can be called anytime from the shell via ${_cyan}consolepi-addconsole${_norm} and is available from" "${_cyan}consolepi-menu${_norm} via the 'rn' (rename) option." -nl - -foot + -foot '-' ) menu_print "${_msg[@]}" echo From 3f5775cffa57e7964afcd596e41c06e7c3a9172c Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 02:45:59 -0500 Subject: [PATCH 09/53] move libssl libffi to do_apt_deps --- installer/install.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index bc9d1495..a15038d3 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -90,6 +90,20 @@ do_apt_deps() { [[ ! $(dpkg -l python3-pip 2>/dev/null| tail -1 |cut -d" " -f1) == "ii" ]] && process_cmds -e -pf "install python3-pip" -apt-install "python3-pip" + # 02-05-2020 raspbian buster could not pip install requirements would error with no libffi + # 09-03-2020 Confirmed this is necessary, and need to vrfy on upgrades + process="Verify libffi-dev" + if ! dpkg -l libffi-dev >/dev/null 2>&1 ; then + process_cmds -pf "install libffi-dev" -apt-install "libffi-dev" + fi + + # 02-13-2020 raspbian buster could not pip install cryptography resolved by apt installing libssl-dev + # TODO check if this is required + process="install libssl-dev" + if ! dpkg -l libssl-dev >/dev/null 2>&1 ; then + process_cmds -pf "install libssl-dev" -apt-install "libssl-dev" + fi + # TODO add picocom, maybe ser2net, ensure process_cmds can accept multiple packages logit "$process - Complete" @@ -249,13 +263,6 @@ pre_git_prep() { fi # -- // Operations performed on both installs and upgrades \\ -- - # 02-05-2020 raspbian buster could not pip install requirements would error with no libffi - # 09-03-2020 Confirmed this is necessary, and need to vrfy on upgrades - process="Verify libffi-dev" - if ! dpkg -l libffi-dev >/dev/null 2>&1 ; then - process_cmds -nostart -apt-install "libffi-dev" - fi - # Give consolepi group sudo rights without passwd to stuff in the ConsolePi dir if [ ! -f /etc/sudoers.d/010_consolepi ]; then process="sudo rights consolepi group" @@ -270,13 +277,6 @@ pre_git_prep() { unset process fi - # 02-13-2020 raspbian buster could not pip install cryptography resolved by apt installing libssl-dev - # TODO check if this is required - process="install libssl-dev" - if ! dpkg -l libssl-dev >/dev/null 2>&1 ; then - process_cmds -nostart -apt-install "libssl-dev" - fi - if [ -f $cloud_cache ]; then process="ConsolePi-Upgrade-Prep (check cache owned by consolepi group)" group=$(stat -c '%G' $cloud_cache) From 8288c42c258b722046cfd39e48818654c736f290 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 02:46:41 -0500 Subject: [PATCH 10/53] squelch log on tty test --- src/autohotspotN | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/autohotspotN b/src/autohotspotN index 079350ef..b4efba69 100755 --- a/src/autohotspotN +++ b/src/autohotspotN @@ -84,11 +84,11 @@ logit() { no_color_msg=${message/\\${_green}/} ; no_color_msg=${no_color_msg/\\${_red}/} ; no_color_msg=${no_color_msg/\\${_norm}/} # -- Log to log-file -- - echo -e "$(date +"%b %d %T") [${status}][${process}] ${no_color_msg}" >> $log_file + echo -e "$(date +"%b %d %T") [$$][${status}][${process}] ${no_color_msg}" >> $log_file # -- Any warning/errors log to syslog/stdout as well -- if [[ ! "${status}" == "INFO" ]] && [[ ! "${status}" == "DEBUG" ]]; then - if [[ -t 1 ]]; then + if [ -t 1 2>/dev/null ]; then echo -e "[${c_status}] ${message}" # log any errors to syslog as well else echo -e "[${status}] ${no_color_msg}" # log any errors to syslog as well @@ -100,7 +100,7 @@ logit() { fi else # -- Always Log to stdout if this is a tty -- - [ -t 1 ] && echo -e "[${c_status}][${process}] ${message}" + [ -t 1 2>/dev/null ] && echo -e "[${c_status}][${process}] ${message}" fi return 0 } @@ -173,11 +173,11 @@ start_stop_dnsmasq() { # if all files are in place to use new separate instance for hotspot dhcp do so otherwise assume using dnsmasq default instance if [ -f $ahs_dhcp_config ] && [ -f /etc/dnsmasq.d/01-consolepi ] && ( [ -L /etc/systemd/system/consolepi-autohotspot-dhcp.service ] || [ -f /etc/systemd/system/consolepi-autohotspot-dhcp.service ] ); then - logit "Using ConsolePi Specific dnsmasq instance" - systemctl $1 consolepi-autohotspot-dhcp.service + [[ $1 == "start" ]] && logit "Using ConsolePi Specific dnsmasq instance" + systemctl $1 consolepi-autohotspot-dhcp.service || logit "Failed to $1 AutoHotSpot DHCP" else - logit "ConsolePi Specific dnsmasq instance *not* Configured, using default dnsmasq instance" - systemctl $1 dnsmasq.service + [[ $1 == "start" ]] && logit "ConsolePi Specific dnsmasq instance *not* Configured, using default dnsmasq instance" + systemctl $1 dnsmasq.service || logit "Failed to $1 AutoHotSpot DHCP (dnsmasq)" fi } From c378382699841a307d6233bd4672af31ca59bdd6 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 02:47:06 -0500 Subject: [PATCH 11/53] Retry loop for initial mount after image --- installer/consolepi-image-creator.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/installer/consolepi-image-creator.sh b/installer/consolepi-image-creator.sh index 9b6174a0..04e3a26f 100755 --- a/installer/consolepi-image-creator.sh +++ b/installer/consolepi-image-creator.sh @@ -558,8 +558,18 @@ main() { # Mount boot partition dots "Mounting boot partition to enable ssh" - [[ $my_usb =~ "mmcblk" ]] && res=$(sudo mount /dev/${my_usb}p1 /mnt/usb1 2>&1) || res=$(sudo mount /dev/${my_usb}1 /mnt/usb1 2>&1) - do_error $? "$res" + for i in {1..2}; do + [[ $my_usb =~ "mmcblk" ]] && res=$(sudo mount /dev/${my_usb}p1 /mnt/usb1 2>&1) || res=$(sudo mount /dev/${my_usb}1 /mnt/usb1 2>&1) ; rc=$? + if [[ $rc == 0 ]]; then + break + else + # mmcblk device would fail on laptop after image creation re-run with -nodd and was fine + echo "Sleep then Retry" + sleep 3 + dots "Mounting boot partition to enable ssh" + fi + done + do_error $rc "$res" # Create empty file ssh in boot partition dots "Enabling ssh on image" From a645bb4f6be74bddf6854490b77e5874d7829e0e Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 02:52:00 -0500 Subject: [PATCH 12/53] menu_print being odd on upgrade only --- installer/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/common.sh b/installer/common.sh index 453d2809..b7702efe 100755 --- a/installer/common.sh +++ b/installer/common.sh @@ -112,7 +112,7 @@ menu_print() { while (( "$#" )); do case "$1" in -c) - style=$2 + style="$2" shift 2 ;; -L|-len) From c3b36aeb2c408dd8a927baff7ff5875a6c534fb7 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 02:57:45 -0500 Subject: [PATCH 13/53] revert get_serial_udev back to static - not menu_print --- installer/update.sh | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/installer/update.sh b/installer/update.sh index d3aa0582..d2675771 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -792,31 +792,27 @@ get_serial_udev() { process="Predictable Console Ports" logit "${process} Starting" header - - declare -a _msg=( - -L 116 -c '-' -head "${_green}Predictable Console ports${_norm}" - -nl - "Predictable Console ports allow you to configure ConsolePi so that each time you plug-in a specific adapter it" - "will have the same name in consolepi-menu and will be reachable via the same TELNET port." - -nl - "The behavior if you do ${_lred}not${_norm} define Predictable Console Ports is the adapters will use the root device names" - "ttyUSB# or ttyACM# where the # starts with 0 and increments for each adapter of that type plugged in. The names" - "won't necessarily be consistent between reboots nor will the TELNET port. This method is OK for temporary use" - "of an adapter or if you only plan to use a single adapter. Otherwise setting predictable aliases is" - "${_lred}highly recommended${_norm}." - -nl - "Defining the ports with this utility is also how device specific serial settings are configured. Otherwise" - "they will use the default (9600 8N1)." - -nl - -nl - "This function can be called anytime from the shell via ${_cyan}consolepi-addconsole${_norm} and is available from" - "${_cyan}consolepi-menu${_norm} via the 'rn' (rename) option." - -nl - -foot '-' - ) - menu_print "${_msg[@]}" echo - + echo -e "--------------------------------------------- ${_green}Predictable Console ports${_norm} ---------------------------------------------" + echo "- -" + echo "- Predictable Console ports allow you to configure ConsolePi so that each time you plug-in a specific adapter it -" + echo "- will have the same name in consolepi-menu and will be reachable via the same TELNET port. -" + echo "- -" + echo "- The behavior if you do *not* define Predictable Console Ports is the adapters will use the root device names -" + echo "- ttyUSB# or ttyACM# where the # starts with 0 and increments for each adapter of that type plugged in. The names -" + echo "- won't necessarily be consistent between reboots nor will the TELNET port. This method is OK for temporary use -" + echo -e "- of an adapter or if you only plan to use a single adapter. Otherwise setting predictable aliases is -" + echo "- ${_lred}highly recommended${_norm}. -" + echo "- -" + echo "- Defining the ports with this utility is also how device specific serial settings are configured. Otherwise -" + echo "- they will use the default which is 9600 8N1 -" + echo "- -" + echo "- -" + echo -e "- This function can be called anytime from the shell via ${_cyan}consolepi-addconsole${_norm} and is available from -" + echo -e "- ${_cyan}consolepi-menu${_norm} via the 'rn' (rename) option. -" + echo "- -" + echo "---------------------------------------------------------------------------------------------------------------------" + echo echo "You need to have the serial adapters available" prompt="Would you like to configure predictable serial port aliases now" $upgrade && user_input false "${prompt}" || user_input true "${prompt}" From 754de02eaef4390c104f63f594a4d6bcbba7a71c Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 02:58:58 -0500 Subject: [PATCH 14/53] get_serial_udev msg --- installer/update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/update.sh b/installer/update.sh index d2675771..7b9f9c79 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -802,7 +802,7 @@ get_serial_udev() { echo "- ttyUSB# or ttyACM# where the # starts with 0 and increments for each adapter of that type plugged in. The names -" echo "- won't necessarily be consistent between reboots nor will the TELNET port. This method is OK for temporary use -" echo -e "- of an adapter or if you only plan to use a single adapter. Otherwise setting predictable aliases is -" - echo "- ${_lred}highly recommended${_norm}. -" + echo -e "- ${_lred}highly recommended${_norm}. -" echo "- -" echo "- Defining the ports with this utility is also how device specific serial settings are configured. Otherwise -" echo "- they will use the default which is 9600 8N1 -" From 57e25b48ebadffcd6d2831ae22b54ad5487f8e3e Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 02:59:45 -0500 Subject: [PATCH 15/53] spacing in msg --- installer/update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/update.sh b/installer/update.sh index 7b9f9c79..b9b8fe7f 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -802,7 +802,7 @@ get_serial_udev() { echo "- ttyUSB# or ttyACM# where the # starts with 0 and increments for each adapter of that type plugged in. The names -" echo "- won't necessarily be consistent between reboots nor will the TELNET port. This method is OK for temporary use -" echo -e "- of an adapter or if you only plan to use a single adapter. Otherwise setting predictable aliases is -" - echo -e "- ${_lred}highly recommended${_norm}. -" + echo -e "- ${_lred}highly recommended${_norm}. -" echo "- -" echo "- Defining the ports with this utility is also how device specific serial settings are configured. Otherwise -" echo "- they will use the default which is 9600 8N1 -" From edd9b493ebab243f53fdc6604f1cacce01b3e555 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 13:19:57 -0500 Subject: [PATCH 16/53] process_cmds log improvements --- installer/common.sh | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/installer/common.sh b/installer/common.sh index b7702efe..fa43f14b 100755 --- a/installer/common.sh +++ b/installer/common.sh @@ -590,12 +590,12 @@ spaces() { } process_cmds() { - reset_vars=('cmd' 'pmsg' 'fmsg' 'cmd_pfx' 'fail_lvl' 'silent' 'out' 'stop' 'err' 'showstart' 'pname' 'pexclude' 'pkg' 'do_apt_install') + reset_vars=('cmd' 'pmsg' 'fmsg' 'cmd_pfx' 'fail_lvl' '_silent' 'out' 'stop' 'err' 'showstart' 'pname' 'pexclude' 'pkg' 'do_apt_install') local do_autoremove=false # TODO check if the return is necessary may be relic from early testing $_DEBUG_ && echo "DEBUG: ${@}" ## -- DEBUG LINE -- while (( "$#" )); do if $_DEBUG_; then - echo -e "DEBUG:\n\tcmd=${cmd}\n\tsilent=$silent\n\tpmsg=${pmsg}\n\tfmsg=${fmsg}\n\tfail_lvl=$fail_lvl" + echo -e "DEBUG:\n\tcmd=${cmd}\n\t_silent=$_silent\n\tpmsg=${pmsg}\n\tfmsg=${fmsg}\n\tfail_lvl=$fail_lvl" echo -e "DEBUG TOP ~ Currently evaluating: '$1'" fi case "$1" in @@ -608,7 +608,7 @@ process_cmds() { shift ;; -s) # only show msg if cmd fails - local silent=true + local _silent=true shift ;; -u) # Run Command as logged in User @@ -664,8 +664,8 @@ process_cmds() { [ -z pmsg ] && local pmsg="Success - Install $pname (apt)" [ -z fmsg ] && local fmsg="Error - Install $pname (apt)" local stop=true - [[ ! -z $pexclude ]] && local cmd="sudo apt-get -y install $pkg ${pexclude}-" || - local cmd="sudo apt-get -y install $pkg" + [[ ! -z $pexclude ]] && local cmd="sudo apt -y install $pkg ${pexclude}-" || + local cmd="sudo apt -y install $pkg" ;; -apt-purge) # purge pkg followed by autoremove case "$3" in @@ -680,7 +680,7 @@ process_cmds() { esac [ -z pmsg ] && local pmsg="Success - Remove $pname (apt)" [ -z fmsg ] && local fmsg="Error - Remove $pname (apt)" - local cmd="sudo apt-get -y purge $2" + local cmd="sudo apt -y purge $2" local do_autoremove=true shift $_shift ;; @@ -713,10 +713,10 @@ process_cmds() { # if cmd is set process cmd # use defaults if flag not set if [[ ! -z $cmd ]]; then - local pmsg=${pmsg:-"Success - $cmd"} + local pmsg=${pmsg:-"Success - ${cmd/-y /}"} local fmsg=${fmsg:-"Error - $cmd See details in $log_file"} local fail_lvl=${fail_lvl:-"WARNING"} - local silent=${silent:-false} + local _silent=${_silent:-false} local stop=${stop:-false} local err=${err:-$log_file} local out=${out:-'/dev/null'} @@ -724,16 +724,15 @@ process_cmds() { local do_apt_install=${do_apt_install:-false} [[ ! -z $cmd_pfx ]] && local cmd="$cmd_pfx $cmd" if $_DEBUG_; then - echo -e "DEBUG:\n\tcmd=$cmd\n\tpname=$pname\n\tsilent=$silent\n\tpmsg=${pmsg}\n\tfmsg=${fmsg}\n\tfail_lvl=$fail_lvl\n\tout=$out\n\tstop=$stop\n\tret=$ret\n" + echo -e "DEBUG:\n\tcmd=$cmd\n\tpname=$pname\n\t_silent=$_silent\n\tpmsg=${pmsg}\n\tfmsg=${fmsg}\n\tfail_lvl=$fail_lvl\n\tout=$out\n\tstop=$stop\n\tret=$ret\n" echo "------------------------------------------------------------------------------------------" fi # -- // PROCESS THE CMD \\ -- - ! $silent && $showstart && logit "Starting ${pmsg/Success - /}" - # if eval "$cmd" >>"$out" 2>>"$err"; then # <-- Do the command + ! $_silent && $showstart && logit "Starting ${pmsg/Success - /}" logit -L "process_cmds executing: $cmd" if eval "$cmd" >>"$out" 2> >(grep -v "^$\|^WARNING: apt does not.*CLI.*$" >>"$err") ; then # <-- Do the command local cmd_failed=false - ! $silent && logit "$pmsg" + ! $_silent && logit "$pmsg" unset cmd else local cmd_failed=true @@ -746,7 +745,7 @@ process_cmds() { logit -L "process_cmds executing: $cmd" if eval "$cmd" >>"$out" 2> >(grep -v "^$\|^WARNING: apt does not.*CLI.*$" >>"$err"); then local cmd_failed=false - ! $silent && logit "$pmsg" + ! $_silent && logit "$pmsg" fi ((x+=1)) done @@ -775,5 +774,5 @@ process_cmds() { logit "Error - apt autoremove returned error-code" "WARNING" fi - return 0 + ! $cmd_failed && return 0 || return 1 } From cd1a6902e4b2c0f06d8f9bbe36a64990c7aeef93 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 13:20:41 -0500 Subject: [PATCH 17/53] Move pi user passwd change to pre_git_prep with other user stuff --- installer/install.sh | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index a15038d3..92dbc014 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -92,14 +92,12 @@ do_apt_deps() { # 02-05-2020 raspbian buster could not pip install requirements would error with no libffi # 09-03-2020 Confirmed this is necessary, and need to vrfy on upgrades - process="Verify libffi-dev" if ! dpkg -l libffi-dev >/dev/null 2>&1 ; then process_cmds -pf "install libffi-dev" -apt-install "libffi-dev" fi # 02-13-2020 raspbian buster could not pip install cryptography resolved by apt installing libssl-dev # TODO check if this is required - process="install libssl-dev" if ! dpkg -l libssl-dev >/dev/null 2>&1 ; then process_cmds -pf "install libssl-dev" -apt-install "libssl-dev" fi @@ -168,6 +166,38 @@ pre_git_prep() { else # -- // ONLY PERFORMED ON FRESH INSTALLS \\ -- + # Update passwd for pi user if it is the default. + process="pi user password change" + [ -e /run/sshwarn ] || logit "/run/sshwarn failed eval" "DEBUG" + if grep -q "^pi:" /etc/passwd && [[ "$iam" == "pi" ]] && [ -e /run/sshwarn ]; then + if [ ! -z "$pi_pass" ]; then + echo "pi:${pi_pass}" | chpasswd 2>> $log_file && logit "Successfully changed pi password using conf/cmd_line arg" || + logit "Error occured changing pi password using conf/cmd_line arg" "WARNING" + else + header + echo "You are logged in as pi, and the default password has not been changed" + prompt="Do You want to change the password for user pi" + response=$(user_input_bool) + if $response; then + # match=false + # while ! $match; do + # read -sep "Enter new password for user pi: " pass && echo + # read -sep "Re-Enter new password for user pi: " pass2 && echo + # [[ "${pass}" == "${pass2}" ]] && match=true || match=false + # ! $match && echo -e "ERROR: Passwords Do Not Match\n" + # done + ask_pass + echo "pi:${_pass}" | sudo chpasswd 2>> $log_file && logit "Success" || + # echo "pi:${pass}" | sudo chpasswd 2>> $log_file && logit "Success" || + ( logit "Failed to Change Password for pi user" "WARNING" && + echo -e "\n!!! There was an issue changing password. Installation will continue, but continue to use existing password and update manually !!!" ) + # unset pass && unset pass2 && unset process + unset pass; unset process + fi + fi + fi + + process="Create consolepi user/group" # add consolepi user header From a54f3678099667eabcdf6545a185d72086fc7b42 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 13:21:11 -0500 Subject: [PATCH 18/53] Move chg_passwd pi user to phase1 install --- installer/update.sh | 203 +++++++++++++++++++------------------------- 1 file changed, 86 insertions(+), 117 deletions(-) diff --git a/installer/update.sh b/installer/update.sh index b9b8fe7f..638e33b7 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -10,35 +10,6 @@ # -- -- # # --------------------------------------------------------------------------------------------------------------------------------------------------# -chg_password() { - process="pi user password change" - [ -e /run/sshwarn ] || logit "/run/sshwarn failed eval" "DEBUG" - if grep -q "^pi:" /etc/passwd && [[ "$iam" == "pi" ]] && [ -e /run/sshwarn ]; then - if [ ! -z "$pi_pass" ]; then - echo "pi:${pi_pass}" | chpasswd 2>> $log_file && logit "Successfully changed pi password using conf/cmd_line arg" || - logit "Error occured changing pi password using conf/cmd_line arg" "WARNING" - else - header - echo "You are logged in as pi, and the default password has not been changed" - prompt="Do You want to change the password for user pi" - response=$(user_input_bool) - if $response; then - match=false - while ! $match; do - read -sep "Enter new password for user pi: " pass && echo - read -sep "Re-Enter new password for user pi: " pass2 && echo - [[ "${pass}" == "${pass2}" ]] && match=true || match=false - ! $match && echo -e "ERROR: Passwords Do Not Match\n" - done - echo "pi:${pass}" | sudo chpasswd 2>> $log_file && logit "Success" || - ( logit "Failed to Change Password for pi user" "WARNING" && - echo -e "\n!!! There was an issue changing password. Installation will continue, but continue to use existing password and update manually !!!" ) - unset pass && unset pass2 && unset process - fi - fi - fi -} - set_hostname() { process="Change Hostname" hostn=$(cat /etc/hostname) @@ -162,104 +133,103 @@ disable_ipv6() { misc_imports(){ # additional imports occur in related functions if import file exists process="Perform misc imports" - if ! $upgrade; then - # -- ssh authorized keys -- - found_path=$(get_staged_file_path "authorized_keys") - [[ $found_path ]] && logit "pre-staged ssh authorized keys found - importing" - if [[ $found_path ]]; then - file_diff_update $found_path /root/.ssh/authorized_keys - file_diff_update $found_path ${home_dir}/.ssh/authorized_keys - chown $iam:$iam ${home_dir}/.ssh/authorized_keys - fi - # -- ssh known hosts -- - found_path=$(get_staged_file_path "known_hosts") - [[ $found_path ]] && logit "pre-staged ssh known_hosts file found - importing" - if [[ $found_path ]]; then - file_diff_update $found_path /root/.ssh/known_hosts - file_diff_update $found_path ${home_dir}/.ssh/known_hosts - chown $iam:$iam ${home_dir}/.ssh/known_hosts + # -- ssh authorized keys -- + found_path=$(get_staged_file_path "authorized_keys") + [[ $found_path ]] && logit "pre-staged ssh authorized keys found - importing" + if [[ $found_path ]]; then + file_diff_update $found_path /root/.ssh/authorized_keys + file_diff_update $found_path ${home_dir}/.ssh/authorized_keys + chown $iam:$iam ${home_dir}/.ssh/authorized_keys + fi + + # -- ssh known hosts -- + found_path=$(get_staged_file_path "known_hosts") + [[ $found_path ]] && logit "pre-staged ssh known_hosts file found - importing" + if [[ $found_path ]]; then + file_diff_update $found_path /root/.ssh/known_hosts + file_diff_update $found_path ${home_dir}/.ssh/known_hosts + chown $iam:$iam ${home_dir}/.ssh/known_hosts + fi + + # -- pre staged cloud creds -- + if $cloud && [[ -f ${stage_dir}/.credentials/credentials.json ]]; then + found_path=${stage_dir}/.credentials + mv $found_path/* "/etc/ConsolePi/cloud/${cloud_svc}/.credentials" 2>> $log_file && + logit "Found ${cloud_svc} credentials. Moving to /etc/ConsolePi/cloud/${cloud_svc}/.credentials" || + logit "Error occurred moving your ${cloud_svc} credentials files" "WARNING" + elif $cloud ; then + if [ ! -f "$CLOUD_CREDS_FILE" ]; then + desktop_msg="Use 'consolepi-menu cloud' then select the 'r' (refresh) option to authorize ConsolePi in ${cloud_svc}" + lite_msg="RaspiOS-lite detected. Refer to the GitHub for instructions on how to generate credential files off box" fi + fi - # -- pre staged cloud creds -- - if $cloud && [[ -f ${stage_dir}/.credentials/credentials.json ]]; then - found_path=${stage_dir}/.credentials - mv $found_path/* "/etc/ConsolePi/cloud/${cloud_svc}/.credentials" 2>> $log_file && - logit "Found ${cloud_svc} credentials. Moving to /etc/ConsolePi/cloud/${cloud_svc}/.credentials" || - logit "Error occurred moving your ${cloud_svc} credentials files" "WARNING" - elif $cloud ; then - if [ ! -f "$CLOUD_CREDS_FILE" ]; then - desktop_msg="Use 'consolepi-menu cloud' then select the 'r' (refresh) option to authorize ConsolePi in ${cloud_svc}" - lite_msg="RaspiOS-lite detected. Refer to the GitHub for instructions on how to generate credential files off box" + # -- custom overlay file for PoE hat (fan control) -- + found_path=$(get_staged_file_path "rpi-poe-overlay.dts") + [[ $found_path ]] && logit "overlay file found creating dtbo" + if [[ $found_path ]]; then + sudo dtc -@ -I dts -O dtb -o /tmp/rpi-poe.dtbo $found_path >> $log_file 2>&1 && + overlay_success=true || overlay_success=false + if $overlay_success; then + sudo mv /tmp/rpi-poe.dtbo /boot/overlays 2>> $log_file && + logit "Successfully moved overlay file, will activate on boot" || + logit "Failed to move overlay file" + else + logit "Failed to create Overlay file from dts" fi - fi - - # -- custom overlay file for PoE hat (fan control) -- - found_path=$(get_staged_file_path "rpi-poe-overlay.dts") - [[ $found_path ]] && logit "overlay file found creating dtbo" - if [[ $found_path ]]; then - sudo dtc -@ -I dts -O dtb -o /tmp/rpi-poe.dtbo $found_path >> $log_file 2>&1 && - overlay_success=true || overlay_success=false - if $overlay_success; then - sudo mv /tmp/rpi-poe.dtbo /boot/overlays 2>> $log_file && - logit "Successfully moved overlay file, will activate on boot" || - logit "Failed to move overlay file" - else - logit "Failed to create Overlay file from dts" - fi - fi + fi - # TODO may need to adjust once fully automated - # -- wired-dhcp configurations -- - if [[ -d ${stage_dir}/wired-dhcp ]]; then - logit "Staged wired-dhcp directory found copying contents to ConsolePi wired-dchp dir" - cp -r ${stage_dir}/wired-dhcp/. /etc/ConsolePi/dnsmasq.d/wired-dhcp/ && - logit "Success - copying staged wired-dchp configs" || - logit "Failure - copying staged wired-dchp configs" "WARNING" - fi + # TODO may need to adjust once fully automated + # -- wired-dhcp configurations -- + if [[ -d ${stage_dir}/wired-dhcp ]]; then + logit "Staged wired-dhcp directory found copying contents to ConsolePi wired-dchp dir" + cp -r ${stage_dir}/wired-dhcp/. /etc/ConsolePi/dnsmasq.d/wired-dhcp/ && + logit "Success - copying staged wired-dchp configs" || + logit "Failure - copying staged wired-dchp configs" "WARNING" + fi - # -- ztp configurations -- - if [[ -d ${stage_dir}/ztp ]]; then - logit "Staged ztp directory found copying contents to ConsolePi ztp dir" - cp -r ${stage_dir}/ztp/. ${consolepi_dir}ztp/ 2>>$log_file && - logit "Success - copying staged ztp configs" || - logit "Failure - copying staged ztp configs" "WARNING" - if [[ $(ls -1 | grep -vi "README" | wc -l ) > 0 ]]; then - check_perms ${consolepi_dir}ztp - fi + # -- ztp configurations -- + if [[ -d ${stage_dir}/ztp ]]; then + logit "Staged ztp directory found copying contents to ConsolePi ztp dir" + cp -r ${stage_dir}/ztp/. ${consolepi_dir}ztp/ 2>>$log_file && + logit "Success - copying staged ztp configs" || + logit "Failure - copying staged ztp configs" "WARNING" + if [[ $(ls -1 | grep -vi "README" | wc -l ) > 0 ]]; then + check_perms ${consolepi_dir}ztp fi + fi - # -- autohotspot dhcp configurations -- - if [[ -d ${stage_dir}/autohotspot-dhcp ]]; then - logit "Staged autohotspot-dhcp directory found copying contents to ConsolePi autohotspot dchp dir" - cp -r ${stage_dir}/autohotspot-dhcp/. /etc/ConsolePi/dnsmasq.d/autohotspot/ && - logit "Success - copying staged autohotspot-dchp configs" || - logit "Failure - copying staged autohotspot-dchp configs" "WARNING" - fi + # -- autohotspot dhcp configurations -- + if [[ -d ${stage_dir}/autohotspot-dhcp ]]; then + logit "Staged autohotspot-dhcp directory found copying contents to ConsolePi autohotspot dchp dir" + cp -r ${stage_dir}/autohotspot-dhcp/. /etc/ConsolePi/dnsmasq.d/autohotspot/ && + logit "Success - copying staged autohotspot-dchp configs" || + logit "Failure - copying staged autohotspot-dchp configs" "WARNING" + fi - # -- udev rules - serial port mappings -- - found_path=$(get_staged_file_path "10-ConsolePi.rules") - if [[ $found_path ]]; then - logit "udev rules file found ${found_path} enabling provided udev rules" - if [ -f /etc/udev/rules.d/10-ConsolePi.rules ]; then - file_diff_update $found_path /etc/udev/rules.d/10-ConsolePi.rules - else - sudo cp $found_path /etc/udev/rules.d - sudo udevadm control --reload-rules && sudo udevadm trigger - fi + # -- udev rules - serial port mappings -- + found_path=$(get_staged_file_path "10-ConsolePi.rules") + if [[ $found_path ]]; then + logit "udev rules file found ${found_path} enabling provided udev rules" + if [ -f /etc/udev/rules.d/10-ConsolePi.rules ]; then + file_diff_update $found_path /etc/udev/rules.d/10-ConsolePi.rules + else + sudo cp $found_path /etc/udev/rules.d + sudo udevadm control --reload-rules && sudo udevadm trigger fi + fi - # -- imported elsewhere during the install - # /etc/ser2net.conf in install_ser2net() - # /etc/openvpn/client/ConsolePi.ovpn and ovpn_credentials in install_openvpn() - # /etc/wpa_supplicant/wpa_supplicant.conf in get_known_ssids() - # - # -- imported in phase 1 (install.sh) - # /home/pi/.ssh/known_hosts - # /home/pi/.ssh/authorized_keys - # /home//. for non pi user contents of /home/ is imported after the user is created + # -- imported elsewhere during the install + # /etc/ser2net.conf in install_ser2net() + # /etc/openvpn/client/ConsolePi.ovpn and ovpn_credentials in install_openvpn() + # /etc/wpa_supplicant/wpa_supplicant.conf in get_known_ssids() + # + # -- imported in phase 1 (install.sh) + # /home/pi/.ssh/known_hosts + # /home/pi/.ssh/authorized_keys + # /home//. for non pi user contents of /home/ is imported after the user is created - fi unset process } @@ -994,13 +964,12 @@ update_main() { # update_config if ! $upgrade; then - chg_password set_hostname set_timezone disable_ipv6 do_wifi_country + misc_imports fi - misc_imports install_ser2net dhcp_run_hook ConsolePi_cleanup From ea633401e48e22aee19ff3033555c4c617a8ffa4 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 13:23:10 -0500 Subject: [PATCH 19/53] logging enchancement --- installer/utilities.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/utilities.sh b/installer/utilities.sh index d52de501..e2eec02d 100755 --- a/installer/utilities.sh +++ b/installer/utilities.sh @@ -290,7 +290,7 @@ util_exec() { else ch=true fi - $ch && process_cmds "${cmd_list[@]}" && logit "Done - $2 $process Completed without Issue." + $ch && process_cmds "${cmd_list[@]}" && logit "Done - $2 $process Completed without issue." || logit "Done - $2 $process Completed WARNINGS Occured." "WARNING" } # translate menu tag to pkg name when a prettier name is used in the menu From 8b481a3600921281f856f4e204e6ef6a70bfb352 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 13:38:11 -0500 Subject: [PATCH 20/53] Change a couple of default values --- ConsolePi.yaml.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ConsolePi.yaml.example b/ConsolePi.yaml.example index 12a643a6..12e3ad6c 100644 --- a/ConsolePi.yaml.example +++ b/ConsolePi.yaml.example @@ -12,12 +12,12 @@ CONFIG: vpn_check_ip: 10.0.150.1 # used to check VPN (internal) connectivity should be ip only reachable via VPN net_check_ip: 8.8.4.4 # used to check Internet connectivity local_domain: example.com # used to bypass VPN. evals domain sent via dhcp option if matches this var will not establish vpn - wlan_ip: 10.112.0.1 # IP of ConsolePi when in hotspot mode + wlan_ip: 10.110.0.1 # IP of ConsolePi when in hotspot mode wlan_ssid: ConsolePi # SSID used in hotspot mode wlan_psk: ConsolePiR0cks!! # psk used for hotspot SSID wlan_country: US # regulatory domain for hotspot SSID wired_dhcp: false # Run dhcp on eth interface (after trying as client) - wired_ip: 10.12.0.1 # Fallback IP for eth interface + wired_ip: 10.30.110.1 # Fallback IP for eth interface btmode: serial # Bluetooth Mode: 'serial' or 'pan' cloud: false # enable ConsolePi cloud sync for Clustering (mdns enabled either way) cloud_svc: gdrive # must be gdrive (all that is supported now) From 9296935b8c2f531d0f8f36336ec94128ba8bc058 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 14:01:30 -0500 Subject: [PATCH 21/53] process_cmd logging output tweaks --- installer/common.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/installer/common.sh b/installer/common.sh index fa43f14b..bfa3824b 100755 --- a/installer/common.sh +++ b/installer/common.sh @@ -713,7 +713,10 @@ process_cmds() { # if cmd is set process cmd # use defaults if flag not set if [[ ! -z $cmd ]]; then - local pmsg=${pmsg:-"Success - ${cmd/-y /}"} + local pcmd=${cmd/sudo /} ; local pcmd=${cmd/-y /} + local pmsg=${pmsg:-"Success - $pcmd"} + unset pcmd + # local pmsg=${pmsg:-"Success - ${cmd/-y /}"} local fmsg=${fmsg:-"Error - $cmd See details in $log_file"} local fail_lvl=${fail_lvl:-"WARNING"} local _silent=${_silent:-false} @@ -728,7 +731,7 @@ process_cmds() { echo "------------------------------------------------------------------------------------------" fi # -- // PROCESS THE CMD \\ -- - ! $_silent && $showstart && logit "Starting ${pmsg/Success - /}" + ! $_silent && $showstart && logit -E "Starting ${pmsg/Success - /}" logit -L "process_cmds executing: $cmd" if eval "$cmd" >>"$out" 2> >(grep -v "^$\|^WARNING: apt does not.*CLI.*$" >>"$err") ; then # <-- Do the command local cmd_failed=false From 6c645e63504bc3e166e4f7d3084110dc9821c723 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 14:34:28 -0500 Subject: [PATCH 22/53] fix consolepi-autohotspot-dhcp disable during install --- installer/update.sh | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/installer/update.sh b/installer/update.sh index 638e33b7..e7043010 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -378,7 +378,6 @@ install_autohotspotn () { process="AutoHotSpotN" logit "Install/Update AutoHotSpotN" - # TODO check logic here, double check consolepi-autohotspot-dhcp is being disabled after install systemd_diff_update autohotspot if ! head -1 /etc/dnsmasq.conf 2>/dev/null | grep -q 'ConsolePi installer' ; then logit "Using New autohotspot specific dnsmasq instance" @@ -388,31 +387,36 @@ install_autohotspotn () { systemctl stop consolepi-autohotspot-dhcp 2>>$log_file || logit "Failed to stop consolepi-autohotspot-dhcp.service check log" "WARNING" fi - if systemctl is-enabled >/dev/null 2>&1; then - systemctl disable consolepi-autohotspot-dhcp 2>>$log_file || + if systemctl is-enabled consolepi-autohotspot-dhcp >/dev/null 2>&1; then + systemctl disable consolepi-autohotspot-dhcp 2>>$log_file && + logit "consolepi-autohotspot-dhcp autostart disabled Successfully, startup handled by autohotspot" logit "Failed to disable consolepi-autohotspot-dhcp.service check log" "WARNING" fi else logit "Using old autohotspot system default dnsmasq instance" fi - if ! $(which hostapd >/dev/null); then - process_cmds -apt-install hostapd - else - hostapd_ver=$(hostapd -v 2>&1| head -1| awk '{print $2}') - logit "hostapd ${hostapd_ver} already installed" - fi - dnsmasq_ver=$(dnsmasq -v 2>/dev/null | head -1 | awk '{print $3}') if [[ -z "$dnsmasq_ver" ]]; then process_cmds -apt-install dnsmasq + # disable dnsmasq only if we just installed it + sudo systemctl disable dnsmasq 1>/dev/null 2>> $log_file && + logit "dnsmasq autostart disabled Successfully" || + logit "An error occurred disabling dnsmasq autostart - verify after install" "WARNING" else logit "dnsmasq v${dnsmasq_ver} already installed" fi + if ! $(which hostapd >/dev/null); then + process_cmds -apt-install hostapd + else + hostapd_ver=$(hostapd -v 2>&1| head -1| awk '{print $2}') + logit "hostapd ${hostapd_ver} already installed" + fi + # -- override_dir set in common.sh [[ -f ${override_dir}/hostapd.service ]] && hostapd_override=true || hostapd_override=false - [[ -f ${override_dir}/dnsmasq.service ]] && dnsmasq_override=true || dnsmasq_override=false + [[ -f ${override_dir}/dnsmasq.service ]] && dnsmasq_override=true || dnsmasq_override=false # No Longer Used if ! $hostapd_override ; then logit "disabling hostapd (handled by AutoHotSpotN)." sudo systemctl unmask hostapd.service 1>/dev/null 2>> $log_file && @@ -425,13 +429,6 @@ install_autohotspotn () { logit "${_cyan}skipped hostapd disable - hostapd.service is overriden${_norm}" fi - # disable dnsmasq only if we just installed it (dnsmasq_ver won't be defined) - if [[ -z "$dnsmasq_ver" ]]; then - sudo systemctl disable dnsmasq 1>/dev/null 2>> $log_file && - logit "dnsmasq autostart disabled Successfully" || - logit "An error occurred disabling dnsmasq autostart - verify after install" "WARNING" - fi - logit "Create/Configure hostapd.conf" convert_template hostapd.conf /etc/hostapd/hostapd.conf wlan_ssid=${wlan_ssid} wlan_psk=${wlan_psk} wlan_country=${wlan_country} sudo chmod +r /etc/hostapd/hostapd.conf 2>> $log_file || logit "Failed to make hostapd.conf readable - verify after install" "WARNING" From ebd31c073ccbe9f8d9f15a04c01368054df732f2 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 15:09:02 -0500 Subject: [PATCH 23/53] simplify misc_imports --- installer/update.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/update.sh b/installer/update.sh index e7043010..33f7116f 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -136,8 +136,8 @@ misc_imports(){ # -- ssh authorized keys -- found_path=$(get_staged_file_path "authorized_keys") - [[ $found_path ]] && logit "pre-staged ssh authorized keys found - importing" if [[ $found_path ]]; then + logit "pre-staged ssh authorized keys found - importing" file_diff_update $found_path /root/.ssh/authorized_keys file_diff_update $found_path ${home_dir}/.ssh/authorized_keys chown $iam:$iam ${home_dir}/.ssh/authorized_keys @@ -145,8 +145,8 @@ misc_imports(){ # -- ssh known hosts -- found_path=$(get_staged_file_path "known_hosts") - [[ $found_path ]] && logit "pre-staged ssh known_hosts file found - importing" if [[ $found_path ]]; then + logit "pre-staged ssh known_hosts file found - importing" file_diff_update $found_path /root/.ssh/known_hosts file_diff_update $found_path ${home_dir}/.ssh/known_hosts chown $iam:$iam ${home_dir}/.ssh/known_hosts From 87e550f9b65bc332ec2b5b4bb463097a1291705b Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 15:09:16 -0500 Subject: [PATCH 24/53] add do_user_imports --- installer/install.sh | 48 +++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index 92dbc014..83b65e0a 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -107,6 +107,20 @@ do_apt_deps() { logit "$process - Complete" } +do_user_dir_import(){ + [[ $1 == root ]] && local user_home=root || local user_home="home/$1" + # -- Copy Prep pre-staged files if they exist (stage-dir/home/) for newly created user. + if [[ -d "$stage_dir/$user_home" ]]; then + logit "Found staged files for $1, copying to users home" + chown -R $(grep "^$1:" /etc/passwd | cut -d: -f3-4) "$stage_dir/$user_home" && + cp -r "$stage_dir/$user_home" "/$user_home" && + ( logit "Success - copy staged files for user $1" && return 0 ) || + ( logit "An error occured when attempting cp pre-staged files for user $1" "WARNING" + return 1 + ) + fi +} + # Process Changes that are required prior to git pull when doing upgrade pre_git_prep() { if $upgrade; then @@ -179,24 +193,17 @@ pre_git_prep() { prompt="Do You want to change the password for user pi" response=$(user_input_bool) if $response; then - # match=false - # while ! $match; do - # read -sep "Enter new password for user pi: " pass && echo - # read -sep "Re-Enter new password for user pi: " pass2 && echo - # [[ "${pass}" == "${pass2}" ]] && match=true || match=false - # ! $match && echo -e "ERROR: Passwords Do Not Match\n" - # done ask_pass echo "pi:${_pass}" | sudo chpasswd 2>> $log_file && logit "Success" || - # echo "pi:${pass}" | sudo chpasswd 2>> $log_file && logit "Success" || ( logit "Failed to Change Password for pi user" "WARNING" && echo -e "\n!!! There was an issue changing password. Installation will continue, but continue to use existing password and update manually !!!" ) - # unset pass && unset pass2 && unset process - unset pass; unset process + unset _pass; unset process fi fi fi + do_user_dir_import pi || logit -L "User dir import for pi user returned error" + process="Create consolepi user/group" # add consolepi user @@ -216,7 +223,10 @@ pre_git_prep() { echo -e "\nAdding 'consolepi' user. Please provide credentials for 'consolepi' user..." ask_pass # provides _pass in global context echo -e "${_pass}\n${_pass}\n" | adduser --conf /tmp/adduser.conf --gecos "" consolepi >/dev/null 2>> $log_file && - logit "consolepi user created." || logit "Error creating consolepi user" "ERROR" + ( + logit "consolepi user created." + do_user_dir_import consolepi || logit -L "User dir import for consolepi user returned error" + ) || logit "Error creating consolepi user" "ERROR" unset _pass fi echo @@ -248,13 +258,15 @@ pre_git_prep() { logit "Successfully added new user $result" # -- Copy Prep pre-staged files if they exist (stage-dir/home/) for newly created user. - if [[ -d "$stage_dir/home/$result" ]]; then - logit "Found staged files for $result, copying to users home" - chown -R $(grep "^$result:" /etc/passwd | cut -d: -f3-4) "$stage_dir/home/$result" && - cp -r "$stage_dir/home/$result" "/home/$result" && - logit "Success - copy staged files for user $result" || - logit "An error occured when attempting cp pre-staged files for user $result" "WARNING" - fi + do_user_dir_import $result || logit -L "User dir import for $result user returned error" + + # if [[ -d "$stage_dir/home/$result" ]]; then + # logit "Found staged files for $result, copying to users home" + # chown -R $(grep "^$result:" /etc/passwd | cut -d: -f3-4) "$stage_dir/home/$result" && + # cp -r "$stage_dir/home/$result" "/home/$result" && + # logit "Success - copy staged files for user $result" || + # logit "An error occured when attempting cp pre-staged files for user $result" "WARNING" + # fi else logit "Error adding new user $result" "WARNING" From 7c88ab55f8afb20b0f1f3d917628866d953c5a78 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 15:19:35 -0500 Subject: [PATCH 25/53] missing || in cmd && pass || fail (consolepi-ahs-dhcp) --- installer/update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/update.sh b/installer/update.sh index 33f7116f..c219a2d2 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -389,7 +389,7 @@ install_autohotspotn () { fi if systemctl is-enabled consolepi-autohotspot-dhcp >/dev/null 2>&1; then systemctl disable consolepi-autohotspot-dhcp 2>>$log_file && - logit "consolepi-autohotspot-dhcp autostart disabled Successfully, startup handled by autohotspot" + logit "consolepi-autohotspot-dhcp autostart disabled Successfully, startup handled by autohotspot" || logit "Failed to disable consolepi-autohotspot-dhcp.service check log" "WARNING" fi else From f4285e223b3d5e63ea18e5edb1b5947305b2d1f7 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 15:28:03 -0500 Subject: [PATCH 26/53] squelch error in logit when testing directly from bash --- installer/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/common.sh b/installer/common.sh index bfa3824b..49916251 100755 --- a/installer/common.sh +++ b/installer/common.sh @@ -175,7 +175,7 @@ logit() { # # NOTE: Sending a status of "ERROR" results in the script exiting # default status is INFO if none provided. - [[ $(basename "$0") == 'dhcpcd.exit-hook' ]] && stop_on_error=false || stop_on_error=true + [[ $(basename "$0" 2>/dev/null) == 'dhcpcd.exit-hook' ]] && stop_on_error=false || stop_on_error=true local args=() while (( "$#" )); do case "$1" in From bc0f1dd37ebb8a72acec5a5a2b4ec787845f52cb Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 15:28:29 -0500 Subject: [PATCH 27/53] Clean Up silent install output @ completion --- installer/update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/update.sh b/installer/update.sh index c219a2d2..6af40e9c 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -1009,7 +1009,7 @@ update_main() { post_install_msg else _msg="Success Silent Install Complete a reboot is required." - [[ "$warn_cnt" > 0 ]] && logit "$_msg\n ${_red}Warnings Occured During Install ($warn_cnt)${_norm}." | cut -d']' -f 3 || echo "$_msg" + [[ "$warn_cnt" > 0 ]] && logit "$_msg\n ${_red}Warnings Occured During Install ($warn_cnt)${_norm}." | cut -d']' -f4- || echo "$_msg" fi $silent && $do_reboot && echo -e "\n${_green}Install Complete${_norm}\n system will reboot in 10 seconds (CTRL+C to abort reboot)" && sleep 10 && $reboot } From 2ba2a7facbe66deeceae46c22c10aad3127bb113 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 16:05:36 -0500 Subject: [PATCH 28/53] stop dnsmasq after install - change order of install_ahs --- installer/update.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/installer/update.sh b/installer/update.sh index 6af40e9c..707a8a2c 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -378,6 +378,20 @@ install_autohotspotn () { process="AutoHotSpotN" logit "Install/Update AutoHotSpotN" + dnsmasq_ver=$(dnsmasq -v 2>/dev/null | head -1 | awk '{print $3}') + if [[ -z "$dnsmasq_ver" ]]; then + process_cmds -apt-install dnsmasq + # disable dnsmasq only if we just installed it + systemctl stop dnsmasq 1>/dev/null 2>> $log_file && + logit "dnsmasq stopped Successfully" || + logit "An error occurred stopping dnsmasq - verify after install" "WARNING" + sudo systemctl disable dnsmasq 1>/dev/null 2>> $log_file && + logit "dnsmasq autostart disabled Successfully" || + logit "An error occurred disabling dnsmasq autostart - verify after install" "WARNING" + else + logit "dnsmasq v${dnsmasq_ver} already installed" + fi + systemd_diff_update autohotspot if ! head -1 /etc/dnsmasq.conf 2>/dev/null | grep -q 'ConsolePi installer' ; then logit "Using New autohotspot specific dnsmasq instance" @@ -396,17 +410,6 @@ install_autohotspotn () { logit "Using old autohotspot system default dnsmasq instance" fi - dnsmasq_ver=$(dnsmasq -v 2>/dev/null | head -1 | awk '{print $3}') - if [[ -z "$dnsmasq_ver" ]]; then - process_cmds -apt-install dnsmasq - # disable dnsmasq only if we just installed it - sudo systemctl disable dnsmasq 1>/dev/null 2>> $log_file && - logit "dnsmasq autostart disabled Successfully" || - logit "An error occurred disabling dnsmasq autostart - verify after install" "WARNING" - else - logit "dnsmasq v${dnsmasq_ver} already installed" - fi - if ! $(which hostapd >/dev/null); then process_cmds -apt-install hostapd else From 9c52ddcce2aa007635b03739539c966165880eb1 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 17:26:08 -0500 Subject: [PATCH 29/53] minor cleanup --- installer/install.sh | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index 83b65e0a..98f5a328 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -197,17 +197,17 @@ pre_git_prep() { echo "pi:${_pass}" | sudo chpasswd 2>> $log_file && logit "Success" || ( logit "Failed to Change Password for pi user" "WARNING" && echo -e "\n!!! There was an issue changing password. Installation will continue, but continue to use existing password and update manually !!!" ) - unset _pass; unset process + unset _pass fi fi fi + # import any pi user stuff after header so usesr can see the import msg + header do_user_dir_import pi || logit -L "User dir import for pi user returned error" process="Create consolepi user/group" - # add consolepi user - header cp /etc/adduser.conf /tmp/adduser.conf extra_groups="adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio" extra_groups2="consolepi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio" @@ -303,7 +303,8 @@ pre_git_prep() { # fi # fi fi - # -- // Operations performed on both installs and upgrades \\ -- + + # -- // OPERATIONS PERFORMED ON BOTH INSTALLS AND UPGRADES \\ -- # Give consolepi group sudo rights without passwd to stuff in the ConsolePi dir if [ ! -f /etc/sudoers.d/010_consolepi ]; then @@ -319,6 +320,7 @@ pre_git_prep() { unset process fi + # -- Verify cloud cache is owned by consolepi group if [ -f $cloud_cache ]; then process="ConsolePi-Upgrade-Prep (check cache owned by consolepi group)" group=$(stat -c '%G' $cloud_cache) @@ -332,6 +334,7 @@ pre_git_prep() { unset process fi + # -- verify Group owndership and permissions of /etc/ConsolePi and .git dir if [ -d $consolepi_dir ]; then process="ConsolePi-Upgrade-Prep (verify permissions)" @@ -438,24 +441,17 @@ do_pyvenv() { fi if $dopip; then - # if $upgrade; then - # -- update pip to current -- logit "Upgrade pip" sudo ${consolepi_dir}venv/bin/python3 -m pip install --upgrade pip 1>/dev/null 2>> $log_file && logit "Success - pip upgrade" || logit "WARNING - pip upgrade returned error" "WARNING" - # fi - # -- *Always* update venv packages based on requirements file -- - # [ ! -z $py3ver ] && [ $py3ver -lt 6 ] && req_file="requirements-legacy.txt" || req_file="requirements.txt" + # -- Update venv packages based on requirements file -- logit "pip install/upgrade ConsolePi requirements - This can take some time." echo -e "\n-- Output of \"pip install --upgrade -r ${consolepi_dir}installer/requirements.txt\" --\n" sudo ${consolepi_dir}venv/bin/python3 -m pip install --upgrade -r ${consolepi_dir}installer/requirements.txt 2> >(grep -v "WARNING: Retrying " | tee -a $log_file >&2) && ( echo; logit "Success - pip install/upgrade ConsolePi requirements" ) || logit "Error - pip install/upgrade ConsolePi requirements" "ERROR" - - # clean up the retry logs if pip install requirements was successful - # grep -q "^.*Success.*pip install.*requirements" $log_file && sed -i '/WARNING: Retrying (Retry.*/d' $log_file else logit "pip upgrade / requirements upgrade skipped based on -nopip argument" "WARNING" fi @@ -714,5 +710,4 @@ main() { fi } -# process_args "$@" main "$@" From e9b99c79a3e91b0a4a00fdda79303e3fbfd31259 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 17:26:56 -0500 Subject: [PATCH 30/53] fix pcmd logic in process_cmds() --- installer/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/common.sh b/installer/common.sh index 49916251..f7025c9e 100755 --- a/installer/common.sh +++ b/installer/common.sh @@ -713,7 +713,7 @@ process_cmds() { # if cmd is set process cmd # use defaults if flag not set if [[ ! -z $cmd ]]; then - local pcmd=${cmd/sudo /} ; local pcmd=${cmd/-y /} + local pcmd=${cmd/sudo /} ; local pcmd=${pcmd/-y /} local pmsg=${pmsg:-"Success - $pcmd"} unset pcmd # local pmsg=${pmsg:-"Success - ${cmd/-y /}"} From ce3044d3ce0401e71571d64a3bc2bf9f53080570 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 17:27:26 -0500 Subject: [PATCH 31/53] minor orginization / cleanup --- installer/update.sh | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/installer/update.sh b/installer/update.sh index 707a8a2c..b3615d02 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -173,7 +173,7 @@ misc_imports(){ overlay_success=true || overlay_success=false if $overlay_success; then sudo mv /tmp/rpi-poe.dtbo /boot/overlays 2>> $log_file && - logit "Successfully moved overlay file, will activate on boot" || + logit "Success moved overlay file, will activate on boot" || logit "Failed to move overlay file" else logit "Failed to create Overlay file from dts" @@ -365,11 +365,7 @@ install_ovpn() { fi sudo chmod 600 /etc/openvpn/client/* 1>/dev/null 2>> $log_file || logit "Failed chmod 600 openvpn client files" "WARNING" - unset process -} -ovpn_graceful_shutdown() { - process="OpenVPN Graceful Shutdown" systemd_diff_update "ovpn-graceful-shutdown" unset process } @@ -419,7 +415,7 @@ install_autohotspotn () { # -- override_dir set in common.sh [[ -f ${override_dir}/hostapd.service ]] && hostapd_override=true || hostapd_override=false - [[ -f ${override_dir}/dnsmasq.service ]] && dnsmasq_override=true || dnsmasq_override=false # No Longer Used + # [[ -f ${override_dir}/dnsmasq.service ]] && dnsmasq_override=true || dnsmasq_override=false # No Longer Used if ! $hostapd_override ; then logit "disabling hostapd (handled by AutoHotSpotN)." sudo systemctl unmask hostapd.service 1>/dev/null 2>> $log_file && @@ -973,10 +969,7 @@ update_main() { install_ser2net dhcp_run_hook ConsolePi_cleanup - if $ovpn_enable; then - install_ovpn - ovpn_graceful_shutdown - fi + $ovpn_enable && install_ovpn if $hotspot ; then install_autohotspotn gen_dnsmasq_conf @@ -991,9 +984,7 @@ update_main() { ! $upgrade && misc_stuff do_resize if ( [ ! -z "$skip_utils" ] && $skip_utils ) || $silent; then - process="optional utilities installer" - logit "utilities menu bypassed by config variable" - unset process + logit -t "optional utilities installer" "utilities menu bypassed by config variable" else get_utils util_main @@ -1003,8 +994,7 @@ update_main() { get_known_ssids get_serial_udev else - process="Configure WLAN - Predictable Console Ports" - logit "Prompts bypassed due to -silent flag" + logit -t "Configure WLAN - Predictable Console Ports" "Prompts bypassed due to -silent flag" fi custom_post_install_script process=Complete From 693da7bde1a6cbb2a63e1ad89d719ce091147b2e Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 17:57:06 -0500 Subject: [PATCH 32/53] WIP elliminate multiple PB msgs w/ multiple interfaces --- src/dhcpcd.exit-hook | 12 ++++++++++-- src/systemd/ConsolePi_cleanup | 12 ++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/dhcpcd.exit-hook b/src/dhcpcd.exit-hook index 82864605..54a6332c 100755 --- a/src/dhcpcd.exit-hook +++ b/src/dhcpcd.exit-hook @@ -287,8 +287,16 @@ run() { Check_is_new_ip if $is_new_ip; then - BuildMsg "bound" - $push && Push + # -- if delay lock file not in place delay 10 seconds if it is gen msg and send now. + # -- Prevents multiple messages when multiple interfaces come up with new IPs (or OpenVPN connects) + [[ ! -f /tmp/consolepi-push-delay.lock ]] && touch /tmp/consolepi-push-delay.lock && sleep 10 + if [[ -f /tmp/consolepi-push-delay.lock ]]; then + rm /tmp/consolepi-push-delay.lock + BuildMsg "bound" + $push && Push + else + logit -L -t puship "Push Message deffered based on $interface IP change ($new_ip_address), sent by another interface" + fi $cloud && update_cloud $ovpn_enable && Check_VPN else diff --git a/src/systemd/ConsolePi_cleanup b/src/systemd/ConsolePi_cleanup index 3c2879ad..6619bd45 100644 --- a/src/systemd/ConsolePi_cleanup +++ b/src/systemd/ConsolePi_cleanup @@ -1,10 +1,10 @@ #!/bin/sh # ### BEGIN INIT INFO -# Provides: +# Provides: # Required-Start: -# Required-Stop: -# Should-Start: +# Required-Stop: +# Should-Start: # Should-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 @@ -14,9 +14,9 @@ case "$1" in start|stop) - for i in eth0 wlan0 tun0 tun1 tun2 tun3 tun4 tun5; do + for i in eth0 wlan0 consolepi-push-delay.lock tun0 tun1 tun2 tun3 tun4 tun5; do i="/tmp/$i" - [ -e $i ] && rm $i + [ -e $i ] && rm $i done echo puship-ConsolePiCleanUp CleanUp Complete exit 0 @@ -24,5 +24,5 @@ start|stop) *) echo Error valid options are start stop exit 1 - ;; + ;; esac From 450d87bf9a4da2238a8a49d8400c589c81117d36 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 18:19:39 -0500 Subject: [PATCH 33/53] move auto_launch installer to .profile --- installer/consolepi-image-creator.sh | 2 +- installer/install.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/installer/consolepi-image-creator.sh b/installer/consolepi-image-creator.sh index 04e3a26f..c9f3d048 100755 --- a/installer/consolepi-image-creator.sh +++ b/installer/consolepi-image-creator.sh @@ -619,7 +619,7 @@ main() { fi $LOCAL_DEV && cmd_line="-dev $cmd_line" - grep -q "consolepi-install" $IMG_HOME/.bashrc || echo "consolepi-install ${cmd_line}" >> $IMG_HOME/.bashrc + grep -q "consolepi-install" $IMG_HOME/.profile || echo "consolepi-install ${cmd_line}" >> $IMG_HOME/.profile # make install command/script executable sudo chmod +x /mnt/usb2/usr/local/bin/consolepi-install && diff --git a/installer/install.sh b/installer/install.sh index 98f5a328..bf6ad63f 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -52,9 +52,9 @@ get_common() { remove_first_boot() { # SD-Card created using Image Creator Script launches installer automatically - remove first-boot launch process="Remove exec on first-boot" - sudo sed -i "s#consolepi-install.*##g" /home/pi/.bashrc - grep -q consolepi-install /home/pi/.bashrc && - logit "Failed to remove first-boot verify /etc/rc.local" "WARNING" + sudo sed -i "s#consolepi-install.*##g" /home/pi/.profile + grep -q consolepi-install /home/pi/.profile && + logit "Failed to remove first-boot verify /home/pi/.profile" "WARNING" } do_apt_update() { From 46c414d27df7d3be606edaaebd47c5a6be7e063c Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 18:20:13 -0500 Subject: [PATCH 34/53] fix auto-reboot on silent install $reboot --> reboot --- installer/update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/update.sh b/installer/update.sh index b3615d02..9a199df6 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -1004,7 +1004,7 @@ update_main() { _msg="Success Silent Install Complete a reboot is required." [[ "$warn_cnt" > 0 ]] && logit "$_msg\n ${_red}Warnings Occured During Install ($warn_cnt)${_norm}." | cut -d']' -f4- || echo "$_msg" fi - $silent && $do_reboot && echo -e "\n${_green}Install Complete${_norm}\n system will reboot in 10 seconds (CTRL+C to abort reboot)" && sleep 10 && $reboot + $silent && $do_reboot && echo -e "\n${_green}Install Complete${_norm}\n system will reboot in 10 seconds (CTRL+C to abort reboot)" && sleep 10 && reboot } # ( set -o posix ; set ) | grep -v _xspecs | grep -v LS_COLORS # DEBUG Line From 8f36d1bc199836f9f68e41a1fabbe17c9a8156f2 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 18:41:27 -0500 Subject: [PATCH 35/53] pre-stage user-dir imports --- installer/consolepi-image-creator.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/installer/consolepi-image-creator.sh b/installer/consolepi-image-creator.sh index c9f3d048..284d9143 100755 --- a/installer/consolepi-image-creator.sh +++ b/installer/consolepi-image-creator.sh @@ -187,6 +187,19 @@ get_input() { # return input (input is set globally) } +do_user_dir_import(){ + [[ $1 == root ]] && local user_home=root || local user_home="home/$1" + # -- Copy Prep pre-staged files if they exist (stage-dir/home/) for newly created user. + if [[ -d "$STAGE_DIR/$user_home" ]]; then + logit "Found staged files for $1, copying to users home" + chown -R $(grep "^$1:" /etc/passwd | cut -d: -f3-4) "$STAGE_DIR/$user_home" && + cp -r "$STAGE_DIR/$user_home" "/mnt/usb2/$user_home" && + ( logit "Success - copy staged files for user $1" && return 0 ) || + ( logit "An error occured when attempting cp pre-staged files for user $1" "WARNING" + return 1 + ) + fi +} show_disk_details() { echo -e "------------------------------- // Device Details for $(green "$my_usb") \\\\\ -----------------------------------" @@ -243,6 +256,9 @@ do_import_configs() { cp ${CUR_DIR}/$STAGE_DIR/known_hosts /mnt/usb2/root/.ssh/ ; do_error $((rc+=$?)) fi + do_user_dir_import root + do_user_dir_import pi + # -- adjust perms in .ssh directory if created imported -- if [[ -d $IMG_HOME/.ssh ]]; then dots "Set Ownership of $IMG_HOME/.ssh" From 03e287d015b2bde955f290a8c2923c83dd643dc8 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 18:41:43 -0500 Subject: [PATCH 36/53] skip pi pas change when silent and no pi_pass provided --- installer/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/install.sh b/installer/install.sh index bf6ad63f..bebbf68c 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -187,7 +187,7 @@ pre_git_prep() { if [ ! -z "$pi_pass" ]; then echo "pi:${pi_pass}" | chpasswd 2>> $log_file && logit "Successfully changed pi password using conf/cmd_line arg" || logit "Error occured changing pi password using conf/cmd_line arg" "WARNING" - else + elif ! $silent header echo "You are logged in as pi, and the default password has not been changed" prompt="Do You want to change the password for user pi" From ccf51360afb3b3aa08b70ed8ab1401f07316b3a9 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 19:20:00 -0500 Subject: [PATCH 37/53] Display dev mode in title when enabled --- installer/consolepi-image-creator.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/installer/consolepi-image-creator.sh b/installer/consolepi-image-creator.sh index 284d9143..9b2193d5 100755 --- a/installer/consolepi-image-creator.sh +++ b/installer/consolepi-image-creator.sh @@ -452,9 +452,12 @@ main() { fi [[ $my_usb ]] && boot_list=($(sudo fdisk -l |grep -o '/dev/sd[a-z][0-9] \*'| cut -d'/' -f3| awk '{print $1}')) [[ $boot_list =~ $my_usb ]] && my_usb= # if usb device found make sure it's not marked as bootable if so reset my_usb so we can check for sd card adapter + # basename $(mount | grep 'on / '|awk '{print $1}') [[ -z $my_usb ]] && my_usb=$( sudo fdisk -l | grep 'Disk /dev/mmcblk' | awk '{print $2}' | cut -d: -f1 | cut -d'/' -f3) - echo -e "\n\n$(green "ConsolePi Image Creator") \n'exit' (which will terminate the script) is valid at all prompts\n" + ! $LOCAL_DEV && SCRIPT_TITLE=$(green "ConsolePi Image Creator") || SCRIPT_TITLE="${_green}ConsolePi Image Creator${_norm} ${_lred}${_blink}Local DEV${_norm}" + echo -e "\n\n$SCRIPT_TITLE \n'exit' (which will terminate the script) is valid at all prompts\n" + [[ $my_usb ]] && echo -e "Script has discovered removable flash device @ $(green "${my_usb}") with the following details\n" || echo -e "Script failed to detect removable flash device, you will need to specify the device" From eaa4ae6377a76076e2b15de818e877d9aaf1f14d Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 20:05:08 -0500 Subject: [PATCH 38/53] fix elif syntax in pi pass change --- installer/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/install.sh b/installer/install.sh index bebbf68c..06f79577 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -187,7 +187,7 @@ pre_git_prep() { if [ ! -z "$pi_pass" ]; then echo "pi:${pi_pass}" | chpasswd 2>> $log_file && logit "Successfully changed pi password using conf/cmd_line arg" || logit "Error occured changing pi password using conf/cmd_line arg" "WARNING" - elif ! $silent + elif ! $silent; then header echo "You are logged in as pi, and the default password has not been changed" prompt="Do You want to change the password for user pi" From e7bacd0a3b2b799c9978e1ed69484b85fe0e5f15 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 20:05:29 -0500 Subject: [PATCH 39/53] fix user dir import --- installer/consolepi-image-creator.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/installer/consolepi-image-creator.sh b/installer/consolepi-image-creator.sh index 9b2193d5..bb5476dd 100755 --- a/installer/consolepi-image-creator.sh +++ b/installer/consolepi-image-creator.sh @@ -191,13 +191,12 @@ do_user_dir_import(){ [[ $1 == root ]] && local user_home=root || local user_home="home/$1" # -- Copy Prep pre-staged files if they exist (stage-dir/home/) for newly created user. if [[ -d "$STAGE_DIR/$user_home" ]]; then - logit "Found staged files for $1, copying to users home" - chown -R $(grep "^$1:" /etc/passwd | cut -d: -f3-4) "$STAGE_DIR/$user_home" && - cp -r "$STAGE_DIR/$user_home" "/mnt/usb2/$user_home" && - ( logit "Success - copy staged files for user $1" && return 0 ) || - ( logit "An error occured when attempting cp pre-staged files for user $1" "WARNING" - return 1 - ) + dots "Found staged files for $1, cp to ${1}'s home on image" + res=$( + chown -R $(grep "^$1:" /mnt/usb2/etc/passwd | cut -d: -f3-4) "$STAGE_DIR/$user_home" 2>&1 && + cp -r "$STAGE_DIR/$user_home/." "/mnt/usb2/$user_home/" 2>&1 + ) && + ( do_error $? && return 0 ) || ( do_error $? "$res" && return 1 ) fi } From 76dd6b8f02bcbc2bda8d672c6e3a7c31c84752ad Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 20:32:01 -0500 Subject: [PATCH 40/53] squelch ioctl log for non tty --- installer/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/common.sh b/installer/common.sh index f7025c9e..0187211a 100755 --- a/installer/common.sh +++ b/installer/common.sh @@ -7,7 +7,7 @@ # wired_dhcp=false # temp until a config option cur_dir=$(pwd) iam=${SUDO_USER:-$(who -m | awk '{ print $1 }')} -tty_cols=$(stty -a | grep -o "columns [0-9]*" | awk '{print $2}') +tty_cols=$(stty -a 2>/dev/null | grep -o "columns [0-9]*" | awk '{print $2}') consolepi_dir="/etc/ConsolePi/" src_dir="${consolepi_dir}src/" bak_dir="${consolepi_dir}bak/" From dc7e4b96f19bb9af93bee419a4cc6d974e9ff98a Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 20:33:05 -0500 Subject: [PATCH 41/53] log auto_launch success/failure --- installer/install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index 06f79577..039fcf9a 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -233,11 +233,14 @@ pre_git_prep() { fi if [ ! -z "${auto_launch}" ]; then - echo -e '\n#Auto-Launch consolepi-menu on login\nconsolepi-menu' >> /home/consolepi/.profile + echo -e '\n# Auto-Launch consolepi-menu on login\nconsolepi-menu' >> /home/consolepi/.profile && + logit "consolepi user configured to auto-launch menu on login" || + logit "Failed to cofnigure auto-launch menu on login for consolepi user" else if ! $silent; then user_input true "Make consolepi user auto-launch menu on login" - $result && echo -e '\n#Auto-Launch consolepi-menu on login\nconsolepi-menu' >> /home/consolepi/.profile + $result && echo -e '\n# Auto-Launch consolepi-menu on login\nconsolepi-menu' >> /home/consolepi/.profile || + logit "Failed to cofnigure auto-launch menu on login for consolepi user" else logit "consolepi user auto-launch menu bypassed -silent install lacking --auto_launch flag=" fi From 55ab5e8740b8d461505b3212c47137cd3763d55c Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 20:56:22 -0500 Subject: [PATCH 42/53] revert stderr redir on -t test does nothing --- src/autohotspotN | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/autohotspotN b/src/autohotspotN index b4efba69..d7b1d3ab 100755 --- a/src/autohotspotN +++ b/src/autohotspotN @@ -88,7 +88,7 @@ logit() { # -- Any warning/errors log to syslog/stdout as well -- if [[ ! "${status}" == "INFO" ]] && [[ ! "${status}" == "DEBUG" ]]; then - if [ -t 1 2>/dev/null ]; then + if [ -t 1 ]; then echo -e "[${c_status}] ${message}" # log any errors to syslog as well else echo -e "[${status}] ${no_color_msg}" # log any errors to syslog as well @@ -100,7 +100,7 @@ logit() { fi else # -- Always Log to stdout if this is a tty -- - [ -t 1 2>/dev/null ] && echo -e "[${c_status}][${process}] ${message}" + [ -t 1 ] && echo -e "[${c_status}][${process}] ${message}" fi return 0 } From 710e49b647dea6c397a835b534d842fefc2c1152 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 20:58:43 -0500 Subject: [PATCH 43/53] revert push delay, too long between interface up --- src/dhcpcd.exit-hook | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/dhcpcd.exit-hook b/src/dhcpcd.exit-hook index 54a6332c..29f04b42 100755 --- a/src/dhcpcd.exit-hook +++ b/src/dhcpcd.exit-hook @@ -210,11 +210,6 @@ Check_is_new_ip() { $is_new_ip && StashNewIP } -# update_cloud() { -# /etc/ConsolePi/cloud/${cloud_svc}/cloud.py && -# logit -L -t puship-${cloud_svc} Updated cloud Config || -# logit -L -t puship-${cloud_svc} Error returned while Updating cloud Config -# } update_cloud() { logit -L -t puship-${cloud_svc} "Triggering Update in background" @@ -287,16 +282,8 @@ run() { Check_is_new_ip if $is_new_ip; then - # -- if delay lock file not in place delay 10 seconds if it is gen msg and send now. - # -- Prevents multiple messages when multiple interfaces come up with new IPs (or OpenVPN connects) - [[ ! -f /tmp/consolepi-push-delay.lock ]] && touch /tmp/consolepi-push-delay.lock && sleep 10 - if [[ -f /tmp/consolepi-push-delay.lock ]]; then - rm /tmp/consolepi-push-delay.lock - BuildMsg "bound" - $push && Push - else - logit -L -t puship "Push Message deffered based on $interface IP change ($new_ip_address), sent by another interface" - fi + BuildMsg "bound" + $push && Push $cloud && update_cloud $ovpn_enable && Check_VPN else From 15f2447d30992b9d8fd12a94b03818622e53cd70 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 23:13:12 -0500 Subject: [PATCH 44/53] tweaks in user_dir_import and auto_launch --- installer/install.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index 039fcf9a..1acbaab9 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -113,7 +113,7 @@ do_user_dir_import(){ if [[ -d "$stage_dir/$user_home" ]]; then logit "Found staged files for $1, copying to users home" chown -R $(grep "^$1:" /etc/passwd | cut -d: -f3-4) "$stage_dir/$user_home" && - cp -r "$stage_dir/$user_home" "/$user_home" && + cp -r "$stage_dir/$user_home/." "/$user_home/" && ( logit "Success - copy staged files for user $1" && return 0 ) || ( logit "An error occured when attempting cp pre-staged files for user $1" "WARNING" return 1 @@ -232,17 +232,20 @@ pre_git_prep() { echo fi - if [ ! -z "${auto_launch}" ]; then - echo -e '\n# Auto-Launch consolepi-menu on login\nconsolepi-menu' >> /home/consolepi/.profile && - logit "consolepi user configured to auto-launch menu on login" || - logit "Failed to cofnigure auto-launch menu on login for consolepi user" - else - if ! $silent; then - user_input true "Make consolepi user auto-launch menu on login" - $result && echo -e '\n# Auto-Launch consolepi-menu on login\nconsolepi-menu' >> /home/consolepi/.profile || + # -- consolepi user auto-launch menu (The grep verification is for re-testing scenarios to prevent duplicate lines) + if ! grep -q "^consolepi-menu" /home/consolepi/.profile; then + if [ ! -z "${auto_launch}" ]; then + echo -e '\n# Auto-Launch consolepi-menu on login\nconsolepi-menu' >> /home/consolepi/.profile && + logit "consolepi user configured to auto-launch menu on login" || logit "Failed to cofnigure auto-launch menu on login for consolepi user" else - logit "consolepi user auto-launch menu bypassed -silent install lacking --auto_launch flag=" + if ! $silent; then + user_input true "Make consolepi user auto-launch menu on login" + $result && ( echo -e '\n# Auto-Launch consolepi-menu on login\nconsolepi-menu' >> /home/consolepi/.profile || + logit "Failed to cofnigure auto-launch menu on login for consolepi user" ) + else + logit "consolepi user auto-launch menu bypassed -silent install lacking --auto_launch flag=" + fi fi fi @@ -693,8 +696,10 @@ main() { script_iam=`whoami` if [ "${script_iam}" = "root" ]; then set +H # Turn off ! history expansion + cmd_line="$@" process_args "$@" get_common # get and import common functions script + [ ! -z "$cmd_line" ] && logit -L -t "ConsolePi Installer" "Called with the following args: $cmd_line" get_pi_info # (common.sh func) Collect some version info for logging remove_first_boot # if auto-launch install on first login is configured remove do_apt_update # apt-get update the pi From 31fd3ebf6f966dfe73e7e2e12c6032b6767f7fcb Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 23:14:44 -0500 Subject: [PATCH 45/53] change start target wants/after derictives. Stagger starts --- src/systemd/consolepi-api.service | 4 +++- src/systemd/consolepi-mdnsbrowse.service | 5 +++-- src/systemd/consolepi-mdnsreg.service | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/systemd/consolepi-api.service b/src/systemd/consolepi-api.service index 99d70cce..6bb74f73 100644 --- a/src/systemd/consolepi-api.service +++ b/src/systemd/consolepi-api.service @@ -1,7 +1,9 @@ [Unit] Description=ConsolePi API: facilitates ConsolePis sharing info in Cluster +Documentation=https://github.com/Pack3tL0ss/ConsolePi DefaultDependencies=no -After=networking.service +After=network-online.target +Wants=network-online.target StartLimitInterval=200 StartLimitBurst=5 diff --git a/src/systemd/consolepi-mdnsbrowse.service b/src/systemd/consolepi-mdnsbrowse.service index 35712e83..3431252f 100644 --- a/src/systemd/consolepi-mdnsbrowse.service +++ b/src/systemd/consolepi-mdnsbrowse.service @@ -1,8 +1,9 @@ [Unit] Description=Browse for remote ConsolePis via mdns and update local cache +Documentation=https://github.com/Pack3tL0ss/ConsolePi DefaultDependencies=no -After=network-online.target -Wants=network-online.target +Wants=consolepi-mdnsreg.service +After=consolepi-mdnsreg.service StartLimitInterval=200 StartLimitBurst=5 diff --git a/src/systemd/consolepi-mdnsreg.service b/src/systemd/consolepi-mdnsreg.service index 00104e09..5290938a 100644 --- a/src/systemd/consolepi-mdnsreg.service +++ b/src/systemd/consolepi-mdnsreg.service @@ -1,8 +1,9 @@ [Unit] Description=Advertise ConsolePi and local serial information via mdns +Documentation=https://github.com/Pack3tL0ss/ConsolePi DefaultDependencies=no -After=network-online.target -Wants=network-online.target +After=consolepi-api.service +Wants=consolepi-api.sercice StartLimitInterval=200 StartLimitBurst=5 From 9436e9648fa792bd689996a72dbf5f22621fb3ac Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 23:26:19 -0500 Subject: [PATCH 46/53] change when chown is done in do_user_dir_import --- installer/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/install.sh b/installer/install.sh index 1acbaab9..ecf942f1 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -112,8 +112,8 @@ do_user_dir_import(){ # -- Copy Prep pre-staged files if they exist (stage-dir/home/) for newly created user. if [[ -d "$stage_dir/$user_home" ]]; then logit "Found staged files for $1, copying to users home" - chown -R $(grep "^$1:" /etc/passwd | cut -d: -f3-4) "$stage_dir/$user_home" && cp -r "$stage_dir/$user_home/." "/$user_home/" && + chown -R $(grep "^$1:" /etc/passwd | cut -d: -f3-4) "/$user_home/" && ( logit "Success - copy staged files for user $1" && return 0 ) || ( logit "An error occured when attempting cp pre-staged files for user $1" "WARNING" return 1 From 5f810d75598d43b742d3b30505ccb14cf789b43d Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Thu, 10 Sep 2020 23:42:48 -0500 Subject: [PATCH 47/53] pull user tasks into own function ~ re-order --- installer/install.sh | 125 +++++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 59 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index ecf942f1..b95d93a8 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -121,64 +121,9 @@ do_user_dir_import(){ fi } -# Process Changes that are required prior to git pull when doing upgrade -pre_git_prep() { - if $upgrade; then - - # remove old bluemenu.sh script replaced with consolepi-menu.py - process="ConsolePi-Upgrade-Prep (refactor bluemenu.sh)" - if [[ -f /etc/ConsolePi/src/bluemenu.sh ]]; then - rm /etc/ConsolePi/src/bluemenu.sh && - logit "Removed old menu script will be replaced during pull" || - logit "ERROR Found old menu script but unable to remove (/etc/ConsolePi/src/bluemenu.sh)" "WARNING" - fi - - # Remove old symlink if it exists - process="ConsolePi-Upgrade-Prep (remove symlink consolepi-menu)" - if [[ -L /usr/local/bin/consolepi-menu ]]; then - unlink /usr/local/bin/consolepi-menu && - logit "Removed old consolepi-menu symlink will replace during upgade" || - logit "ERROR Unable to remove old consolepi-menu symlink verify it should link to file in src dir" "WARNING" - fi - - # Remove old launch file if it exists - process="ConsolePi-Upgrade-Prep (remove consolepi-menu quick-launch file)" - if [[ -f /usr/local/bin/consolepi-menu ]]; then - rm /usr/local/bin/consolepi-menu && - logit "Removed old consolepi-menu quick-launch file will replace during upgade" || - logit "ERROR Unable to remove old consolepi-menu quick-launch file" "WARNING" - fi - - # verify group membership -- upgrade only -- checks - process="create consolepi group" - if ! grep -q consolepi /etc/group; then - sudo groupadd consolepi && - logit "Added consolepi group" || - logit "Error adding consolepi group" "WARNING" - else - logit "consolepi group already exists" - fi - process="Verify Group Membership" - [[ "$iam" == "pi" ]] && _users=pi || _users=("pi" "$iam") - _groups=('consolepi' 'dialout') - for user in "${_users[@]}"; do - if ! grep -q "^${user}:" /etc/passwd; then - logit "$user does not exist. Skipping" - continue - fi - for grp in "${_groups[@]}"; do - if [[ ! $(groups $user) == *"${grp}"* ]]; then - sudo usermod -a -G $grp $user && - logit "Added ${user} user to $grp group" || - logit "Error adding ${user} user to $grp group" "WARNING" - else - logit "${user} already belongs to $grp group" - fi - done - done - unset process - - else # -- // ONLY PERFORMED ON FRESH INSTALLS \\ -- +do_users(){ + if ! $upgrade; then + # -- // ONLY PERFORMED ON FRESH INSTALLS \\ -- # Update passwd for pi user if it is the default. process="pi user password change" @@ -308,6 +253,67 @@ pre_git_prep() { # userdel pi 2>> $log_file && logit "pi user removed" || "Error returned when attempting to remove pi user" "WARNING" # fi # fi + + else # --- UPGRADE VERIFICATIONS --- + # verify group membership -- upgrade only -- checks + process="create consolepi group" + if ! grep -q consolepi /etc/group; then + sudo groupadd consolepi && + logit "Added consolepi group" || + logit "Error adding consolepi group" "WARNING" + else + logit "consolepi group already exists" + fi + process="Verify Group Membership" + [[ "$iam" == "pi" ]] && _users=pi || _users=("pi" "$iam") + _groups=('consolepi' 'dialout') + for user in "${_users[@]}"; do + if ! grep -q "^${user}:" /etc/passwd; then + logit "$user does not exist. Skipping" + continue + fi + for grp in "${_groups[@]}"; do + if [[ ! $(groups $user) == *"${grp}"* ]]; then + sudo usermod -a -G $grp $user && + logit "Added ${user} user to $grp group" || + logit "Error adding ${user} user to $grp group" "WARNING" + else + logit "${user} already belongs to $grp group" + fi + done + done + fi + +} + +# Process Changes that are required prior to git pull when doing upgrade +pre_git_prep() { + if $upgrade; then + + # remove old bluemenu.sh script replaced with consolepi-menu.py + process="ConsolePi-Upgrade-Prep (refactor bluemenu.sh)" + if [[ -f /etc/ConsolePi/src/bluemenu.sh ]]; then + rm /etc/ConsolePi/src/bluemenu.sh && + logit "Removed old menu script will be replaced during pull" || + logit "ERROR Found old menu script but unable to remove (/etc/ConsolePi/src/bluemenu.sh)" "WARNING" + fi + + # Remove old symlink if it exists + process="ConsolePi-Upgrade-Prep (remove symlink consolepi-menu)" + if [[ -L /usr/local/bin/consolepi-menu ]]; then + unlink /usr/local/bin/consolepi-menu && + logit "Removed old consolepi-menu symlink will replace during upgade" || + logit "ERROR Unable to remove old consolepi-menu symlink verify it should link to file in src dir" "WARNING" + fi + + # Remove old launch file if it exists + process="ConsolePi-Upgrade-Prep (remove consolepi-menu quick-launch file)" + if [[ -f /usr/local/bin/consolepi-menu ]]; then + rm /usr/local/bin/consolepi-menu && + logit "Removed old consolepi-menu quick-launch file will replace during upgade" || + logit "ERROR Unable to remove old consolepi-menu quick-launch file" "WARNING" + fi + unset process fi # -- // OPERATIONS PERFORMED ON BOTH INSTALLS AND UPGRADES \\ -- @@ -702,9 +708,10 @@ main() { [ ! -z "$cmd_line" ] && logit -L -t "ConsolePi Installer" "Called with the following args: $cmd_line" get_pi_info # (common.sh func) Collect some version info for logging remove_first_boot # if auto-launch install on first login is configured remove + do_users # USER INPUT - create / update users and do staged imports do_apt_update # apt-get update the pi do_apt_deps # install dependencies via apt - pre_git_prep # process upgrade tasks required prior to git pull + pre_git_prep # UPGRADE ONLY: process upgrade tasks required prior to git pull git_ConsolePi # git clone or git pull ConsolePi $upgrade && post_git # post git changes do_pyvenv # build upgrade python3 venv for ConsolePi From 025defe827bfffd90bd538fcdcb68bfff938ea3b Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Fri, 11 Sep 2020 00:05:21 -0500 Subject: [PATCH 48/53] improve dhcp_run_hook --- installer/update.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/installer/update.sh b/installer/update.sh index 9a199df6..cb124e35 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -274,17 +274,16 @@ dhcp_run_hook() { process="Configure dhcp.exit-hook" hook_file="/etc/ConsolePi/src/dhcpcd.exit-hook" logit "${process} - Starting" - [[ -f /etc/dhcpcd.exit-hook ]] && exists=true || exists=false # find out if exit-hook file already exists - if $exists; then - is_there=`grep -c $hook_file /etc/dhcpcd.exit-hook` # find out if it's already pointing to ConsolePi script - if [ $is_there -gt 0 ]; then + if [ -f /etc/dhcpcd.exit-hook ]; then + if grep -q $hook_file /etc/dhcpcd.exit-hook; then logit "exit-hook already configured [File Found and Pointer exists]" #exit-hook exists and line is already there else - sudo sed -i '/.*\/etc\/ConsolePi\/.*/c\\/etc\/ConsolePi\/src\/dhcpcd.exit-hook "$@"' /etc/dhcpcd.exit-hook && - logit "Successfully Updated exit-hook Pointer" || logit "Failed to update exit-hook pointer" "ERROR" + echo "$hook_file \"\$@\"" > "/tmp/dhcpcd.exit-hook" + file_diff_update /tmp/dhcpcd.exit-hook /etc/dhcpcd.exit-hook + rm /tmp/dhcpcd.exit-hook >/dev/null 2>>$log_file fi else - sudo echo "$hook_file \"\$@\"" > "/etc/dhcpcd.exit-hook" || logit "Failed to create exit-hook script" "ERROR" + echo "$hook_file \"\$@\"" > "/etc/dhcpcd.exit-hook" || logit "Failed to create exit-hook script" "ERROR" fi # -- Make Sure exit-hook is executable -- From ea1177bb4c9af8808d6f4399051f881178fea9f3 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Fri, 11 Sep 2020 00:12:09 -0500 Subject: [PATCH 49/53] cleanup left over tmp file --- installer/utilities.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installer/utilities.sh b/installer/utilities.sh index e2eec02d..9b775904 100755 --- a/installer/utilities.sh +++ b/installer/utilities.sh @@ -68,9 +68,6 @@ get_util_status () { # PKG_EXPLAIN['wireshark~tshark']="packet capture software" util_list_i=($(for u in ${!UTIL_VER[@]}; do echo $u; done | sort)) util_list_f=($(for u in ${!UTIL_VER[@]}; do echo $u; done | sort -rn)) - # sudo rm /tmp/ansible_ver 2>/dev/null - - sep=': '; i=0; for u in ${util_list_i[@]}; do pretty=${u//_/ } @@ -91,6 +88,9 @@ get_util_status () { fi done # echo -e "---\nDEBUG\n${ASK_OPTIONS[@]}\n---" # -- DEBUG LINE -- + + # -- CLEANUP -- + [ -f /tmp/ansible_ver ] && rm /tmp/ansible_ver 2>>$log_file } do_ask() { From 7b03d046f7d29dc80cea26f798db92e9b14ee43d Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Fri, 11 Sep 2020 00:29:41 -0500 Subject: [PATCH 50/53] minor output tweak in post_install msg --- installer/update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/update.sh b/installer/update.sh index cb124e35..4a44e8f4 100755 --- a/installer/update.sh +++ b/installer/update.sh @@ -896,7 +896,7 @@ post_install_msg() { -li "${_cyan}consolepi-addconsole${_norm}: Configure serial adapter to telnet port rules" -li "${_cyan}consolepi-showaliases${_norm}: Shows Configured adapter aliases, helps identify any issues with aliases" -li "${_cyan}consolepi-logs${_norm}: Displays ConsolePi logs (Note this will install mutli-tail the first time it's ran)" - " valid args: all (will cat consolepi.log), any other argument is passed to tail as a flag." + " valid args: 'all' (will cat consolepi.log), any other argument is passed to tail as a flag." " If no arguments are specified, script will follow tail on consolepi-log, and syslog (with filters)" " examples: \"consolepi-logs all\", \"consolepi-logs -f\", \"consolepi-logs -20\", \"consolepi-logs 20\"" -li "${_cyan}consolepi-killvpn${_norm}: Gracefully terminate openvpn tunnel if one is established" From a7ca83189b83eba7755f06154f1b0a8769a2edfe Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Fri, 11 Sep 2020 02:07:01 -0500 Subject: [PATCH 51/53] version bump --- .static.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.static.yaml b/.static.yaml index cd2664e1..9e8b0061 100644 --- a/.static.yaml +++ b/.static.yaml @@ -2,8 +2,8 @@ # This file should not be modified. Static variables/paths used throughout ConsolePi # Versioning = YYYY.Major.Patch/Minor --- -CONSOLEPI_VER: 2020-4.2 -INSTALLER_VER: 52 +CONSOLEPI_VER: 2020-4.3 +INSTALLER_VER: 53 CFG_FILE_VER: 9 CONFIG_FILE_YAML: /etc/ConsolePi/ConsolePi.yaml CONFIG_FILE: /etc/ConsolePi/ConsolePi.conf # For backward compat, use yaml config going forward From f1349af299cf63ada61c7df45ee620ee6e8f0a42 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Fri, 11 Sep 2020 02:14:22 -0500 Subject: [PATCH 52/53] Remove extra new line in user for remotes prompt --- installer/config.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/installer/config.sh b/installer/config.sh index 619a662f..25b6a234 100755 --- a/installer/config.sh +++ b/installer/config.sh @@ -342,7 +342,6 @@ collect() { if ! $selected_prompts || [ -z "$rem_user" ]; then header [ -z "$rem_user" ] && rem_user=$iam - echo echo "If you have multiple ConsolePis they can discover each other over the network via mdns" echo "and if enabled can sync via Google Drive." echo From 392f4267156cac2bfff6634d27feecf229bf0355 Mon Sep 17 00:00:00 2001 From: wade ~ Pack3tL0ss Date: Fri, 11 Sep 2020 02:44:19 -0500 Subject: [PATCH 53/53] Update v2020-4.3 Installer v --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index b3420af3..c48d051c 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,15 @@ Prior Changes can be found in the - [ChangeLog](changelog.md) - Additionally AutoHotSpot was added as a configurable option, but the prompt didn't display. All of these worked via cmd-line option/silent install. > If you did a fresh install w/ any version from v2020-2.4 - v2020-4.2 you are likely impacted. Just use `sudo passwd consolepi` to set the password as desired. +### Sept 2020 (v2020-4.3) Installer Version 53 Sept 2020 Lots of Installer Tweaks +- This effort was primarily around the Installer and the Image Creator. +- Installer: Tested, re-tested, made enhancements/improvements, added more imports +- Place home/pi home/your-user /root etc. in consolepi-stage dir and run image-creator... + - Image Creator will import home/pi into home/pi on the image, entire directory structure. Same for /root. + - Once the installer runs on the image it will also import /home/pi (redundant, but useful if you don't use the image-creator) + - Installer also prompts to see if you want to create new users, once created if in the consolepi-stage dir it's structure will be imported +> So you can import .ssh keys / known_hosts and any other files/dirs you want in the users home. + # Features ## **Feature Summary Image** @@ -570,6 +579,8 @@ Examples: - The ConsolePi installer will start on first login, as long as the RaspberryPi has internet access. This can be disabled with `--auto_install=false`. > If you set `--auto_install=false`, `--cmd_line=...` is ignored. You would specify arguments for the installer manually. - If the `consolepi-image-creator.sh` script is ran from a ConsolePi, the script will detect that it's a ConsolePi and offer to pre-staage it's existing settings. If a file has alredy been pre-staged (via consolepi-stage dir) it will skip it. It will give you the chance to edit ConsolePi.yaml if pre-staged, so you can deploy multiple ConsolePis and edit the specifics for each as you stage them. +- Entire home directory imports: If you place /root and/or /home/pi inside the consolepi-stage directory. Those contents/subdirs will be imported to the respective users directory on the image. + - You can even pre-stage a users home directory for a user that doesn't exist. When the installer runs, you are given the option to create new users. Once created if a folder is found in consolepi-stage for that user (i.e. `home/pi/consolepi-stage/home/larry`), the contents will be coppied from the `consolepi-stage` dir to `/home/larry`. The install script (not this image-creator, the installer that actually installs ConsolePi) will look for and if found import a number of items from the consolepi-stage directory. Gdrive credentials, ovpn settings, ssh keys refer to *TODO link to section highlighting imports*