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 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) 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* diff --git a/installer/common.sh b/installer/common.sh index 34cebec3..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/" @@ -111,29 +111,35 @@ menu_print() { line_len=${line_len:=121} while (( "$#" )); do case "$1" in + -c) + style="$2" + 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" + 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 + 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 @@ -169,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 @@ -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 } @@ -580,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 @@ -598,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 @@ -654,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 @@ -670,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 ;; @@ -703,10 +713,13 @@ process_cmds() { # if cmd is set process cmd # use defaults if flag not set if [[ ! -z $cmd ]]; then - local pmsg=${pmsg:-"Success - $cmd"} + local pcmd=${cmd/sudo /} ; local pcmd=${pcmd/-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} + local _silent=${_silent:-false} local stop=${stop:-false} local err=${err:-$log_file} local out=${out:-'/dev/null'} @@ -714,16 +727,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 -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 - ! $silent && logit "$pmsg" + ! $_silent && logit "$pmsg" unset cmd else local cmd_failed=true @@ -736,7 +748,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 @@ -765,5 +777,5 @@ process_cmds() { logit "Error - apt autoremove returned error-code" "WARNING" fi - return 0 + ! $cmd_failed && return 0 || return 1 } 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 diff --git a/installer/consolepi-image-creator.sh b/installer/consolepi-image-creator.sh index cee19ac9..bb5476dd 100755 --- a/installer/consolepi-image-creator.sh +++ b/installer/consolepi-image-creator.sh @@ -187,6 +187,18 @@ 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 + 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 +} show_disk_details() { echo -e "------------------------------- // Device Details for $(green "$my_usb") \\\\\ -----------------------------------" @@ -243,6 +255,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" @@ -315,7 +330,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}" @@ -436,9 +451,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" @@ -558,8 +576,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" @@ -609,7 +637,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 92b9e0f0..b95d93a8 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() { @@ -90,73 +90,69 @@ 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 + 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 + 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" } -# 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 +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" + 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 + ) + 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" +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" + [ -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" + 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" + response=$(user_input_bool) + if $response; then + ask_pass + 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 + fi + fi 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 + # 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" - else # -- // ONLY PERFORMED ON FRESH INSTALLS \\ -- 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" @@ -172,25 +168,35 @@ 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 fi - if [ ! -z "${auto_launch}" ]; then - echo -e '\n#Auto-Launch consolepi-menu on login\nconsolepi-menu' >> /home/consolepi/.profile - 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 # 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 @@ -203,13 +209,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" @@ -221,6 +229,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 @@ -244,16 +253,71 @@ 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 - # -- // 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" +} + +# 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 \\ -- + # 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" @@ -268,13 +332,7 @@ 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 - + # -- 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) @@ -288,6 +346,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)" @@ -394,24 +453,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 @@ -650,13 +702,16 @@ 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_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 @@ -670,5 +725,4 @@ main() { fi } -# process_args "$@" main "$@" diff --git a/installer/update.sh b/installer/update.sh index 1b1f3f55..4a44e8f4 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") + 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 + fi + + # -- ssh known hosts -- + found_path=$(get_staged_file_path "known_hosts") + 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 + 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 "Success 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 } @@ -304,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 -- @@ -395,11 +364,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 } @@ -408,7 +373,20 @@ install_autohotspotn () { process="AutoHotSpotN" logit "Install/Update AutoHotSpotN" - # TODO check logic here, double check consolepi-autohotspot-dhcp is being disabled after install + 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" @@ -418,8 +396,9 @@ 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 @@ -433,16 +412,9 @@ install_autohotspotn () { 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 - else - logit "dnsmasq v${dnsmasq_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 && @@ -455,13 +427,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" @@ -557,7 +522,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 } @@ -767,8 +733,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 @@ -790,7 +757,6 @@ get_serial_udev() { process="Predictable Console Ports" logit "${process} Starting" header - echo echo -e "--------------------------------------------- ${_green}Predictable Console ports${_norm} ---------------------------------------------" echo "- -" @@ -800,8 +766,8 @@ get_serial_udev() { 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 -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 -" @@ -812,8 +778,8 @@ get_serial_udev() { 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 @@ -879,7 +845,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}" @@ -930,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" @@ -993,20 +959,16 @@ 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 - if $ovpn_enable; then - install_ovpn - ovpn_graceful_shutdown - fi + $ovpn_enable && install_ovpn if $hotspot ; then install_autohotspotn gen_dnsmasq_conf @@ -1021,9 +983,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 @@ -1033,8 +993,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 @@ -1042,9 +1001,9 @@ 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 + $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 diff --git a/installer/utilities.sh b/installer/utilities.sh index d52de501..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() { @@ -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 diff --git a/src/autohotspotN b/src/autohotspotN index 079350ef..d7b1d3ab 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 ]; 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 @@ -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 } diff --git a/src/dhcpcd.exit-hook b/src/dhcpcd.exit-hook index 82864605..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" 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 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 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