경로 이동
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
FROM python:3-alpine
|
||||
|
||||
|
||||
RUN pip3 install requests && \
|
||||
rm -r /root/.cache
|
||||
|
||||
COPY install_hidche.py /bin
|
||||
RUN chmod +x /bin/install_hidche.py
|
||||
CMD install_hidche.py
|
||||
Executable
+120
@@ -0,0 +1,120 @@
|
||||
#!/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
|
||||
indexPHP = '%s/index.php'%wwwRoot
|
||||
if os.path.exists('%s/hwe/d_setting/DB.php'):
|
||||
exit(0)
|
||||
|
||||
useWaitIndex = False
|
||||
if not os.path.exists(indexPHP):
|
||||
useWaitIndex = True
|
||||
fp = open(indexPHP, 'wt', encoding='utf-8')
|
||||
fp.write("""
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>HIDCHE - Auto Install Process</title>
|
||||
<meta http-equiv="refresh" content="5"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Please wait for installation.</h1>
|
||||
</body>
|
||||
</html>
|
||||
""")
|
||||
fp.close()
|
||||
|
||||
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()
|
||||
|
||||
db_root_pw = hash_password('root', env['MYSQL_USER']+env['MYSQL_PASSWORD'])[:32]
|
||||
db_root_name = '%s_root'%env['HIDCHE_DB_PREFIX']
|
||||
|
||||
setupDBResult = session.post('http://web/sam/f_install/j_setup_db.php', {
|
||||
'db_host':'db',
|
||||
'db_port':3306,
|
||||
'db_id':db_root_name,
|
||||
'db_pw':db_root_pw,
|
||||
'db_name':db_root_name,
|
||||
'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':'운영자'
|
||||
}
|
||||
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)
|
||||
|
||||
db_pw = hash_password(serverName, env['MYSQL_USER']+env['MYSQL_PASSWORD'])[:32]
|
||||
db_name = '%s_%s'%(env['HIDCHE_DB_PREFIX'], serverName)
|
||||
resetResult = session.post('http://web/sam/%s/j_install_db.php'%serverName, {
|
||||
'db_host':'db',
|
||||
'db_port':3306,
|
||||
'db_id':db_name,
|
||||
'db_pw':db_pw,
|
||||
'db_name':db_name,
|
||||
})
|
||||
print(serverName, resetResult.text)
|
||||
|
||||
if useWaitIndex:
|
||||
fp = open(indexPHP, 'wt', encoding='utf-8')
|
||||
fp.write("<?php header('location:sam',TRUE,301);")
|
||||
fp.close()
|
||||
os.chown(indexPHP, 33, 33)
|
||||
|
||||
print('Welcome to HIDCHE')
|
||||
Reference in New Issue
Block a user