From 0556d39b8aa349013075f78557b82719372911db Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Sun, 1 Sep 2024 08:26:13 +0200 Subject: [PATCH 1/2] Add support for changing login shells between ZSH and BASH --- lib/armbian-configng/config.ng.jobs.json | 35 +++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/armbian-configng/config.ng.jobs.json b/lib/armbian-configng/config.ng.jobs.json index f8f52f18..ef567cdf 100644 --- a/lib/armbian-configng/config.ng.jobs.json +++ b/lib/armbian-configng/config.ng.jobs.json @@ -75,8 +75,41 @@ "src_reference": "", "author": "https://github.com/igorpecovnik", "condition": "[[ -n $(ls /sbin/armbian-install) ]]" + }, + { + "id": "S30", + "description": "Change shell system wide to BASH", + "command": [ + "export BASHLOCATION=$(grep /bash$ /etc/shells | tail -1)", + "sed -i \"s|^SHELL=.*|SHELL=${BASHLOCATION}|\" /etc/default/useradd", + "sed -i \"s|^DSHELL=.*|DSHELL=${BASHLOCATION}|\" /etc/adduser.conf", + "debconf-apt-progress -- apt-get -y purge armbian-zsh", + "update_skel", + "awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534 || $3 == 0) print $1}' /etc/passwd | xargs -L1 chsh -s $(grep /bash$ /etc/shells | tail -1)" + ], + "status": "Pending Review", + "doc_link": "", + "src_reference": "", + "author": "https://github.com/igorpecovnik", + "condition": "[[ $(cat /etc/passwd | grep \"^root:\" | rev | cut -d\":\" -f1 | cut -d\"/\" -f1| rev) == \"zsh\" ]]" + }, + { + "id": "S31", + "description": "Change shell system wide to ZSH", + "command": [ + "export ZSHLOCATION=$(grep /zsh$ /etc/shells | tail -1)", + "sed -i \"s|^SHELL=.*|SHELL=${ZSHLOCATION}|\" /etc/default/useradd", + "sed -i \"s|^DSHELL=.*|DSHELL=${ZSHLOCATION}|\" /etc/adduser.conf", + "debconf-apt-progress -- apt-get -y install armbian-zsh", + "update_skel", + "awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534 || $3 == 0) print $1}' /etc/passwd | xargs -L1 chsh -s $(grep /zsh$ /etc/shells | tail -1)" + ], + "status": "Pending Review", + "doc_link": "", + "src_reference": "", + "author": "https://github.com/igorpecovnik", + "condition": "[[ $(cat /etc/passwd | grep \"^root:\" | rev | cut -d\":\" -f1 | cut -d\"/\" -f1| rev) == \"bash\" ]]" } - ] }, { From 9b9bc05be49dea382c0ce5fef09ab848cba5dd05 Mon Sep 17 00:00:00 2001 From: Tearran Date: Sun, 1 Sep 2024 15:19:23 -0400 Subject: [PATCH 2/2] Added system helper file move update_skel and qr_code from PR #49 --- README.md | 50 +++++++++++++++++++++- bin/armbian-configng | 4 +- lib/armbian-configng/config.ng.system.sh | 54 ++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 lib/armbian-configng/config.ng.system.sh diff --git a/README.md b/README.md index f0da46a0..8385a077 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Armbian Configuration Utility -Updated: Thu Aug 29 11:45:21 AM UTC 2024 +Updated: Sun Sep 1 03:03:48 PM EDT 2024 Utility for configuring your board, adjusting services, and installing applications. It comes with Armbian by default. @@ -15,6 +15,9 @@ sudo armbian-config - **S03** - Edit the boot environment - **S04** - Install Linux headers - **S05** - Remove Linux headers + - **S06** - Install to internal storage + - **S30** - Change shell system wide to BASH + - **S31** - Change shell system wide to ZSH - ## **Network** @@ -88,6 +91,9 @@ Usage: armbian-configng [option] [arguments] --cli S03 - Edit the boot environment --cli S04 - Install Linux headers --cli S05 - Remove Linux headers + --cli S06 - Install to internal storage + --cli S30 - Change shell system wide to BASH + --cli S31 - Change shell system wide to ZSH --cli N00 - Install Bluetooth support --cli N01 - Remove Bluetooth support --cli N02 - Bluetooth Discover @@ -194,6 +200,46 @@ Jobs: Headers_remove ~~~ +### S06 + +Install to internal storage + +Jobs: + +~~~ +armbian-install +~~~ + +### S30 + +Change shell system wide to BASH + +Jobs: + +~~~ +export BASHLOCATION=$(grep /bash$ /etc/shells | tail -1) +sed -i "s|^SHELL=.*|SHELL=${BASHLOCATION}|" /etc/default/useradd +sed -i "s|^DSHELL=.*|DSHELL=${BASHLOCATION}|" /etc/adduser.conf +debconf-apt-progress -- apt-get -y purge armbian-zsh +update_skel +awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534 || $3 == 0) print $1}' /etc/passwd | xargs -L1 chsh -s $(grep /bash$ /etc/shells | tail -1) +~~~ + +### S31 + +Change shell system wide to ZSH + +Jobs: + +~~~ +export ZSHLOCATION=$(grep /zsh$ /etc/shells | tail -1) +sed -i "s|^SHELL=.*|SHELL=${ZSHLOCATION}|" /etc/default/useradd +sed -i "s|^DSHELL=.*|DSHELL=${ZSHLOCATION}|" /etc/adduser.conf +debconf-apt-progress -- apt-get -y install armbian-zsh +update_skel +awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534 || $3 == 0) print $1}' /etc/passwd | xargs -L1 chsh -s $(grep /zsh$ /etc/shells | tail -1) +~~~ + ### N00 Install Bluetooth support @@ -447,6 +493,7 @@ These helper functions facilitate various operations related to job management, | Display a Yes/No dialog box and process continue/exit | get_user_continue 'Do you wish to continue?' process_input | Joey Turner | Display a message box | show_message <<< 'hello world' | Joey Turner | Migrated procedures from Armbian config. | connect_bt_interface | Igor Pecovnik +| Show or generate QR code for Google OTP | qr_code generate | Igor Pecovnik | Freeze/unhold Migrated procedures from Armbian config. | set_safe_boot unhold or set_safe_boot freeze | Igor Pecovnik | Check if kernel headers are installed | are_headers_installed | Gunjan Gupta | Check when apt list was last updated | see_current_apt | Joey Turner @@ -472,6 +519,7 @@ These helper functions facilitate various operations related to job management, | Parse json to get list of desired menu or submenu items | parse_menu_items 'menu_options_array' | Gunjan Gupta | Show the usage of the functions. | see_use | Joey Turner | Check the internet connection with fallback DNS | see_ping | Joey Turner +| Update the /etc/skel files in users directories | update_skel | Igor Pecovnik | Secure version of get_user_continue | get_user_continue_secure 'Do you wish to continue?' process_input | Joey Turner diff --git a/bin/armbian-configng b/bin/armbian-configng index 30049d03..e2a442cf 100755 --- a/bin/armbian-configng +++ b/bin/armbian-configng @@ -36,13 +36,15 @@ declare -A module_options # # Load configng core functions and module options array -source "$lib_dir/config.ng.functions.sh" +source "$lib_dir/config.ng.functions.sh" set_runtime_variables echo "Loaded Runtime variables..." #| show_infobox ; #set_newt_colors 2 echo "Loaded Dialog..." #| show_infobox ; source "$lib_dir/config.ng.docs.sh" echo "Loaded Docs..." #| show_infobox ; +source "$lib_dir/config.ng.system.sh" +echo "Loaded System helpers..." #| show_infobox ; source "$lib_dir/config.ng.network.sh" echo "Loaded Network helpers..." #| show_infobox ; diff --git a/lib/armbian-configng/config.ng.system.sh b/lib/armbian-configng/config.ng.system.sh new file mode 100644 index 00000000..54848fbe --- /dev/null +++ b/lib/armbian-configng/config.ng.system.sh @@ -0,0 +1,54 @@ +#!/bin/bash + + +module_options+=( +["update_skel,author"]="Igor Pecovnik" +["update_skel,ref_link"]="" +["update_skel,feature"]="update_skel" +["update_skel,desc"]="Update the /etc/skel files in users directories" +["update_skel,example"]="update_skel" +["update_skel,status"]="Active" +) +# +# check dpkg status of $1 -- currently only 'not installed at all' case caught +# +function update_skel (){ + + getent passwd | + while IFS=: read -r username x uid gid gecos home shell + do + if [ ! -d "$home" ] || [ "$username" == 'root' ] || [ "$uid" -lt 1000 ] + then + continue + fi + tar -C /etc/skel/ -cf - . | su - "$username" -c "tar --skip-old-files -xf -" + done + +} + + +module_options+=( +["qr_code,author"]="Igor Pecovnik" +["qr_code,ref_link"]="" +["qr_code,feature"]="qr_code" +["qr_code,desc"]="Show or generate QR code for Google OTP" +["qr_code,example"]="qr_code generate" +["qr_code,status"]="Active" +) +# +# check dpkg status of $1 -- currently only 'not installed at all' case caught +# +function qr_code (){ + + clear + if [[ "$1" == "generate" ]]; then + google-authenticator -t -d -f -r 3 -R 30 -W -q + cp /root/.google_authenticator /etc/skel + update_skel + fi + export TOP_SECRET=$(head -1 /root/.google_authenticator) + qrencode -m 2 -d 9 -8 -t ANSI256 "otpauth://totp/test?secret=$TOP_SECRET" + echo -e '\nScan QR code with your OTP application on mobile phone\n' + read -n 1 -s -r -p "Press any key to continue" + +}