94 lines
2.6 KiB
Python
Executable File
94 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import os.path
|
|
import requests
|
|
import time
|
|
import subprocess
|
|
import json
|
|
from hashlib import sha512
|
|
|
|
def hash_password(globalSalt, password):
|
|
globalSalt = globalSalt.encode('utf-8')
|
|
password = password.encode('utf-8')
|
|
return sha512(globalSalt+password+globalSalt).hexdigest()
|
|
|
|
env = os.environ
|
|
wwwRoot = '/var/www/html'
|
|
samRoot = '%s/sam'%wwwRoot
|
|
imageRoot= '%s/image'%wwwRoot
|
|
|
|
if os.path.exists('%s/hwe/d_setting/DB.php'):
|
|
exit(0)
|
|
|
|
while True:
|
|
try:
|
|
r = requests.head('http://web/sam/f_install/j_install_status.php')
|
|
if r.status_code == 200:
|
|
break
|
|
except Exception:
|
|
pass
|
|
print("Waiting for web connection...", flush=True)
|
|
time.sleep(2)
|
|
|
|
while True:
|
|
result = subprocess.call('nc -z -v -w30 db 3306'.split(' '), stderr=subprocess.STDOUT)
|
|
if result == 0:
|
|
break
|
|
print("Waiting for database connection...", flush=True)
|
|
time.sleep(2)
|
|
|
|
session = requests.session()
|
|
|
|
setupDBResult = session.post('http://web/sam/f_install/j_setup_db.php', {
|
|
'db_host':'db',
|
|
'db_port':3306,
|
|
'db_id':env['MYSQL_USER'],
|
|
'db_pw':env['MYSQL_PASSWORD'],
|
|
'db_name':'%s_root'%env['HIDCHE_DB_PREFIX'],
|
|
'serv_host':env['HIDCHE_GAME_PATH'],
|
|
'shared_icon_path':'%s/icons'%env['HIDCHE_IMAGE_PATH'],
|
|
'game_image_path':'%s/game'%env['HIDCHE_IMAGE_PATH'],
|
|
'kakao_rest_key':env['HIDCHE_KAKAO_REST_KEY'],
|
|
'kakao_admin_key':env['HIDCHE_KAKAO_ADMIN_KEY'],
|
|
})
|
|
|
|
setupDBJsonResult = json.loads(setupDBResult.text)
|
|
print(setupDBJsonResult)
|
|
|
|
globalSalt = setupDBJsonResult['globalSalt']
|
|
|
|
hashPassword = hash_password(globalSalt, env['HIDCHE_PASSWORD'])
|
|
|
|
query = {
|
|
'username':env['HIDCHE_ADMIN'],
|
|
'password':hashPassword,
|
|
'nickname':'운영자'
|
|
}
|
|
print(query)
|
|
setupAdminResult = session.post('http://web/sam/f_install/j_create_admin.php', query)
|
|
setupAdminJsonResult = json.loads(setupAdminResult.text)
|
|
print(setupAdminJsonResult)
|
|
|
|
loginResult=session.post('http://web/sam/j_login.php', query)
|
|
print(loginResult.text)
|
|
|
|
serverList = str(env['HIDCHE_SERVER_LIST']).split(',')
|
|
serverList.reverse()
|
|
for serverName in serverList:
|
|
updateResult = session.post('http://web/sam/j_updateServer.php', {
|
|
'server':serverName,
|
|
'target':'origin/devel'
|
|
})
|
|
print(serverName, updateResult.text)
|
|
|
|
resetResult = session.post('http://web/sam/%s/j_install_db.php'%serverName, {
|
|
'db_host':'db',
|
|
'db_port':3306,
|
|
'db_id':env['MYSQL_USER'],
|
|
'db_pw':env['MYSQL_PASSWORD'],
|
|
'db_name':'%s_%s'%(env['HIDCHE_DB_PREFIX'], serverName),
|
|
})
|
|
print(serverName, resetResult.text)
|
|
|
|
print('Welcome to HIDCHE') |