Skip to content

Commit

Permalink
ZSH: move functions from JSON to separate modules
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Nov 6, 2024
1 parent f058282 commit 7ea3744
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
18 changes: 2 additions & 16 deletions tools/json/config.system.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,7 @@
"id": "SY008",
"description": "Change shell system wide to BASH",
"about": "This will switch system wide shell 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",
"apt_install_wrapper apt-get -y purge armbian-zsh zsh-common zsh tmux",
"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)"
],
"command": [ "manage_zsh disable" ],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "[[ $(cat /etc/passwd | grep \"^root:\" | rev | cut -d\":\" -f1 | cut -d\"/\" -f1| rev) == \"zsh\" ]]"
Expand All @@ -230,14 +223,7 @@
"id": "SY009",
"description": "Change shell system wide to ZSH",
"about": "This will switch system wide shell 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",
"apt_install_wrapper apt-get -y install armbian-zsh zsh-common zsh tmux",
"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)"
],
"command": [ "manage_zsh enable" ],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "[[ $(cat /etc/passwd | grep \"^root:\" | rev | cut -d\":\" -f1 | cut -d\"/\" -f1| rev) == \"bash\" ]]"
Expand Down
47 changes: 47 additions & 0 deletions tools/modules/system/manage_zsh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module_options+=(
["manage_zsh,author"]="@igorpecovnik"
["manage_zsh,ref_link"]=""
["manage_zsh,feature"]="manage_zsh"
["manage_zsh,desc"]="Set system shell to BASH"
["manage_zsh,example"]="manage_zsh enable|disable"
["manage_zsh,status"]="Active"
)
#
# @description Set system shell to ZSH
#
function manage_zsh() {

local bash_location=$(grep /bash$ /etc/shells | tail -1)
local zsh_location=$(grep /zsh$ /etc/shells | tail -1)

if [[ "$1" == "enable" ]]; then

sed -i "s|^SHELL=.*|SHELL=/bin/zsh|" /etc/default/useradd
sed -i -E "s|(^\|#)DSHELL=.*|DSHELL=/bin/zsh|" /etc/adduser.conf

# install
apt_install_wrapper apt-get -y install armbian-zsh zsh-common zsh tmux

update_skel

# change shell for root
usermod --shell "/bin/zsh" root
# change shell for others
sed -i 's/bash$/zsh/g' /etc/passwd

else

sed -i "s|^SHELL=.*|SHELL=/bin/bash|" /etc/default/useradd
sed -i -E "s|(^\|#)DSHELL=.*|DSHELL=/bin/bash|" /etc/adduser.conf

# remove
apt_install_wrapper apt-get -y remove armbian-zsh zsh-common zsh tmux

# change shell for root
usermod --shell "/bin/bash" root
# change shell for others
sed -i 's/zsh$/bash/g' /etc/passwd

fi

}

0 comments on commit 7ea3744

Please sign in to comment.