Add upgrade script for initializing database 65/192865/1 submit/tizen_4.0/20181112.065358
authorhyunuktak <hyunuk.tak@samsung.com>
Mon, 12 Nov 2018 06:41:18 +0000 (15:41 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Mon, 12 Nov 2018 06:41:20 +0000 (15:41 +0900)
Change-Id: I7f8b344ec0615b1aa1e69ee00ac400d44537c652
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
data/init_stc_db.sh [new file with mode: 0644]
packaging/stc-manager.spec
scripts/500.stc-manager-upgrade.sh [new file with mode: 0644]

diff --git a/data/init_stc_db.sh b/data/init_stc_db.sh
new file mode 100644 (file)
index 0000000..ef1292e
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/sh
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+if [ ! -f /opt/usr/dbspace/.stc-manager-datausage.db ]
+then
+       /usr/bin/sqlite3 /opt/usr/dbspace/.stc-manager-datausage.db 'PRAGMA journal_mode = PERSIST;
+       PRAGMA user_version = 1;
+       CREATE TABLE IF NOT EXISTS statistics (
+               id INTEGER PRIMARY KEY AUTOINCREMENT,
+               binpath TEXT NOT NULL,
+               received BIGINT,
+               sent BIGINT,
+               time_stamp BIGINT,
+               iftype INT,
+               is_roaming INT,
+               hw_net_protocol_type INT,
+               ifname TEXT,
+               subscriber_id TEXT,
+               ground INT
+       );
+       CREATE TABLE IF NOT EXISTS restrictions (
+               restriction_id INTEGER PRIMARY KEY AUTOINCREMENT,
+               binpath TEXT,
+               iftype INT,
+               ifname TEXT,
+               rstn_type INT,
+               roaming INT,
+               subscriber_id TEXT NOT NULL,
+               data_limit BIGINT,
+               data_warn_limit BIGINT,
+               monthly_limit BIGINT,
+               weekly_limit BIGINT,
+               daily_limit BIGINT,
+               month_start_date INT
+       );
+       CREATE INDEX IF NOT EXISTS restrictions_index ON restrictions (binpath, iftype, ifname);
+       CREATE TABLE IF NOT EXISTS counters (
+               restriction_id INTEGER NOT NULL,
+               data_counter BIGINT,
+               warn_counter BIGINT,
+               monthly_counter BIGINT,
+               weekly_counter BIGINT,
+               daily_counter BIGINT,
+               month_start_date INT,
+               month_start_ts BIGINT,
+               week_start_ts BIGINT,
+               day_start_ts BIGINT,
+               PRIMARY KEY (restriction_id)
+       );
+       CREATE TABLE IF NOT EXISTS fw_lock (
+               name TEXT PRIMARY KEY,
+               state INT
+       );
+       CREATE TABLE IF NOT EXISTS fw_chains (
+               chain TEXT PRIMARY KEY,
+               target INT,
+               priority INT
+       );
+       CREATE TABLE IF NOT EXISTS fw_rules (
+               key BIGINT PRIMARY KEY,
+               chain TEXT NOT NULL,
+               direction INT,
+               s_ip_type INT,
+               d_ip_type INT,
+               s_port_type INT,
+               d_port_type INT,
+               protocol INT,
+               family INT,
+               s_ip1 TEXT NOT NULL,
+               s_ip2 TEXT NOT NULL,
+               d_ip1 TEXT NOT NULL,
+               d_ip2 TEXT NOT NULL,
+               s_port1 INT,
+               s_port2 INT,
+               d_port1 INT,
+               d_port2 INT,
+               ifname TEXT NOT NULL,
+               target INT,
+               log_level INT,
+               log_prefix TEXT NOT NULL,
+               nflog_group INT,
+               nflog_prefix TEXT NOT NULL,
+               nflog_range INT,
+               nflog_threshold INT,
+               identifier TEXT NOT NULL
+       );
+       CREATE INDEX IF NOT EXISTS rules_index ON fw_rules (chain, target);'
+fi
+
+/usr/bin/chmod 660 /opt/usr/dbspace/.stc-manager-datausage.db
+/usr/bin/chmod 660 /opt/usr/dbspace/.stc-manager-datausage.db-journal
+
+/usr/bin/chsmack -a _ /opt/usr/dbspace/.stc-manager-datausage.db
+/usr/bin/chsmack -a _ /opt/usr/dbspace/.stc-manager-datausage.db-journal
index eaea7f2..b784dcb 100755 (executable)
@@ -10,6 +10,8 @@ Source0:    %{name}-%{version}.tar.gz
 %define enable_statistics YES
 %define enable_restriction YES
 %define database_full_path /opt/usr/dbspace/.stc-manager-datausage.db
+%define upgrade_script_path /usr/share/upgrade/scripts
+%define upgrade_data_path /usr/share/upgrade/data
 
 BuildRequires:  cmake
 BuildRequires:  pkgconfig(glib-2.0)
@@ -145,6 +147,12 @@ ln -s ../stc-manager.service %{buildroot}%{_libdir}/systemd/system/multi-user.ta
 mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d
 cp resources/dbus/stc-manager.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/stc-manager.conf
 
+#Upgrade script file
+mkdir -p %{buildroot}%{upgrade_script_path}
+mkdir -p %{buildroot}%{upgrade_data_path}
+cp -f scripts/500.stc-manager-upgrade.sh %{buildroot}%{upgrade_script_path}
+cp -f data/init_stc_db.sh %{buildroot}%{upgrade_data_path}
+
 %post plugin-net-popup
 rm %{_libdir}/stc-plugin-popup.so
 ln -s %{_libdir}/stc-plugin-net-popup.so %{_libdir}/stc-plugin-popup.so
@@ -171,6 +179,8 @@ ln -s %{_libdir}/stc-plugin-stc-popup.so %{_libdir}/stc-plugin-popup.so
 %if %{?enable_database} == YES
 %config(noreplace) %attr(660, root, root) %{database_full_path}
 %config(noreplace) %attr(660, root, root) %{database_full_path}-journal
+%{upgrade_script_path}/500.stc-manager-upgrade.sh
+%{upgrade_data_path}/init_stc_db.sh
 %endif
 
 %files plugin-appstatus
diff --git a/scripts/500.stc-manager-upgrade.sh b/scripts/500.stc-manager-upgrade.sh
new file mode 100644 (file)
index 0000000..7443577
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+#---------------------------------------------------------#
+# stc-manager patch for upgrade (3.0 -> the latest tizen) #
+#---------------------------------------------------------#
+
+# Macro
+UPGRADE_DATA_PATH=/usr/share/upgrade/data/
+NETWORK_DATA_PATH=/opt/usr/data/network/
+DBSPACE_PATH=/opt/usr/dbspace
+
+# Copy the script for creating db
+mkdir -p $NETWORK_DATA_PATH
+cp $UPGRADE_DATA_PATH/init_stc_db.sh $NETWORK_DATA_PATH
+chmod 755 $NETWORK_DATA_PATH/init_stc_db.sh
+
+# Make db
+$NETWORK_DATA_PATH/init_stc_db.sh