Skip to content

Commit f14678a

Browse files
committed
nc-encrypt.sh: Fix detection of running encryption
Signed-off-by: Tobias Knöppler <[email protected]>
1 parent fc4c931 commit f14678a

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

bin/ncp/SECURITY/nc-encrypt.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ install()
2020

2121
configure()
2222
{
23-
(
23+
2424
set -e -o pipefail
2525
local datadir parentdir encdir tmpdir
2626
datadir="$(get_ncpcfg datadir)"
2727
[[ "${datadir?}" == "null" ]] && datadir=/var/www/nextcloud/data
2828
parentdir="$(dirname "${datadir}")"
2929
encdir="${parentdir?}/ncdata_enc"
30-
tmpdir="$(mktemp -u -p "${parentdir}" -t nc-data-crypt.XXXXXX))"
30+
tmpdir="$(mktemp -u -p "${parentdir}" -t nc-data-crypt.XXXXXX)"
3131

3232
[[ "${ACTIVE?}" != "yes" ]] && {
3333
if ! is_active; then
@@ -59,7 +59,7 @@ configure()
5959
# Just mount already encrypted data
6060
if [[ -f "${encdir?}"/gocryptfs.conf ]]; then
6161
systemctl reset-failed ncp-encrypt ||:
62-
systemd-run -u ncp-encrypt -E PASSWORD bash -c "gocryptfs -allow_other -q '${encdir}' '${datadir}' <<<\"\${PASSWORD}\" 2>&1 | sed /^Switch/d |& tee /var/log/ncp-encrypt.log"
62+
systemd-run -u ncp-encrypt -E PASSWORD bash -c "gocryptfs -fg -allow_other -q '${encdir}' '${datadir}' <<<\"\${PASSWORD}\" 2>&1 | sed /^Switch/d |& tee /var/log/ncp-encrypt.log"
6363

6464
# switch to the regular virtual hosts after we decrypt, so we can access NC and ncp-web
6565
a2ensite ncp 001-nextcloud
@@ -72,13 +72,32 @@ configure()
7272
mkdir -p "${encdir?}"
7373
echo "${PASSWORD?}" | gocryptfs -init -q "${encdir}"
7474
save_maintenance_mode
75-
trap restore_maintenance_mode EXIT
75+
cleanup() {
76+
umount "${datadir}" ||:
77+
[[ -f "${tmpdir}" ]] && {
78+
rm -rf "${datadir?}" ||:
79+
mv "${tmpdir}" "${datadir}"
80+
81+
chown -R www-data:www-data "${datadir}"
82+
}
83+
restore_maintenance_mode
84+
}
85+
trap cleanup EXIT
7686

7787
mv "${datadir?}" "${tmpdir?}"
7888

7989
mkdir "${datadir}"
8090
systemctl reset-failed ncp-encrypt ||:
81-
systemd-run -u ncp-encrypt -E PASSWORD bash -c "gocryptfs -allow_other -q '${encdir}' '${datadir}' <<<\"\${PASSWORD}\" 2>&1 | sed /^Switch/d |& tee /var/log/ncp-encrypt.log"
91+
systemd-run -u ncp-encrypt -E PASSWORD bash -c "gocryptfs -fg -allow_other -q '${encdir}' '${datadir}' <<<\"\${PASSWORD}\" 2>&1 | sed /^Switch/d |& tee /var/log/ncp-encrypt.log"
92+
93+
maxtries=5
94+
while [[ "$(systemctl is-active ncp-encrypt)" != "active" ]]
95+
do
96+
echo "Wating for encryption process to start... (${maxtries})"
97+
sleep 3
98+
maxtries=$((maxtries - 1))
99+
[[ $maxtries -gt 0 ]] || return 1
100+
done
82101

83102
echo "Encrypting data..."
84103
mv "${tmpdir}"/* "${tmpdir}"/.[!.]* "${datadir}"
@@ -88,7 +107,7 @@ configure()
88107
set_ncpcfg datadir "${datadir}"
89108

90109
echo "Data is now encrypted"
91-
)
110+
92111
}
93112

94113
# License

ncp.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ EOF
128128

129129
cat > /home/www/ncp-app-bridge.sh <<'EOF'
130130
#!/bin/bash
131-
set -ex
131+
set -e
132132
grep -q '[\\&#;`|*?~<>^()[{}$&]' <<< "$*" && exit 1
133133
action="${1?}"
134134
[[ "$action" == "config" ]] && {

0 commit comments

Comments
 (0)