Skip to content

Commit

Permalink
Fix database restore and wizards
Browse files Browse the repository at this point in the history
  • Loading branch information
mreid-tt committed Oct 22, 2023
1 parent 2b61920 commit f162e9f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
11 changes: 6 additions & 5 deletions spk/owncloud/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ service_postinst ()

# Restore the Database
[ -f "${DATA_DIR}/${SYNOPKG_PKGNAME}.db" ] && ${RM} "${DATA_DIR}/${SYNOPKG_PKGNAME}.db"
${SQLITE} "${DATA_DIR}/${SYNOPKG_PKGNAME}.db" < "${TEMPDIR}/database/${SYNOPKG_PKGNAME}.db" 2>&1
${SQLITE} "${DATA_DIR}/${SYNOPKG_PKGNAME}.db" < "${TEMPDIR}/database/${SYNOPKG_PKGNAME}-dbbackup.bak" 2>&1

# Update the systems data-fingerprint after a backup is restored
exec_occ maintenance:data-fingerprint
Expand Down Expand Up @@ -253,7 +253,8 @@ service_preuninst ()
fi

# Prepare archive structure
TEMPDIR="${SYNOPKG_PKGTMP}/${SYNOPKG_PKGNAME}_backup_v$(SPK_VERS)_$(date +"%Y%m%d")"
OCC_VER=$(exec_occ -V | cut -d ' ' -f 3)
TEMPDIR="${SYNOPKG_PKGTMP}/${SYNOPKG_PKGNAME}_backup_v${OCC_VER}_$(date +"%Y%m%d")"
${MKDIR} "${TEMPDIR}"

# Place server in maintenance mode
Expand All @@ -262,7 +263,7 @@ service_preuninst ()
# Backup the Database
echo "Copying previous database from ${DATADIR}"
${MKDIR} "${TEMPDIR}/database"
${SQLITE} "${DATADIR}/${SYNOPKG_PKGNAME}.db" ".backup '${TEMPDIR}/database/${SYNOPKG_PKGNAME}.db'" 2>&1
${SQLITE} "${DATADIR}/${SYNOPKG_PKGNAME}.db" .dump > "${TEMPDIR}/database/${SYNOPKG_PKGNAME}-dbbackup.bak" 2>&1

# Backup Directories
echo "Copying previous configuration from ${OCROOT}"
Expand Down Expand Up @@ -358,7 +359,7 @@ validate_preupgrade ()
# ownCloud upgrades only possible from 8.2.11, 9.0.9, 9.1.X, or 10.X.Y
is_upgrade_possible="no"
valid_versions=("8.2.11" "9.0.9" "9.1.*" "10.*.*")
previous=$(echo ${SYNOPKG_OLD_PKGVER} | cut -d'-' -f1)
previous=$(echo ${SYNOPKG_OLD_PKGVER} | cut -d '-' -f 1)
for version in "${valid_versions[@]}"; do
if echo "$previous" | grep -q "$version"; then
is_upgrade_possible="yes"
Expand Down Expand Up @@ -402,7 +403,7 @@ service_save ()
[ -d ${SYNOPKG_TEMP_UPGRADE_FOLDER}/db_backup ] && ${RM} ${SYNOPKG_TEMP_UPGRADE_FOLDER}/db_backup
echo "Backup existing server database to ${SYNOPKG_TEMP_UPGRADE_FOLDER}/db_backup"
${MKDIR} ${SYNOPKG_TEMP_UPGRADE_FOLDER}/db_backup
${SQLITE} "${DATADIR}/${SYNOPKG_PKGNAME}.db" ".backup '${SYNOPKG_TEMP_UPGRADE_FOLDER}/db_backup/${SYNOPKG_PKGNAME}-dbbackup_$(date +"%Y%m%d").bak'" 2>&1
${SQLITE} "${DATADIR}/${SYNOPKG_PKGNAME}.db" .dump > "${SYNOPKG_TEMP_UPGRADE_FOLDER}/db_backup/${SYNOPKG_PKGNAME}-dbbackup_$(date +"%Y%m%d").bak" 2>&1
}

