Skip to content

Commit

Permalink
treehouses password change (fixes #2072) (#2077)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
JLKwong and dogi authored Mar 13, 2021
1 parent 6153489 commit ada452c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ help [command] gives you a more detailed info about t
verbose <on|off> makes each command print more output (might not work with treehouses remote)
expandfs expands the partition of the RPI image to the maximum of the SD card
rename <hostname> changes hostname
password <password|disable|enable> changes the password for 'pi' user or disables/enables password authentication
password <disable|enable|change [passwd]> changes the password for 'pi' user or disables/enables password authentication
sshkey <add|list|delete|deleteall|github> used for adding or removing ssh keys for authentication
version [contributors|remote] returns the version of treehouses CLI, remote, or list of contributors
image returns version of the system image installed
Expand Down
2 changes: 1 addition & 1 deletion _treehouses
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ treehouses openvpn show
treehouses openvpn start
treehouses openvpn stop
treehouses openvpn use
treehouses password
treehouses password change
treehouses password disable
treehouses password enable
treehouses picture
Expand Down
2 changes: 1 addition & 1 deletion modules/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ help [command] gives you a more detailed info about t
verbose <on|off> makes each command print more output (might not work with treehouses remote)
expandfs expands the partition of the RPI image to the maximum of the SD card
rename <hostname> changes hostname
password <password|disable|enable> changes the password for 'pi' user or disables/enables password authentication
password <disable|enable|change [passwd]> changes the password for 'pi' user or disables/enables password authentication
sshkey <add|list|delete|deleteall|github> used for adding or removing ssh keys for authentication
version [contributors|remote] returns the version of treehouses CLI, remote, or list of contributors
image returns version of the system image installed
Expand Down
24 changes: 17 additions & 7 deletions modules/password.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
function password {
checkrpi
checkroot
checkargn $# 1
checkargn $# 2
options="$1"

case "$options" in
"")
log_and_exit1 "Error: Password not entered"
"change")
case "$2" in
"")
log_and_exit1 "Error: Password not entered"
;;
*)
chpasswd <<< "pi:$2"
echo "Success: the password has been changed"
;;
esac
;;
"disable")
checkargn $# 1
disablepassword
;;
"enable")
checkargn $# 1
enablepassword
;;
*)
chpasswd <<< "pi:$options"
echo "Success: the password has been changed"
log_help_and_exit1 "Error: Must use an option to 'change', 'disable', or 'enable'" "password"
;;
esac
}
Expand All @@ -34,13 +44,13 @@ function enablepassword {

function password_help () {
echo
echo "Usage: $BASENAME password <password>"
echo "Usage: $BASENAME password change <password>"
echo " $BASENAME password [disable|enable]"
echo
echo "Changes the password for 'pi' user"
echo
echo "Example:"
echo " $BASENAME password ABC"
echo " $BASENAME change password ABC"
echo " Sets the password for 'pi' user to 'ABC'."
echo
echo " $BASENAME password disable"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@treehouses/cli",
"version": "1.25.19",
"version": "1.25.20",
"remote": "4000",
"description": "Thin command-line interface for Raspberry Pi low level configuration.",
"main": "cli.sh",
Expand Down
4 changes: 2 additions & 2 deletions tests/password.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
load test-helper

@test "$clinom password raspberry" {
run "${clicmd}" password raspberry
run "${clicmd}" password change raspberry
assert_success
}
}

0 comments on commit ada452c

Please sign in to comment.