-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
51-users.sh
43 lines (34 loc) · 1.46 KB
/
51-users.sh
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
#!/usr/bin/with-contenv bash
# ==============================================================================
# Community Hass.io Add-ons: FTP
# Configures vsftpd
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
declare username
declare password
for user in $(hass.config.get 'users|keys[]'); do
username=$(hass.config.get "users[${user}].username")
mkdir -p "/ftproot/users/${username}"
touch "/etc/vsftpd/users/${username}"
for dir in "addons" "backup" "config" "share" "ssl"; do
if hass.config.true "users[${user}].${dir}"; then
mkdir "/ftproot/users/${username}/${dir}"
mount --bind "/${dir}" "/ftproot/users/${username}/${dir}"
fi
done
if hass.config.true "users[${user}].allow_chmod"; then
echo 'chmod_enable=YES' >> "/etc/vsftpd/users/${username}"
fi
if hass.config.true "users[${user}].allow_download"; then
echo 'download_enable=YES' >> "/etc/vsftpd/users/${username}"
fi
if hass.config.true "users[${user}].allow_upload"; then
echo 'write_enable=YES' >> "/etc/vsftpd/users/${username}"
fi
if hass.config.true "users[${user}].allow_dirlist"; then
echo 'dirlist_enable=YES' >> "/etc/vsftpd/users/${username}"
fi
password=$(hass.config.get "users[${user}].password" | openssl passwd -1 -stdin)
echo "${username}:${password}" >> /etc/vsftpd/passwd
done