File: //proc/25618/root/var/packages/CMS/scripts/CMSUpdateDB.sh
#!/bin/sh
CUT=/bin/cut
ECHO=/bin/echo
GREP=/bin/grep
SQLITE3=/usr/bin/sqlite3
UPDATER="/var/packages/CMS/target/tools/synocmsupdater"
DB_LOG_FILE="/var/packages/CMS/var/db/cmslog_db.sqlite"
DB_NC_FILE="/var/packages/CMS/var/db/nc_db.sqlite"
DB_FILE="/var/packages/CMS/var/db/cms_db.sqlite"
DB_TASK_FILE="/var/packages/CMS/var/db/cmstask_db.sqlite"
CMS_OLD_VERSION="$1"
CMS_OLD_BUILD_NUM=$(echo "$CMS_OLD_VERSION" | $CUT -d '-' -f 2)
if [ -z "$CMS_OLD_BUILD_NUM" ]; then
/usr/bin/logger -p err -t "synocms" "Failed to get package old version in CMS upgrade"
CMS_OLD_BUILD_NUM="0"
fi
LegacyUpdate()
{
# add columns to accomandate more share info
$ECHO "PRAGMA table_info(share_info);" | $SQLITE3 ${DB_FILE} | cut -d'|' -f2 | grep -q '^display_vol_name$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE share_info ADD COLUMN display_vol_name TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add display_vol_name into share_info table"
exit 1
fi
fi
$ECHO "PRAGMA table_info(share_info);" | $SQLITE3 ${DB_FILE} | cut -d'|' -f2 | grep -q '^extra_info$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE share_info ADD COLUMN extra_info TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add extra_info into share_info table"
exit 1
fi
fi
$ECHO "PRAGMA table_info(app);" | $SQLITE3 ${DB_FILE} | cut -d'|' -f2 | grep -q '^name_tha$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE app ADD COLUMN name_tha TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add name_tha into app table"
exit 1
fi
fi
$ECHO "PRAGMA table_info(package);" | $SQLITE3 ${DB_FILE} | cut -d'|' -f2 | grep -q '^pkg_desc_tha$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE package ADD COLUMN pkg_desc_tha TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add pkg_desc_tha into package table"
exit 1
fi
fi
$ECHO "PRAGMA table_info(package);" | $SQLITE3 ${DB_FILE} | cut -d'|' -f2 | grep -q '^pkg_name_tha$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE package ADD COLUMN pkg_name_tha TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add pkg_name_tha into package table"
exit 1
fi
fi
$ECHO "PRAGMA table_info(log);" | $SQLITE3 ${DB_LOG_FILE} | cut -d'|' -f2 | grep -q '^tha$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE log ADD COLUMN tha TEXT DEFAULT '';" | $SQLITE3 ${DB_LOG_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add tha into log table"
exit 1
fi
fi
$ECHO "PRAGMA table_info(msg);" | $SQLITE3 ${DB_NC_FILE} | cut -d'|' -f2 | grep -q '^tha$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE msg ADD COLUMN tha TEXT DEFAULT '';" | $SQLITE3 ${DB_NC_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add tha into msg table"
exit 1
fi
fi
}
AddDiskSummaryStatus()
{
$ECHO "PRAGMA table_info(hdd_info);" | $SQLITE3 ${DB_FILE} | $CUT -d'|' -f2 | $GREP -q '^summary_status_category$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE hdd_info ADD COLUMN summary_status_category TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add disk summary status category"
exit 1
fi
fi
$ECHO "PRAGMA table_info(hdd_info);" | $SQLITE3 ${DB_FILE} | $CUT -d'|' -f2 | $GREP -q '^summary_status_key$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE hdd_info ADD COLUMN summary_status_key TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add disk summary status key"
exit 1
fi
$UPDATER convert-disk-summary-status
fi
}
AddConnectionInInfoTable()
{
$ECHO "PRAGMA table_info(info);" | $SQLITE3 ${DB_FILE} | $CUT -d'|' -f2 | $GREP -q '^connection$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE info ADD COLUMN connection TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add connection category"
exit 1
fi
fi
}
RemoveUnsuppotedPolicy()
{
$UPDATER update-policy \
'Set:Notification_Setting_Push_Service:msn_enable:false' \
'Set:Notification_Setting_Push_Service:msn_account:""' \
'Set:Notification_Setting_Push_Service:skype_enable:false' \
'Set:Notification_Setting_Push_Service:skype_account:""' \
'Set:Network_Backup:enable_custom_rsync:false' \
'Set:DSM_Setting:enable_https:true' \
'AddKeyIfNotExist:DSM_Setting:enable_https_redirect:false' \
'Remove:WebDAV' \
'Remove:Syslog_Client' \
'Remove:Samba:offline_files_support' \
'Remove:File_Station:enable_java'
if [ $? -ne 0 ]; then
$ECHO "Failed to update policy"
exit 1
fi
$UPDATER update-policy \
'Remove:Notification_Event_LocalLUNBkpError' \
'Remove:Notification_Event_LocalLUNRecoverError' \
'Remove:Notification_Event_LocalRecoverCanceled' \
'Remove:Notification_Event_LocalRecoverError' \
'Remove:Notification_Event_NetBkpError' \
'Remove:Notification_Event_NetBkpS3Cancel' \
'Remove:Notification_Event_NetBkpS3Error' \
'Remove:Notification_Event_NetLUNBkpError' \
'Remove:Notification_Event_NetLUNRecoverError' \
'Remove:Notification_Event_NetLUNRecoverFinished' \
'Remove:Notification_Event_NetRecoverCanceled' \
'Remove:Notification_Event_NetRecoverError' \
'Remove:Notification_Event_NetRecoverFinished' \
'Remove:Notification_Event_S3RecoverCanceled' \
'Remove:Notification_Event_S3RecoverError' \
'Remove:Notification_Event_S3RecoverFinished' \
'Remove:Notification_Event_USBBKPCancelled' \
'Remove:Notification_Event_USBBKPDisconnect' \
'Remove:Notification_Event_USBBKPError' \
'Remove:Notification_Event_USBBKPNospace' \
'Remove:Notification_Event_LocalLUNBkpFinished' \
'Remove:Notification_Event_LocalLUNRecoverFinished' \
'Remove:Notification_Event_LocalRecoverFinished' \
'Remove:Notification_Event_NetBkpOK' \
'Remove:Notification_Event_NetBkpS3OK' \
'Remove:Notification_Event_NetLUNBkpOK' \
'Remove:Notification_Event_USBBKPFinished' \
'Remove:Notification_Event_USBBKPPartial'
if [ $? -ne 0 ]; then
$ECHO "Failed to update policy"
exit 1
fi
$UPDATER update-policy \
'Set:Notification_Event_CpuFanStop:CpuFanStop_msn:false' \
'Set:Notification_Event_CpuFanStop:CpuFanStop_skype:false' \
'Set:Notification_Event_DiskTemperatureAbnormal:DiskTemperatureAbnormal_msn:false' \
'Set:Notification_Event_DiskTemperatureAbnormal:DiskTemperatureAbnormal_skype:false' \
'Set:Notification_Event_DsmProtectionCheckFailed:DsmProtectionCheckFailed_msn:false' \
'Set:Notification_Event_DsmProtectionCheckFailed:DsmProtectionCheckFailed_skype:false' \
'Set:Notification_Event_EBoxHDEcc:EBoxHDEcc_msn:false' \
'Set:Notification_Event_EBoxHDEcc:EBoxHDEcc_skype:false' \
'Set:Notification_Event_EUnitPowerFail:EUnitPowerFail_msn:false' \
'Set:Notification_Event_EUnitPowerFail:EUnitPowerFail_skype:false' \
'Set:Notification_Event_EUnitPowerResume:EUnitPowerResume_msn:false' \
'Set:Notification_Event_EUnitPowerResume:EUnitPowerResume_skype:false' \
'Set:Notification_Event_EboxFanResume:EboxFanResume_msn:false' \
'Set:Notification_Event_EboxFanResume:EboxFanResume_skype:false' \
'Set:Notification_Event_EboxFanStop:EboxFanStop_msn:false' \
'Set:Notification_Event_EboxFanStop:EboxFanStop_skype:false' \
'Set:Notification_Event_EboxLinkFail:EboxLinkFail_msn:false' \
'Set:Notification_Event_EboxLinkFail:EboxLinkFail_skype:false' \
'Set:Notification_Event_EboxLinkResume:EboxLinkResume_msn:false' \
'Set:Notification_Event_EboxLinkResume:EboxLinkResume_skype:false' \
'Set:Notification_Event_ExpansionFrmInconsistent:ExpansionFrmInconsistent_msn:false' \
'Set:Notification_Event_ExpansionFrmInconsistent:ExpansionFrmInconsistent_skype:false' \
'Set:Notification_Event_FailedToRunNtp:FailedToRunNtp_msn:false' \
'Set:Notification_Event_FailedToRunNtp:FailedToRunNtp_skype:false' \
'Set:Notification_Event_HDEcc:HDEcc_msn:false' \
'Set:Notification_Event_HDEcc:HDEcc_skype:false' \
'Set:Notification_Event_ImproperShutdown:ImproperShutdown_msn:false' \
'Set:Notification_Event_ImproperShutdown:ImproperShutdown_skype:false' \
'Set:Notification_Event_InternalDiskFail:InternalDiskFail_msn:false' \
'Set:Notification_Event_InternalDiskFail:InternalDiskFail_skype:false' \
'Set:Notification_Event_InternalDiskIOError:InternalDiskIOError_msn:false' \
'Set:Notification_Event_InternalDiskIOError:InternalDiskIOError_skype:false' \
'Set:Notification_Event_InternalFanStop:InternalFanStop_msn:false' \
'Set:Notification_Event_InternalFanStop:InternalFanStop_skype:false' \
'Set:Notification_Event_OverheatShutdownCPU:OverheatShutdownCPU_msn:false' \
'Set:Notification_Event_OverheatShutdownCPU:OverheatShutdownCPU_skype:false' \
'Set:Notification_Event_OverheatShutdownDisk:OverheatShutdownDisk_msn:false' \
'Set:Notification_Event_OverheatShutdownDisk:OverheatShutdownDisk_skype:false' \
'Set:Notification_Event_OverheatShutdownThermal:OverheatShutdownThermal_msn:false' \
'Set:Notification_Event_OverheatShutdownThermal:OverheatShutdownThermal_skype:false' \
'Set:Notification_Event_Raid5SpareChanged:Raid5SpareChanged_msn:false' \
'Set:Notification_Event_Raid5SpareChanged:Raid5SpareChanged_skype:false' \
'Set:Notification_Event_RaidDiskFail:RaidDiskFail_msn:false' \
'Set:Notification_Event_RaidDiskFail:RaidDiskFail_skype:false' \
'Set:Notification_Event_RaidSystemVolumeCrashed:RaidSystemVolumeCrashed_msn:false' \
'Set:Notification_Event_RaidSystemVolumeCrashed:RaidSystemVolumeCrashed_skype:false' \
'Set:Notification_Event_RaidSystemVolumeDegrade:RaidSystemVolumeDegrade_msn:false' \
'Set:Notification_Event_RaidSystemVolumeDegrade:RaidSystemVolumeDegrade_skype:false' \
'Set:Notification_Event_RaidVolumeBadSector:RaidVolumeBadSector_msn:false' \
'Set:Notification_Event_RaidVolumeBadSector:RaidVolumeBadSector_skype:false' \
'Set:Notification_Event_RaidVolumeCrashed:RaidVolumeCrashed_msn:false' \
'Set:Notification_Event_RaidVolumeCrashed:RaidVolumeCrashed_skype:false' \
'Set:Notification_Event_RaidVolumeDegrade:RaidVolumeDegrade_msn:false' \
'Set:Notification_Event_RaidVolumeDegrade:RaidVolumeDegrade_skype:false' \
'Set:Notification_Event_RaidVolumeFull:RaidVolumeFull_msn:false' \
'Set:Notification_Event_RaidVolumeFull:RaidVolumeFull_skype:false' \
'Set:Notification_Event_RaidiScsiBadSector:RaidiScsiBadSector_msn:false' \
'Set:Notification_Event_RaidiScsiBadSector:RaidiScsiBadSector_skype:false' \
'Set:Notification_Event_RedundantPowerStopProvide:RedundantPowerStopProvide_msn:false' \
'Set:Notification_Event_RedundantPowerStopProvide:RedundantPowerStopProvide_skype:false' \
'Set:Notification_Event_ShareSyncError:ShareSyncError_msn:false' \
'Set:Notification_Event_ShareSyncError:ShareSyncError_skype:false' \
'Set:Notification_Event_SmartTestEBoxErr:SmartTestEBoxErr_msn:false' \
'Set:Notification_Event_SmartTestEBoxErr:SmartTestEBoxErr_skype:false' \
'Set:Notification_Event_SmartTestESataErr:SmartTestESataErr_msn:false' \
'Set:Notification_Event_SmartTestESataErr:SmartTestESataErr_skype:false' \
'Set:Notification_Event_SmartTestIntErr:SmartTestIntErr_msn:false' \
'Set:Notification_Event_SmartTestIntErr:SmartTestIntErr_skype:false' \
'Set:Notification_Event_StoragePoolCrashed:StoragePoolCrashed_msn:false' \
'Set:Notification_Event_StoragePoolCrashed:StoragePoolCrashed_skype:false' \
'Set:Notification_Event_StoragePoolDegraded:StoragePoolDegraded_msn:false' \
'Set:Notification_Event_StoragePoolDegraded:StoragePoolDegraded_skype:false' \
'Set:Notification_Event_StoragePoolRaid5SpareChanged:StoragePoolRaid5SpareChanged_msn:false' \
'Set:Notification_Event_StoragePoolRaid5SpareChanged:StoragePoolRaid5SpareChanged_skype:false' \
'Set:Notification_Event_UPSDisconnect:UPSDisconnect_msn:false' \
'Set:Notification_Event_UPSDisconnect:UPSDisconnect_skype:false' \
'Set:Notification_Event_UPSOnAC:UPSOnAC_msn:false' \
'Set:Notification_Event_UPSOnAC:UPSOnAC_skype:false' \
'Set:Notification_Event_UPSOnBattery:UPSOnBattery_msn:false' \
'Set:Notification_Event_UPSOnBattery:UPSOnBattery_skype:false' \
'Set:Notification_Event_UPSPowerFail:UPSPowerFail_msn:false' \
'Set:Notification_Event_UPSPowerFail:UPSPowerFail_skype:false' \
'Set:Notification_Event_AutoBlockAdd:AutoBlockAdd_msn:false' \
'Set:Notification_Event_AutoBlockAdd:AutoBlockAdd_skype:false' \
'Set:Notification_Event_CpuFanResume:CpuFanResume_msn:false' \
'Set:Notification_Event_CpuFanResume:CpuFanResume_skype:false' \
'Set:Notification_Event_DDNSFail:DDNSFail_msn:false' \
'Set:Notification_Event_DDNSFail:DDNSFail_skype:false' \
'Set:Notification_Event_DeviceEjectedImproperly:DeviceEjectedImproperly_msn:false' \
'Set:Notification_Event_DeviceEjectedImproperly:DeviceEjectedImproperly_skype:false' \
'Set:Notification_Event_ESATADiskFull:ESATADiskFull_msn:false' \
'Set:Notification_Event_ESATADiskFull:ESATADiskFull_skype:false' \
'Set:Notification_Event_ESATAPartitionFull:ESATAPartitionFull_msn:false' \
'Set:Notification_Event_ESATAPartitionFull:ESATAPartitionFull_skype:false' \
'Set:Notification_Event_HotSpareDiskPlugout:HotSpareDiskPlugout_msn:false' \
'Set:Notification_Event_HotSpareDiskPlugout:HotSpareDiskPlugout_skype:false' \
'Set:Notification_Event_HotSpareRepairDone:HotSpareRepairDone_msn:false' \
'Set:Notification_Event_HotSpareRepairDone:HotSpareRepairDone_skype:false' \
'Set:Notification_Event_HotSpareRepairFailed:HotSpareRepairFailed_msn:false' \
'Set:Notification_Event_HotSpareRepairFailed:HotSpareRepairFailed_skype:false' \
'Set:Notification_Event_HotSpareRepairNoProtect:HotSpareRepairNoProtect_msn:false' \
'Set:Notification_Event_HotSpareRepairNoProtect:HotSpareRepairNoProtect_skype:false' \
'Set:Notification_Event_HotSpareRepairStart:HotSpareRepairStart_msn:false' \
'Set:Notification_Event_HotSpareRepairStart:HotSpareRepairStart_skype:false' \
'Set:Notification_Event_InternalFanResume:InternalFanResume_msn:false' \
'Set:Notification_Event_InternalFanResume:InternalFanResume_skype:false' \
'Set:Notification_Event_RaidSystemVolumeSyncDone:RaidSystemVolumeSyncDone_msn:false' \
'Set:Notification_Event_RaidSystemVolumeSyncDone:RaidSystemVolumeSyncDone_skype:false' \
'Set:Notification_Event_RaidVolumeSyncDone:RaidVolumeSyncDone_msn:false' \
'Set:Notification_Event_RaidVolumeSyncDone:RaidVolumeSyncDone_skype:false' \
'Set:Notification_Event_RedundantPowerRecoveredProvide:RedundantPowerRecoveredProvide_msn:false' \
'Set:Notification_Event_RedundantPowerRecoveredProvide:RedundantPowerRecoveredProvide_skype:false' \
'Set:Notification_Event_StoragePoolSyncDone:StoragePoolSyncDone_msn:false' \
'Set:Notification_Event_StoragePoolSyncDone:StoragePoolSyncDone_skype:false' \
'Set:Notification_Event_UPSConnected:UPSConnected_msn:false' \
'Set:Notification_Event_UPSConnected:UPSConnected_skype:false' \
'Set:Notification_Event_USBDiskFail:USBDiskFail_msn:false' \
'Set:Notification_Event_USBDiskFail:USBDiskFail_skype:false' \
'Set:Notification_Event_USBDiskFull:USBDiskFull_msn:false' \
'Set:Notification_Event_USBDiskFull:USBDiskFull_skype:false' \
'Set:Notification_Event_USBPartitionFull:USBPartitionFull_msn:false' \
'Set:Notification_Event_USBPartitionFull:USBPartitionFull_skype:false' \
'Set:Notification_Event_UserWelcome:UserWelcome_msn:false' \
'Set:Notification_Event_UserWelcome:UserWelcome_skype:false' \
'Set:Notification_Event_VpncReconnectFail:VpncReconnectFail_msn:false' \
'Set:Notification_Event_VpncReconnectFail:VpncReconnectFail_skype:false'
if [ $? -ne 0 ]; then
$ECHO "Failed to update policy"
exit 1
fi
}
SetJournalModeAndPageSize() {
for db in "$DB_LOG_FILE" "$DB_NC_FILE" "$DB_FILE" "$DB_TASK_FILE"; do
if [ ! -f "$db" ]; then
continue
fi
(
"$ECHO" "PRAGMA page_size = 4096;"
"$ECHO" "VACUUM;"
"$ECHO" "PRAGMA journal_mode = WAL;"
) | "$SQLITE3" "$db"
if [ $? -ne 0 ]; then
$ECHO "Failed to set DB to WAL mode"
exit 1
fi
done
}
AddDiskI18nName()
{
$ECHO "PRAGMA table_info(hdd_info);" | $SQLITE3 ${DB_FILE} | cut -d'|' -f2 | grep -q '^i18n_name$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE hdd_info ADD COLUMN i18n_name TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add i18n_name into hdd_info table"
exit 1
fi
fi
}
AddDiskCompatibility()
{
$ECHO "PRAGMA table_info(hdd_info);" | $SQLITE3 ${DB_FILE} | cut -d'|' -f2 | grep -q '^compatibility$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE hdd_info ADD COLUMN compatibility TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add disk compatibility column"
exit 1
fi
fi
}
AddDiskHideInfo()
{
$ECHO "PRAGMA table_info(hdd_info);" | $SQLITE3 ${DB_FILE} | cut -d'|' -f2 | grep -q '^hide_info$'
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE hdd_info ADD COLUMN hide_info TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add disk hide_info column"
exit 1
fi
fi
}
AddIntegerColumn()
{
local table="$1"
local key="$2"
$ECHO "PRAGMA table_info(${table});" | $SQLITE3 ${DB_FILE} | cut -d'|' -f2 | grep -q "^${key}$"
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE ${table} ADD COLUMN ${key} INT DEFAULT 0;" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add ${key} column on ${table}"
exit 1
fi
fi
}
AddPkgInstallType()
{
$ECHO "PRAGMA table_info(package);" | $SQLITE3 ${DB_FILE} | cut -d'|' -f2 | grep -q "^install_type$"
if [ $? -ne 0 ]; then
$ECHO "ALTER TABLE package ADD COLUMN install_type TEXT DEFAULT '';" | $SQLITE3 ${DB_FILE}
if [ $? -ne 0 ]; then
$ECHO "Failed to add install_type column on package"
exit 1
fi
$ECHO "Add install_type (package)"
fi
}
if [ "$CMS_OLD_BUILD_NUM" -lt "861" ]; then
LegacyUpdate
AddDiskSummaryStatus
AddConnectionInInfoTable
RemoveUnsuppotedPolicy
fi
if [ "$CMS_OLD_BUILD_NUM" -lt "907" ]; then
SetJournalModeAndPageSize
fi
if [ "$CMS_OLD_BUILD_NUM" -lt "946" ]; then
AddDiskI18nName
fi
if [ "$CMS_OLD_BUILD_NUM" -lt "1012" ]; then
AddDiskCompatibility
fi
if [ "$CMS_OLD_BUILD_NUM" -lt "1015" ]; then
AddDiskHideInfo
AddIntegerColumn "hdd_info" "ctn_id"
AddIntegerColumn "hdd_info" "num_id"
AddIntegerColumn "vol_info" "num_id"
AddIntegerColumn "share_info" "vol_num_id"
fi
if [ "$CMS_OLD_BUILD_NUM" -lt "1213" ]; then
AddPkgInstallType
fi
exit 0