service_restore ()
Expand Down
43 changes: 31 additions & 12 deletions spk/owncloud/src/wizard_templates/install_uifile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ jsFunction=$(/bin/cat<<EOF
return null;
}
function isRestoreChecked(wizardDialog) {
var restoreStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_INSTALL_RESTORE_STEP_TITLE}}}");
if (!restoreStep) {
var typeStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_INSTALL_RESTORE_STEP_TITLE}}}");
if (!typeStep) {
return false;
} else {
return restoreStep.getComponent("${RESTORE_BACKUP_FILE}").checked;
return typeStep.getComponent("${RESTORE_BACKUP_FILE}").checked;
}
}
EOF
Expand All @@ -95,13 +95,21 @@ getActiveate()
${jsFunction}
var currentStep = arguments[0];
var wizardDialog = currentStep.owner;
var restoreStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_INSTALL_RESTORE_STEP_TITLE}}}");
var typeStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_INSTALL_RESTORE_STEP_TITLE}}}");
var adminStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_ADMIN_CONFIGURATION_STEP_TITLE}}}");
var domainStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_TRUSTED_DOMAINS_STEP_TITLE}}}");
var confirmStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_CONFIRM_RESTORE_STEP_TITLE}}}");
var checked = isRestoreChecked(wizardDialog);
if (checked) {
wizardDialog.goBack(restoreStep.itemId);
wizardDialog.goNext("applyStep");
if (currentStep.headline === "{{{OWNCLOUD_ADMIN_CONFIGURATION_STEP_TITLE}}}") {
if (checked) {
wizardDialog.goBack(typeStep.itemId);
wizardDialog.goNext(confirmStep.itemId);
}
} else if (currentStep.headline === "{{{OWNCLOUD_CONFIRM_RESTORE_STEP_TITLE}}}") {
if (!checked) {
wizardDialog.goBack(domainStep.itemId);
wizardDialog.goNext("applyStep");
}
}
}
EOF
Expand All @@ -116,14 +124,18 @@ getDeActiveate()
${jsFunction}
var currentStep = arguments[0];
var wizardDialog = currentStep.owner;
var restoreStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_INSTALL_RESTORE_STEP_TITLE}}}");
var typeStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_INSTALL_RESTORE_STEP_TITLE}}}");
var adminStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_ADMIN_CONFIGURATION_STEP_TITLE}}}");
var domainStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_TRUSTED_DOMAINS_STEP_TITLE}}}");
var confirmStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_CONFIRM_RESTORE_STEP_TITLE}}}");
var checked = isRestoreChecked(wizardDialog);
if (checked) {
currentStep.nextId = "applyStep";
} else {
currentStep.nextId = adminStep.itemId;
if (currentStep.headline === "{{{OWNCLOUD_INSTALL_RESTORE_STEP_TITLE}}}") {
domainStep.nextId = "applyStep";
if (checked) {
currentStep.nextId = confirmStep.itemId;
} else {
currentStep.nextId = adminStep.itemId;
}
}
}
EOF
Expand Down Expand Up @@ -225,6 +237,13 @@ PAGE_ADMIN_CONFIG=$(/bin/cat<<EOF
"emptyText": "192.168.1.50"
}]
}]
}, {
"step_title": "{{{OWNCLOUD_CONFIRM_RESTORE_STEP_TITLE}}}",
"activate_v2": "$(getActiveate)",
"items": [{
"type": "textfield",
"desc": "{{{OWNCLOUD_CONFIRM_RESTORE_DESCRIPTION}}}"
}]
}
EOF
)
Expand Down
3 changes: 3 additions & 0 deletions spk/owncloud/src/wizard_templates/install_uifile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ OWNCLOUD_TRUSTED_DOMAINS_DESCRIPTION: "To access your ownCloud server, you must
OWNCLOUD_TRUSTED_DOMAIN_1_LABEL: "Domain or IP address"
OWNCLOUD_TRUSTED_DOMAIN_2_LABEL: "Domain or IP address"
OWNCLOUD_TRUSTED_DOMAIN_3_LABEL: "Domain or IP address"

OWNCLOUD_CONFIRM_RESTORE_STEP_TITLE: "ownCloud confirm restore"
OWNCLOUD_CONFIRM_RESTORE_DESCRIPTION: "The installation will now proceed, and your previous configuration will be restored from the backup. Please ensure that the file path is correct; otherwise, a new installation will be performed."
3 changes: 3 additions & 0 deletions spk/owncloud/src/wizard_templates/install_uifile_fre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ OWNCLOUD_TRUSTED_DOMAINS_DESCRIPTION: "Pour accéder à votre serveur ownCloud,
OWNCLOUD_TRUSTED_DOMAIN_1_LABEL: "Domaine ou adresse IP"
OWNCLOUD_TRUSTED_DOMAIN_2_LABEL: "Domaine ou adresse IP"
OWNCLOUD_TRUSTED_DOMAIN_3_LABEL: "Domaine ou adresse IP"

OWNCLOUD_CONFIRM_RESTORE_STEP_TITLE: "Confirmer la restauration ownCloud"
OWNCLOUD_CONFIRM_RESTORE_DESCRIPTION: "L'installation va maintenant se poursuivre et votre configuration précédente sera restaurée à partir de la sauvegarde. Veuillez vous assurer que le chemin du fichier est correct ; sinon, une nouvelle installation sera effectuée."
4 changes: 2 additions & 2 deletions spk/owncloud/src/wizard_templates/upgrade_uifile.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

OC_NEW_VER=$(echo ${SYNOPKG_PKGVER} | cut -d'-' -f1)
OC_OLD_VER=$(echo ${SYNOPKG_OLD_PKGVER} | cut -d'-' -f1)
OC_NEW_VER=$(echo ${SYNOPKG_PKGVER} | cut -d '-' -f 1)
OC_OLD_VER=$(echo ${SYNOPKG_OLD_PKGVER} | cut -d '-' -f 1)

quote_json () {
sed -e 's|\\|\\\\|g' -e 's|\"|\\\"|g'
Expand Down

0 comments on commit f162e9f

Please sign in to comment.