HEX
Server: Apache/2.4.63 (Unix)
System: Linux TOMS-220NAS 4.4.302+ #86009 SMP Wed Nov 26 18:19:17 CST 2025 x86_64
User: flavio87 (1026)
PHP: 8.3.27
Disabled: NONE
Upload Files
File: //var/packages/WordPress/WIZARD_UIFILES/uninstall_uifile_cht.sh
#!/bin/bash

# define main function
MAIN_INSTALL="main_install"
MAIN_UPGRADE="main_upgrade"
MAIN_UNINST="main_uninst"
# define each page's name
PAGE_MARIADB5="page_mariadb5"
PAGE_MARIADB10="page_mariadb10"
PAGE_RESTORE="page_restore"
PAGE_UPGRADE_RESTRICTED="page_upgrade_restricted"
PAGE_DB="page_db"
PAGE_UNINST_DB="page_uninst_db"
PAGE_CONFIRM="page_confirm"
PAGE_CONFIRM_UNINST="page_confirm_uninst"
REQUIRE_DB_SETUP=true
DEFAULT="enu"
# set out file name
OUTPUT_INSTALL="install_uifile"
OUTPUT_UPGRADE="upgrade_uifile"
OUTPUT_UNINST="uninstall_uifile"
INIT_DB_NAME="" # need to be overwritten
INIT_DB_USER="" # need to be overwritten
INFO_FILE="" # need to be overwritten
BACKUP_PATH="" # need to be overwritten
BACKUP_WEB_PATH="" # need to be overwritten
# here to define what page is necessary for each stage: install, upgrade, and uninstall
PAGES_INST="$PAGE_MARIADB5 $PAGE_RESTORE $PAGE_MARIADB10 $PAGE_DB"
PAGES_UPGRADE="$PAGE_UPGRADE_RESTRICTED $PAGE_MARIADB5 $PAGE_MARIADB10 $PAGE_DB $PAGE_CONFIRM"
PAGES_UNINST="$PAGE_UNINST_DB $PAGE_CONFIRM_UNINST"

