Add data migration logic

This commit is contained in:
Xiaonan Shen
2022-05-28 20:19:25 +08:00
parent bc23882b91
commit aef8462674
2 changed files with 26 additions and 5 deletions

View File

@@ -9,8 +9,29 @@ echo "everything from scratch. For more information about the new version, check
echo "https://github.com/shenxn/protonmail-bridge-docker" echo "https://github.com/shenxn/protonmail-bridge-docker"
echo echo
if [ -d /root/.config/protonmail ]; then
echo "Volume mount at `/root` for old version found. Please change your mount path to `/protonmail/data`."
echo "See https://github.com/shenxn/protonmail-bridge-docker for detailed migration guide."
echo "Exit in 30 seconds..."
sleep 30
exit 1
fi
groupadd -g ${PROTON_GID:-1001} proton groupadd -g ${PROTON_GID:-1001} proton
useradd -g proton -u ${PROTON_UID:-1001} -m proton useradd -g proton -u ${PROTON_UID:-1001} -m proton
chown proton:proton /protonmail/data
# Migrate old version data
if [ -d /protonmail/data/.config/protonmail ]; then
echo "Migrating legacy data. Note that this operation is irreversible so it is impossible"
echo "to go back to the old version without clearing the volume."
echo
mv /protonmail/data/.config/protonmail /protonmail/data/config
rm -rf /protonmail/data/.config
mv /protonmail/data/.cache/protonmail /protonmail/data/cache
rm -rf /protonmail/data/.cache
chown proton:proton -R /protonmail/data chown proton:proton -R /protonmail/data
fi
exec gosu proton:proton run_protonmail_bridge.sh "$@" exec gosu proton:proton run_protonmail_bridge.sh "$@"

View File

@@ -3,9 +3,9 @@
set -e set -e
# Generate gpg keys # Generate gpg keys
GNUPG_PATH=/protonmail/data/gnupg GNUPG_PATH=/protonmail/data/.gnupg
export GNUPGHOME=${GNUPG_PATH} export GNUPGHOME=${GNUPG_PATH}
if [ ! -f ${GNUPG_PATH} ]; then if [ ! -d ${GNUPG_PATH} ]; then
echo "Generateing gpg keys..." echo "Generateing gpg keys..."
# set GNUPGHOME to a temp directory as a workaround for # set GNUPGHOME to a temp directory as a workaround for
# #
@@ -25,8 +25,8 @@ if [ ! -f ${GNUPG_PATH} ]; then
fi fi
# Initialize pass # Initialize pass
PASSWORD_STORE=/protonmail/data/password-store PASSWORD_STORE=/protonmail/data/.password-store
if [ ! -f ${PASSWORD_STORE} ]; then if [ ! -d ${PASSWORD_STORE} ]; then
echo "Initializing pass..." echo "Initializing pass..."
pass init pass-key pass init pass-key
# Move password store to /protonmail/data # Move password store to /protonmail/data