source: branches/version-2_13_3/eccube_install.sh @ 23554

Revision 23554, 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
75adjust_directory_permissions()
76{
77    chmod -R go+w "./html"
78    chmod go+w "./data"
79    chmod -R go+w "./data/Smarty"
80    chmod -R go+w "./data/cache"
81    chmod -R go+w "./data/class"
82    chmod -R go+w "./data/class_extends"
83    chmod go+w "./data/config"
84    chmod -R go+w "./data/download"
85    chmod -R go+w "./data/downloads"
86    chmod go+w "./data/fonts"
87    chmod go+w "./data/include"
88    chmod go+w "./data/logs"
89    chmod -R go+w "./data/module"
90    chmod go+w "./data/smarty_extends"
91    chmod go+w "./data/upload"
92    chmod go+w "./data/upload/csv"
93}
94
95create_sequence_tables()
96{
97    SEQUENCES="
98dtb_best_products_best_id_seq
99dtb_bloc_bloc_id_seq
100dtb_category_category_id_seq
101dtb_class_class_id_seq
102dtb_classcategory_classcategory_id_seq
103dtb_csv_no_seq
104dtb_csv_sql_sql_id_seq
105dtb_customer_customer_id_seq
106dtb_deliv_deliv_id_seq
107dtb_holiday_holiday_id_seq
108dtb_kiyaku_kiyaku_id_seq
109dtb_mail_history_send_id_seq
110dtb_maker_maker_id_seq
111dtb_member_member_id_seq
112dtb_module_update_logs_log_id_seq
113dtb_news_news_id_seq
114dtb_order_order_id_seq
115dtb_order_detail_order_detail_id_seq
116dtb_other_deliv_other_deliv_id_seq
117dtb_pagelayout_page_id_seq
118dtb_payment_payment_id_seq
119dtb_products_class_product_class_id_seq
120dtb_products_product_id_seq
121dtb_review_review_id_seq
122dtb_send_history_send_id_seq
123dtb_mailmaga_template_template_id_seq
124dtb_plugin_plugin_id_seq
125dtb_plugin_hookpoint_plugin_hookpoint_id_seq
126dtb_api_config_api_config_id_seq
127dtb_api_account_api_account_id_seq
128dtb_tax_rule_tax_rule_id_seq
129"
130
131    comb_sql="";
132    for S in $SEQUENCES; do
133        case ${DBTYPE} in
134            pgsql)
135                sql=$(echo "CREATE SEQUENCE ${S} START 10000;")
136            ;;
137            mysql)
138                sql=$(echo "CREATE TABLE ${S} (
139                        sequence int(11) NOT NULL AUTO_INCREMENT,
140                        PRIMARY KEY (sequence)
141                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
142                    LOCK TABLES ${S} WRITE;
143                    INSERT INTO ${S} VALUES (10000);
144                    UNLOCK TABLES;")
145            ;;
146        esac
147
148        comb_sql=${comb_sql}${sql}
149    done;
150
151    case ${DBTYPE} in
152        pgsql)
153            echo ${comb_sql} | sudo -u ${PGUSER} ${PSQL} -U ${DBUSER} ${DBNAME}
154        ;;
155        mysql)
156            echo ${comb_sql} | ${MYSQL} -u ${DBUSER} ${PASSOPT} ${DBNAME}
157        ;;
158    esac
159}
160
161get_optional_sql()
162{
163    echo "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);"
164    echo "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);"
165}
166
167create_config_php()
168{
169    cat > "./${CONFIG_PHP}" <<__EOF__
170<?php
171define('ECCUBE_INSTALL', 'ON');
172define('HTTP_URL', '${HTTP_URL}');
173define('HTTPS_URL', '${HTTPS_URL}');
174define('ROOT_URLPATH', '${ROOT_URLPATH}');
175define('DOMAIN_NAME', '${DOMAIN_NAME}');
176define('DB_TYPE', '${DBTYPE}');
177define('DB_USER', '${DBUSER}');
178define('DB_PASSWORD', '${CONFIGPASS:-$DBPASS}');
179define('DB_SERVER', '${DBSERVER}');
180define('DB_NAME', '${DBNAME}');
181define('DB_PORT', '${DBPORT}');
182define('ADMIN_DIR', '${ADMIN_DIR}');
183define('ADMIN_FORCE_SSL', FALSE);
184define('ADMIN_ALLOW_HOSTS', 'a:0:{}');
185define('AUTH_MAGIC', '${AUTH_MAGIC}');
186define('PASSWORD_HASH_ALGOS', 'sha256');
187define('MAIL_BACKEND', 'mail');
188define('SMTP_HOST', '');
189define('SMTP_PORT', '');
190define('SMTP_USER', '');
191define('SMTP_PASSWORD', '');
192
193__EOF__
194}
195
196
197#######################################################################
198# Install
199
200#-- Update Permissions
201echo "update permissions..."
202adjust_directory_permissions
203
204#-- Setup Database
205SQL_DIR="./html/install/sql"
206
207case "${DBTYPE}" in
208"pgsql" )
209    # PostgreSQL
210    echo "dropdb..."
211    sudo -u ${PGUSER} ${DROPDB} ${DBNAME}
212    echo "createdb..."
213    sudo -u ${PGUSER} ${CREATEDB} -U ${DBUSER} ${DBNAME}
214    echo "create table..."
215    sudo -u ${PGUSER} ${PSQL} -U ${DBUSER} -f ${SQL_DIR}/create_table_pgsql.sql ${DBNAME}
216    echo "insert data..."
217    sudo -u ${PGUSER} ${PSQL} -U ${DBUSER} -f ${SQL_DIR}/insert_data.sql ${DBNAME}
218    echo "create sequence table..."
219    create_sequence_tables
220    echo "execute optional SQL..."
221    get_optional_sql | sudo -u ${PGUSER} ${PSQL} -U ${DBUSER} ${DBNAME}
222;;
223"mysql" )
224    DBPASS=`echo $DBPASS | tr -d " "`
225    if [ -n ${DBPASS} ]; then
226    PASSOPT="--password=$DBPASS"
227    CONFIGPASS=$DBPASS
228    fi
229    # MySQL
230    echo "dropdb..."
231    ${MYSQL} -u ${ROOTUSER} ${PASSOPT} -e "drop database \`${DBNAME}\`"
232    echo "createdb..."
233    ${MYSQL} -u ${ROOTUSER} ${PASSOPT} -e "create database \`${DBNAME}\`"
234    #echo "grant user..."
235    #${MYSQL} -u ${ROOTUSER} ${PASSOPT} -e "GRANT ALL ON \`${DBNAME}\`.* TO '${DBUSER}'@'%' IDENTIFIED BY '${DBPASS}'"
236    echo "create table..."
237    echo "SET SESSION storage_engine = InnoDB;" |
238        cat - ${SQL_DIR}/create_table_mysql.sql |
239        ${MYSQL} -u ${DBUSER} ${PASSOPT} ${DBNAME}
240    echo "insert data..."
241    ${MYSQL} -u ${DBUSER} ${PASSOPT} ${DBNAME} < ${SQL_DIR}/insert_data.sql
242    echo "create sequence table..."
243    create_sequence_tables
244    echo "execute optional SQL..."
245    get_optional_sql | ${MYSQL} -u ${DBUSER} ${PASSOPT} ${DBNAME}
246;;
247esac
248
249#-- Setup Initial Data
250
251echo "copy images..."
252cp -rv "./html/install/save_image" "./html/upload/"
253
254echo "creating ${CONFIG_PHP}..."
255create_config_php
256
257echo "Finished Successful!"
Note: See TracBrowser for help on using the repository browser.