Added check if patch has already been done

This commit is contained in:
Zegorax
2020-03-21 23:41:13 +01:00
committed by GitHub
parent f1d7a72d03
commit e320224a3a

View File

@@ -1,21 +1,23 @@
#!/bin/bash #!/bin/bash
apt-get update && apt-get install -y python3.6-dev FILE=OO_PubKey
wget https://bootstrap.pypa.io/get-pip.py if test -f "$FILE"; then
python3.6 get-pip.py apt-get update && apt-get install -y python3.6-dev
pip install pycrypto wget https://bootstrap.pypa.io/get-pip.py
python3.6 get-pip.py
pip install pycrypto
cat <<EOF > index.py cat <<EOF > index.py
from Crypto.Hash import SHA, SHA256 from Crypto.Hash import SHA, SHA256
from Crypto.Signature import PKCS1_v1_5 from Crypto.Signature import PKCS1_v1_5
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
from shutil import copyfile from shutil import copyfile
import json import json
import codecs import codecs
hexlify = codecs.getencoder('hex') hexlify = codecs.getencoder('hex')
licenseFile = { licenseFile = {
"branding": False, "branding": False,
"connections": 9999, "connections": 9999,
"customization": False, "customization": False,
@@ -35,41 +37,41 @@ licenseFile = {
"start_date": "2020-01-01T00:00:00.000Z", "start_date": "2020-01-01T00:00:00.000Z",
"users": [], "users": [],
"version": 2 "version": 2
} }
jsonLicenseFile = codecs.encode(json.dumps(licenseFile, separators=(',', ':')), encoding='utf-8') jsonLicenseFile = codecs.encode(json.dumps(licenseFile, separators=(',', ':')), encoding='utf-8')
privKey = RSA.generate(1024) privKey = RSA.generate(1024)
publKey = privKey.publickey().exportKey('PEM') publKey = privKey.publickey().exportKey('PEM')
digest = SHA.new(jsonLicenseFile) digest = SHA.new(jsonLicenseFile)
signer = PKCS1_v1_5.new(privKey) signer = PKCS1_v1_5.new(privKey)
signature = signer.sign(digest) signature = signer.sign(digest)
finalSignature = signature.hex() finalSignature = signature.hex()
licenseFile['signature'] = finalSignature licenseFile['signature'] = finalSignature
f = open("OO_License", "w+") f = open("OO_License", "w+")
f.write(json.dumps(licenseFile)) f.write(json.dumps(licenseFile))
f.close f.close
f = open("OO_PubKey", "w+") f = open("OO_PubKey", "w+")
f.write(publKey.decode('utf-8')) f.write(publKey.decode('utf-8'))
f.close() f.close()
print("The license file has been saved to OO_License. Here's the content :") print("The license file has been saved to OO_License. Here's the content :")
print(json.dumps(licenseFile)) print(json.dumps(licenseFile))
print("It will be placed automatically in the Data directory of OnlyOffice") print("It will be placed automatically in the Data directory of OnlyOffice")
copyfile("OO_License", "/var/www/onlyoffice/Data/license.lic") copyfile("OO_License", "/var/www/onlyoffice/Data/license.lic")
print("Patching docservice and convert...") print("Patching docservice and convert...")
basePath = "/var/www/onlyoffice/documentserver/server/" basePath = "/var/www/onlyoffice/documentserver/server/"
files = ["DocService/docservice", "FileConverter/converter"] files = ["DocService/docservice", "FileConverter/converter"]
for file in files: for file in files:
f = open(basePath+file, 'rb') f = open(basePath+file, 'rb')
data = f.read() data = f.read()
f.close() f.close()
@@ -80,11 +82,13 @@ for file in files:
f.write(replacedData) f.write(replacedData)
f.close() f.close()
EOF EOF
python3.6 index.py python3.6 index.py
echo Patching docservice and convert... echo Patching docservice and convert...
echo Done! Running Document Server...
fi
echo Done! Running Document Server...
/app/ds/run-document-server.sh /app/ds/run-document-server.sh