-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpassword
46 lines (37 loc) · 1.37 KB
/
password
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# change password on image
# default options
RPI_PASSWORD_USER="${RPI_PASSWORD_USER:=pi}"
RPI_PASSWORD_PW="${RPI_PASSWORD_PW:=""}"
RPI_PASSWORD_CRYPT_METHOD="${RPI_PASSWORD_CRYPT_METHOD:=SHA512}"
function rpi_password_prerun() {
[[ -n "${RPI_PASSWORD_USER}" ]] || error "no USER set. password plugin"
if [[ -z "${RPI_PASSWORD_PW}" ]] ; then
# interactively get password
log "enter password: "
read -r -s password_one
log "enter password again: "
read -r -s password_two
[[ "${password_one}" == "${password_two}" ]] || error "passwords don't match. password plugin"
# use this password
RPI_PASSWORD_PW="${password_one}"
unset password_one
unset password_two
fi
return 0
}
function rpi_password_run() {
log " setting password for user \"${RPI_PASSWORD_USER}\""
rootpath="$(realpath "${RPI_ROOT}")"
echo "${RPI_PASSWORD_USER}:${RPI_PASSWORD_PW}" | sudo chpasswd \
--root "${rootpath}" \
--crypt-method "${RPI_PASSWORD_CRYPT_METHOD}"
}
function rpi_password_description() {
echo "change password on image"
}
function rpi_password_help_params() {
help_param "RPI_PASSWORD_USER" "the user to change the password from"
help_param "RPI_PASSWORD_PW" "the password (empty for interactive input)"
help_param "RPI_PASSWORD_CRYPT_METHOD" "crypt method"
}