#!/usr/bin/env sh set -eu cd /var/www/html if wp core is-installed >/dev/null 2>&1; then echo "wp already installed" else wp core install \ --url="http://localhost:8088" \ --title="Indo MVP" \ --admin_user="admin" \ --admin_password="admin123456" \ --admin_email="admin@example.com" \ --skip-email fi wp config set WP_ENVIRONMENT_TYPE local --type=constant >/dev/null 2>&1 || true wp option update timezone_string "Asia/Jakarta" wp option update permalink_structure "/%postname%/" wp rewrite flush --hard wp plugin install woocommerce --activate wp plugin activate indo-mvp-core wp theme activate indo-trade wp option update indo_mvp_enable_chatbox "1" wp option update indo_mvp_enable_inquiry "0" wp option update indo_mvp_enable_whatsapp "0" wp option update indo_mvp_catalog_mode "1" wp option update indo_mvp_whatsapp_number "628123456789" wp option update indo_mvp_notify_emails "admin@example.com" wp option update indo_mvp_default_country "Indonesia" wp option update indo_mvp_auto_inject_product_cta "1" create_page () { title="$1" slug="$2" content="$3" template="${4:-}" if wp post list --post_type=page --name="$slug" --field=ID --format=ids | grep -q '[0-9]'; then echo "page exists: $slug" return fi id="$(wp post create --post_type=page --post_status=publish --post_title="$title" --post_name="$slug" --post_content="$content" --porcelain)" echo "page created: $slug (#$id)" if [ -n "$template" ]; then wp post meta update "$id" _wp_page_template "$template" >/dev/null fi } create_page "Home" "home" "## Pemasok & Produsen untuk Pasar Indonesia\n\nLihat produk, minta penawaran, atau chat WhatsApp untuk respon cepat.\n\nProduk:\n\nhttp://localhost:8088/shop/" create_page "Produk" "products" "## Produk\n\nKunjungi halaman produk kami:\n\nhttp://localhost:8088/shop/" create_page "Tentang Kami" "about-us" "## Tentang Kami\n\nKami adalah produsen & pemasok yang fokus pada kebutuhan pasar Indonesia.\n\nUntuk penawaran cepat, silakan hubungi kami via WhatsApp." create_page "Hubungi Kami" "contact" "## Hubungi Kami\n\n**WhatsApp**: +62 xxx xxxx xxxx\n\n**Email**: sales@domain.com\n\nJam kerja: Senin–Jumat, 09:00–18:00 (WIB)" create_page "FAQ" "faq" "## FAQ\n\n**1) Berapa MOQ?**\n\nMOQ tergantung produk dan spesifikasi." create_page "Shop" "shop" "" privacy_id="$(wp post list --post_type=page --name="privacy-policy" --field=ID --format=ids || true)" if [ -z "$privacy_id" ]; then privacy_id="$(wp post create --post_type=page --post_status=publish --post_title="Kebijakan Privasi" --post_name="privacy-policy" --post_content="## Kebijakan Privasi\n\nKami menghargai privasi Anda." --porcelain)" echo "page created: privacy-policy (#$privacy_id)" fi wp option update wp_page_for_privacy_policy "$privacy_id" create_page "Minta Penawaran" "request-a-quote" "## Minta Penawaran\n\nMohon isi form berikut.\n\n[indo_inquiry_form]\n\n[indo_whatsapp_button label=\"WhatsApp\"]" "page-templates/page-inquiry.php" home_id="$(wp post list --post_type=page --name="home" --field=ID --format=ids | head -n1)" wp option update show_on_front "page" wp option update page_on_front "$home_id" shop_id="$(wp post list --post_type=page --name="shop" --field=ID --format=ids | head -n1)" wp option update woocommerce_shop_page_id "$shop_id" ensure_term () { tax="$1" name="$2" slug="$3" if wp term list "$tax" --field=slug | grep -q "^$slug$"; then return fi wp term create "$tax" "$name" --slug="$slug" >/dev/null } ensure_term product_type "simple" "simple" ensure_term product_cat "Sample" "sample" create_product () { title="$1" slug="$2" price="$3" if wp post list --post_type=product --name="$slug" --field=ID --format=ids | grep -q '[0-9]'; then echo "product exists: $slug" return fi id="$(wp post create --post_type=product --post_status=publish --post_title="$title" --post_name="$slug" --porcelain)" wp term set product_type "$id" simple >/dev/null || true wp term set product_cat "$id" sample >/dev/null || true wp post meta update "$id" _regular_price "$price" >/dev/null wp post meta update "$id" _price "$price" >/dev/null wp post meta update "$id" _stock_status "instock" >/dev/null wp post meta update "$id" _manage_stock "no" >/dev/null echo "product created: $slug (#$id)" } create_product "Sample Product A" "sample-product-a" "12" create_product "Sample Product B" "sample-product-b" "18" create_product "Sample Product C" "sample-product-c" "25" create_product "Sample Product D" "sample-product-d" "9" create_product "Sample Product E" "sample-product-e" "30" create_product "Sample Product F" "sample-product-f" "15" create_product "Sample Product G" "sample-product-g" "22" create_product "Sample Product H" "sample-product-h" "16" create_product "Sample Product I" "sample-product-i" "28" create_product "Sample Product J" "sample-product-j" "11" menu_id="$(wp menu list --fields=term_id,name --format=csv | tail -n +2 | awk -F, '$2=="Primary"{print $1}' | head -n1 || true)" if [ -z "$menu_id" ]; then menu_id="$(wp menu create "Primary" --porcelain)" fi wp menu location assign "$menu_id" primary >/dev/null || true for slug in home products about-us contact faq request-a-quote; do pid="$(wp post list --post_type=page --name="$slug" --field=ID --format=ids | head -n1)" if [ -n "$pid" ]; then wp menu item add-post "$menu_id" "$pid" >/dev/null || true fi done if [ -n "$shop_id" ]; then wp menu item add-post "$menu_id" "$shop_id" >/dev/null || true fi echo "done: http://localhost:8088 (admin/admin123456)"