source: branches/version-2_13-dev/eccube_install.sh @ 23552

Revision 23552, 7.5 KB checked in by shutta, 7 years ago (diff)

#1980 インストールシェルの2.12対応
シーケンステーブル作成部分を関数化して分離。

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
Line 
1#!/bin/sh
2
3######################################################################
4#
5# EC-CUBE のインストールを行う shell スクリプト
6#
7#
8# #処理内容
9# 1. パーミッション変更
10# 2. html/install/sql 配下の SQL を実行
11# 3. 管理者権限をアップデート
12# 4. data/config/config.php を生成
13#
14# 使い方
15# Configurationの内容を自分の環境に併せて修正
16# PostgreSQLの場合は、DBユーザーを予め作成しておいて
17# # ./ec_cube_install.sh pgsql
18# MySQLはMYSQLのRoot以外のユーザーで実行する場合は、128行目をコメントアウトして
19# # ./ec_cube_install.sh mysql
20#
21#
22# 開発コミュニティの関連スレッド
23# http://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=4918&forum=14&post_id=23090#forumpost23090
24#
25#######################################################################
26
27#######################################################################
28# Configuration
29#-- Shop Configuration
30CONFIG_PHP="data/config/config.php"
31ADMIN_MAIL=${ADMIN_MAIL:-"admin@example.com"}
32SHOP_NAME=${SHOP_NAME:-"EC-CUBE SHOP"}
33HTTP_URL=${HTTP_URL:-"http://test.local"}
34HTTPS_URL=${HTTPS_URL:-"http://test.local/"}
35ROOT_URLPATH=${ROOT_URLPATH:-"/"}
36DOMAIN_NAME=${DOMAIN_NAME:-""}
37ADMIN_DIR=${ADMIN_DIR:-"admin/"}
38
39DBSERVER=${DBSERVER-"127.0.0.1"}
40DBNAME=${DBNAME:-"cube213_dev"}
41DBUSER=${DBUSER:-"cube213_dev_user"}
42DBPASS=${DBPASS:-"password"}
43
44ADMINPASS="f6b126507a5d00dbdbb0f326fe855ddf84facd57c5603ffdf7e08fbb46bd633c"
45AUTH_MAGIC="droucliuijeanamiundpnoufrouphudrastiokec"
46
47DBTYPE=$1;
48
49case "${DBTYPE}" in
50"pgsql" )
51    #-- DB Seting Postgres
52    PSQL=psql
53    PGUSER=postgres
54    DROPDB=dropdb
55    CREATEDB=createdb
56    DBPORT=5432
57;;
58"mysql" )
59    #-- DB Seting MySQL
60    MYSQL=mysql
61    ROOTUSER=root
62    ROOTPASS=$DBPASS
63    DBSERVER="127.0.0.1"
64    DBPORT=3306
65;;
66* ) echo "ERROR:: argument is invaid"
67exit
68;;
69esac
70
71
72#######################################################################
73# Functions
74
75create_sequence_tables()
76{
77    SEQUENCES="
78dtb_best_products_best_id_seq
79dtb_bloc_bloc_id_seq
80dtb_category_category_id_seq
81dtb_class_class_id_seq
82dtb_classcategory_classcategory_id_seq
83dtb_csv_no_seq
84dtb_csv_sql_sql_id_seq
85dtb_customer_customer_id_seq
86dtb_deliv_deliv_id_seq
87dtb_holiday_holiday_id_seq
88dtb_kiyaku_kiyaku_id_seq
89dtb_mail_history_send_id_seq
90dtb_maker_maker_id_seq
91dtb_member_member_id_seq
92dtb_module_update_logs_log_id_seq
93dtb_news_news_id_seq
94dtb_order_order_id_seq
95dtb_order_detail_order_detail_id_seq
96dtb_other_deliv_other_deliv_id_seq
97dtb_pagelayout_page_id_seq
98dtb_payment_payment_id_seq
99dtb_products_class_product_class_id_seq
100dtb_products_product_id_seq
101dtb_review_review_id_seq
102dtb_send_history_send_id_seq
103dtb_mailmaga_template_template_id_seq
104dtb_plugin_plugin_id_seq
105dtb_plugin_hookpoint_plugin_hookpoint_id_seq
106dtb_api_config_api_config_id_seq
107dtb_api_account_api_account_id_seq
108dtb_tax_rule_tax_rule_id_seq
109"
110
111    comb_sql="";
112    for S in $SEQUENCES; do
113        case ${DBTYPE} in
114            pgsql)
115                sql=$(echo "CREATE SEQUENCE ${S} START 10000;")
116            ;;
117            mysql)
118                sql=$(echo "CREATE TABLE ${S} (
119                        sequence int(11) NOT NULL AUTO_INCREMENT,
120                        PRIMARY KEY (sequence)
121                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
122                    LOCK TABLES ${S} WRITE;
123                    INSERT INTO ${S} VALUES (10000);
124                    UNLOCK TABLES;")
125            ;;
126        esac
127
128        comb_sql=${comb_sql}${sql}
129    done;
130
131    case ${DBTYPE} in
132        pgsql)
133            echo ${comb_sql} | sudo -u ${PGUSER} ${PSQL} -U ${DBUSER} ${DBNAME}
134        ;;
135        mysql)
136            echo ${comb_sql} | ${MYSQL} -u ${DBUSER} ${PASSOPT} ${DBNAME}
137        ;;
138    esac
139}
140
141create_config_php()
142{
143    cat > "./${CONFIG_PHP}" <<__EOF__
144<?php
145define('ECCUBE_INSTALL', 'ON');
146define('HTTP_URL', '${HTTP_URL}');
147define('HTTPS_URL', '${HTTPS_URL}');
148define('ROOT_URLPATH', '${ROOT_URLPATH}');
149define('DOMAIN_NAME', '${DOMAIN_NAME}');
150define('DB_TYPE', '${DBTYPE}');
151define('DB_USER', '${DBUSER}');
152define('DB_PASSWORD', '${CONFIGPASS:-$DBPASS}');
153define('DB_SERVER', '${DBSERVER}');
154define('DB_NAME', '${DBNAME}');
155define('DB_PORT', '${DBPORT}');
156define('ADMIN_DIR', '${ADMIN_DIR}');
157define('ADMIN_FORCE_SSL', FALSE);
158define('ADMIN_ALLOW_HOSTS', 'a:0:{}');
159define('AUTH_MAGIC', '${AUTH_MAGIC}');
160define('PASSWORD_HASH_ALGOS', 'sha256');
161define('MAIL_BACKEND', 'mail');
162define('SMTP_HOST', '');
163define('SMTP_PORT', '');
164define('SMTP_USER', '');
165define('SMTP_PASSWORD', '');
166
167__EOF__
168}
169
170
171#######################################################################
172# Install
173
174#-- Update Permissions
175echo "update permissions..."
176chmod -R go+w "./html"
177chmod go+w "./data"
178chmod -R go+w "./data/Smarty"
179chmod -R go+w "./data/cache"
180chmod -R go+w "./data/class"
181chmod -R go+w "./data/class_extends"
182chmod go+w "./data/config"
183chmod -R go+w "./data/download"
184chmod -R go+w "./data/downloads"
185chmod go+w "./data/fonts"
186chmod go+w "./data/include"
187chmod go+w "./data/logs"
188chmod -R go+w "./data/module"
189chmod go+w "./data/smarty_extends"
190chmod go+w "./data/upload"
191chmod go+w "./data/upload/csv"
192
193#-- Setup Database
194SQL_DIR="./html/install/sql"
195OPTIONAL_SQL_FILE=optional.sql
196if [ -f ${OPTIONAL_SQL_FILE} ]
197then
198    echo "remove optional SQL"
199    rm ${OPTIONAL_SQL_FILE}
200fi
201
202echo "create optional SQL..."
203echo "INSERT INTO dtb_member (member_id, login_id, password, salt, work, del_flg, authority, creator_id, rank, update_date) VALUES (2, 'admin', '${ADMINPASS}', '${AUTH_MAGIC}', '1', '0', '0', '0', '1', current_timestamp);" >> ${OPTIONAL_SQL_FILE}
204echo "INSERT INTO dtb_baseinfo (id, shop_name, email01, email02, email03, email04, top_tpl, product_tpl, detail_tpl, mypage_tpl, update_date) VALUES (1, '${SHOP_NAME}', '${ADMIN_MAIL}', '${ADMIN_MAIL}', '${ADMIN_MAIL}', '${ADMIN_MAIL}', 'default1', 'default1', 'default1', 'default1', current_timestamp);" >> ${OPTIONAL_SQL_FILE}
205
206case "${DBTYPE}" in
207"pgsql" )
208    # PostgreSQL
209    echo "dropdb..."
210    sudo -u ${PGUSER} ${DROPDB} ${DBNAME}
211    echo "createdb..."
212    sudo -u ${PGUSER} ${CREATEDB} -U ${DBUSER} ${DBNAME}
213    echo "create table..."
214    sudo -u ${PGUSER} ${PSQL} -U ${DBUSER} -f ${SQL_DIR}/create_table_pgsql.sql ${DBNAME}
215    echo "insert data..."
216    sudo -u ${PGUSER} ${PSQL} -U ${DBUSER} -f ${SQL_DIR}/insert_data.sql ${DBNAME}
217    echo "create sequence table..."
218    create_sequence_tables
219    echo "execute optional SQL..."
220    sudo -u ${PGUSER} ${PSQL} -U ${DBUSER} -f ${OPTIONAL_SQL_FILE} ${DBNAME}
221;;
222"mysql" )
223    DBPASS=`echo $DBPASS | tr -d " "`
224    if [ -n ${DBPASS} ]; then
225    PASSOPT="--password=$DBPASS"
226    CONFIGPASS=$DBPASS
227    fi
228    # MySQL
229    echo "dropdb..."
230    ${MYSQL} -u ${ROOTUSER} ${PASSOPT} -e "drop database \`${DBNAME}\`"
231    echo "createdb..."
232    ${MYSQL} -u ${ROOTUSER} ${PASSOPT} -e "create database \`${DBNAME}\`"
233    #echo "grant user..."
234    #${MYSQL} -u ${ROOTUSER} ${PASSOPT} -e "GRANT ALL ON \`${DBNAME}\`.* TO '${DBUSER}'@'%' IDENTIFIED BY '${DBPASS}'"
235    echo "create table..."
236    echo "SET SESSION storage_engine = InnoDB;" |
237        cat - ${SQL_DIR}/create_table_mysql.sql |
238        ${MYSQL} -u ${DBUSER} ${PASSOPT} ${DBNAME}
239    echo "insert data..."
240    ${MYSQL} -u ${DBUSER} ${PASSOPT} ${DBNAME} < ${SQL_DIR}/insert_data.sql
241    echo "create sequence table..."
242    create_sequence_tables
243    echo "execute optional SQL..."
244    ${MYSQL} -u ${DBUSER} ${PASSOPT} ${DBNAME} < ${OPTIONAL_SQL_FILE}
245;;
246esac
247
248#-- Setup Initial Data
249
250echo "copy images..."
251cp -rv "./html/install/save_image" "./html/upload/"
252
253echo "creating ${CONFIG_PHP}..."
254create_config_php
255
256echo "Finished Successful!"
Note: See TracBrowser for help on using the repository browser.