MainCreate()
{
	local output="$1"
	local pages="$2"
	local main_function="$3"

	if IsWizardEmpty; then
		return
	fi

	for dir in lang/*; do
		local lan=$(basename "$dir")
		local wizard_script="${output}_${lan}.sh"
		cat "wizard_common" > "${wizard_script}"
		cat "lang/$lan" "wizard_customized" $pages "$main_function" >> "${wizard_script}"
		CustomWizCreate "${wizard_script}"
	done
	chmod +x "${output}"*.sh
	cp -a "${output}_${DEFAULT}.sh" "${output}.sh"
}

IsUpgradable()
{
	true
}

IsWizardEmpty()
{
	if $REQUIRE_DB_SETUP; then
		false; return
	fi
	true; return
}

NeedConfirmVirtualHost()
{
	local version="$1"
	if [ ! -z "$version" ] && [ "$version" -lt "1000" ]; then
		local websetted=$(/var/packages/WebStation/target/tools/synowebservice vhost is-web-share-as-vhost-root; echo $?)
		return $websetted
	fi

	return 1

}

CustomHasRunWebsiteSetup()
{
	local path="$1"
	[ -s "$path/$CONF_FILE" ]
}

CustomWizCreate()
{
	:
}

CustomMainInstall()
{
	:
}

CustomGetValueFromMetaFile()
{
	local key="$1"
	local backup_info="/var/packages/.$PKG_DIR.conf"
	local syno_conf="/var/packages/$PKG_NAME/synology.conf"
	local record_file=""

	if [ -s "$INFO_FILE" ]; then
		record_file="$INFO_FILE"
	elif [ -s "$backup_info" ]; then
		record_file="$backup_info"
	elif [ -s "$syno_conf" ]; then
		record_file="$syno_conf"
	else
		return
	fi
	get_key_value "$record_file" "$key"
}

GetPreviousPkgBuildNumber()
{
	local old_pkg_ver="$SYNOPKG_OLD_PKGVER"
	if [ -z "${old_pkg_ver}" ]; then
		# SYNOPKG_OLD_PKGVER does not exist in un-install stage of upgrade
		old_pkg_ver="$SYNOPKG_PKGVER"
	fi

	local old_build_number=$(echo "$old_pkg_ver" | cut -d- -f2)
	echo "$old_build_number"
}

IsPreviousVersionBelowDSM7()
{
	[ "$(GetPreviousPkgBuildNumber)" -lt "1000" ]
}

GetWebsiteRootOfPreviousVersion()
{
	local prev_website_root="$WEBSITE_ROOT"
	if IsPreviousVersionBelowDSM7; then
		prev_website_root=$(echo $WEBSITE_ROOT | sed "s/web_packages/web/g")
	fi

	echo "${prev_website_root}";
}

GetBackupPath()
{
	local backup_prefix="${SYNOPKG_PKGDEST_VOL}/@appdata/$PKG_NAME/.backup"
	echo "$backup_prefix"
}

GetBackupWebDir()
{
	local backup_web_dir="$(GetBackupPath)/backup_web_dir"
	echo "$backup_web_dir"
}

ClearBackupDir()
{
	local backup_path="$(GetBackupPath)"
	local backup_web_dir="$(GetBackupWebDir)"
	rm -rf "$backup_path"
	mkdir -p "$backup_web_dir"
}

InitBackupPath()
{
	BACKUP_PATH="$(GetBackupPath)"
	BACKUP_WEB_PATH="$(GetBackupWebDir)"
}

GetDefaultDSM7LegacyDotPackagePrefix()
{
	local dsm7_legacy_backup_path="/$(readlink /var/services/web_packages | cut -d/ -f2)/@appdata/$PKG_NAME/.$PKG_DIR"
	echo "${dsm7_legacy_backup_path}"
}

GetCustomDSM7LegacyBackupPrefix()
{
	GetDefaultDSM7LegacyDotPackagePrefix
}

GetDefaultDSM6LegacyBackupPrefix()
{
	local dsm6_legacy_backup_path="/$(readlink /var/services/web_packages | cut -d/ -f2)/@appstore/.$PKG_DIR"
	echo "${dsm6_legacy_backup_path}"
}

GetCustomDSM6LegacyBackupPrefix()
{
	GetDefaultDSM6LegacyBackupPrefix
}

GetLegacyBackupDataPrefix()
{
	local dsm6_legacy_backup_path="$(GetCustomDSM6LegacyBackupPrefix)"
	local dsm7_legacy_backup_path="$(GetCustomDSM7LegacyBackupPrefix)"

	local legacy_path=""
	if [ -e "$dsm6_legacy_backup_path" ]; then
		legacy_path="$dsm6_legacy_backup_path"
	fi
	if [ -e "$dsm7_legacy_backup_path" ]; then
		legacy_path="$dsm7_legacy_backup_path"
	fi

	echo "$legacy_path"
}

# we define pages in fuction not in global variables,
# because functions in wizard steps will be merged after calling MainCreate.
CustomSetPages()
{
	if $REQUIRE_DB_SETUP; then
		NEW_INSTALL_PAGES="$(PageM10),$(PageDB)"
		RESTORE_PAGES="$(PageRestore),$(PageM10),$(PageDB)"
		MIGRATE_PAGES="$(PageM5),$(PageRestore),$(PageM10),$(PageDB)"
		UNINSTALL_PAGES="$(PageUninstDB),$(PageConfirmUninstDataLoss)"
	else
		NEW_INSTALL_PAGES=""
		RESTORE_PAGES="$(PageRestore)"
		MIGRATE_PAGES="$(PageRestore)"
		UNINSTALL_PAGES=""
	fi
}

CustomParseDBConf()
{
	:
}

CustomGetDBName()
{
	:
}

CustomGetDBUser()
{
	:
}

CustomGetDBPass()
{
	:
}

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

wizard_db_settings="設定 WordPress 資料庫"
wizard_db_name_desc="請輸入 WordPress 資料庫名稱。"
wizard_db_name_label="資料庫名稱"
wizard_m10_desc="請輸入 MariaDB 10 管理者的帳號密碼,以進行 WordPress 資料庫設定。"
wizard_admin_acc="帳號"
wizard_admin_pass="密碼"
wizard_set_db_desc="請為 WordPress 建立資料庫專屬帳號,以使用原有/全新資料。"
wizard_set_data_title="設定 WordPress"
wizard_found_backup="套件保留資料不相容"
wizard_warn_data_backup_deprecated="此版本與您系統內的此套件保留資料不相容。<br>若您安裝此版本,保留資料將會被刪除。<br>如需留存保留資料,請安裝與前一次相同版本的套件。(先前版本:{prev_version})"
wizard_db_user_account_desc="資料庫使用者帳號"
wizard_db_user_password_desc="資料庫使用者密碼"
wizard_migrate_note="最新版本的 WordPress 僅支援 MariaDB 10。<br>系統已偵測到 MariaDB 5 的資料庫,在下個步驟中,系統會將 MariaDB 5 資料庫轉移至 MariaDB 10。<br><br>請輸入 MariaDB 5 管理者的帳號密碼,以進行安裝。"
wizard_migrate_title="轉移 WordPress 資料庫"
wizard_remove_msql_title="移除 WordPress 資料庫"
wizard_remove_msql_desc="若移除 WordPress 資料庫,全部資料將被刪除。"
wizard_msql_password_desc_remove="請輸入資料庫管理者的帳號密碼來移除 WordPress 資料庫。"
wizard_admin_acc="帳號"
wizard_admin_pass="密碼"
wizard_confirm_page_title="重要通知"
wizard_confirm_check="我已閱讀並了解上述通知"
wizard_database="WordPress 資料庫"
wizard_upload_data="上傳至 WordPress 的資料"
wizard_config_data="WordPress 的設定"
wizard_msql_password_desc="請輸入資料庫管理者密碼。"
wizard_unable_to_upgrade_title="無法更新至此版本"
wizard_upgrade_from_prev_release_required_desc="若要更新套件至此版本,請先更新至<a href=\"{1}\" target=\"_blank\">前一版本</a>。"
wizard_data_will_be_lost_after_uninstallation_warning="解除安裝套件將會刪除所有相關資料。"
wizard_i_know_the_data_will_be_removed="我了解所有相關資料將被刪除"
wizard_vhost_setting_warning="系統已偵測到 Web Station 中至少有一個虛擬主機的根目錄設定在「web」資料夾內。系統更新後,WordPress 的資料夾將從「web」移至「web_packages」資料夾內,因此您將無法透過此虛擬主機存取 WordPress。<br><br>若您希望在系統更新後繼續使用相同的網域名稱,請前往 Web Station > 網頁服務入口並刪除此虛擬主機。<br><br>請注意,WordPress 的資料夾位置變更後,仍會保留 http 群組的存取權限。若使用者欲存取 WordPress 的資料夾,請確認已將該使用者帳號加入 http 群組。"
#!/bin/bash

PKG_NAME="WordPress"
PKG_DIR="wordpress"
WEBSITE_ROOT="/var/services/web_packages/$PKG_DIR"
INFO_FILE="/usr/syno/etc/packages/$PKG_NAME/$PKG_DIR.conf"
CONF_FILE="wp-config.php"
MIGRATE_DB_VERSION="0134"
INIT_DB_NAME="wordpress"
INIT_DB_USER="wordpress_user"

CustomMainInstall()
{
	if [ -d "$BACKUP_PATH" ]; then
		GEN_WP_CONF "$BACKUP_PATH"
	fi
}

GEN_WP_CONF()
{
	local path="$1"
	# before 0122, no version value record
	local version=$(get_key_value "$INFO_FILE" "version")
	if [ ! -s "$path/$CONF_FILE" ] && [ -z "$version" ]; then
		# We need to add back the wp-config.php
		echo "$WP_CONF_FILE" | openssl enc -base64 -d > "$path/$CONF_FILE"
		sed -i "s|'DB_NAME',.*|'DB_NAME','wordpressblog');|g" "$path/$CONF_FILE"
		sed -i "s|'DB_USER',.*|'DB_USER','wordpress');|g" "$path/$CONF_FILE"
		sed -i "s|'DB_PASSWORD',.*|'DB_PASSWORD','');|g" "$path/$CONF_FILE"
	fi
}

CustomParseDBConf()
{
	local path="$1"
	local db_info="$2"
	local grep_info="$3"
	local info_output=""

	if [ -s "$path/$CONF_FILE" ]; then
		info_output=$(grep "$grep_info" "$path/$CONF_FILE" | cut -d\' -f4 | UnQuotePHP)
	fi

	if [ -z "$info_output" ];then
		info_output="$(CustomGetValueFromMetaFile "$db_info")"
	fi

	echo "$info_output"
}

CustomGetDBName()
{
	local db_name=$(CustomParseDBConf "$1" "db_name" "DB_NAME")
	if [ -z "$db_name" ]; then
		db_name="$pkgwizard_db_name"
	fi
	echo "$db_name"
}

CustomGetDBUser()
{
	local db_user=$(CustomParseDBConf "$1" "db_user" "DB_USER")
	if [ -z "$db_user" ]; then
		db_user="$pkgwizard_db_user_account"
	fi
	echo "$db_user"

}

CustomGetDBPass()
{
	CustomParseDBConf "$1" "db_pass" "DB_PASSWORD"
}

UnQuotePHP()
{
	sed -e "s|\\\\'|'|g" -e 's|\\\\|\\|g'
}
PageUninstDB()
{
cat << EOF
{
	"step_title": "$wizard_msql_password_desc",
	"items": [{
		"type": "textfield",
		"desc": "$wizard_msql_password_desc",
		"subitems": [{
			"key": "wizard_m10_acc",
			"desc": "$wizard_admin_acc",
			"defaultValue": "root"
		}]
	}, {
		"type": "password",
		"subitems": [{
			"indent": 1,
			"key": "wizard_m10_pass",
			"desc": "$wizard_admin_pass"
		}]
	}, {
		"type": "multiselect",
		"subitems": [{
			"key": "pkgwizard_remove_additional",
			"defaultValue": true,
			"hidden": true
		}]
	}]
}
EOF
}
PageConfirmUninstDataLoss()
{
cat << EOF
{
    "step_title": "$wizard_confirm_page_title",
    "invalid_next_disabled_v2": true,
    "items": [{
        "type": "multiselect",
        "desc": "$wizard_data_will_be_lost_after_uninstallation_warning",
        "subitems": [{
			"key": "pkgwizard_confirm_check",
            "desc": "$wizard_i_know_the_data_will_be_removed",
            "defaultValue": false,
            "validator": {
                "fn": "{return arguments[0];}"
            }
        }]
    }]
}
EOF
}

main()
{
	CustomSetPages

	local uninstall_page="$UNINSTALL_PAGES"
	if [ -n "$uninstall_page" ]; then
		echo "[$uninstall_page]" > "${SYNOPKG_TEMP_LOGFILE}"
	fi

	return 0
}

main "$@"