Last active
October 16, 2016 15:34
-
-
Save peakwinter/21b09090268de80f4cb51f74e0babdf1 to your computer and use it in GitHub Desktop.
arkOS: Convert ownCloud website installation to Nextcloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
try: | |
import configparser | |
except: | |
import ConfigParser | |
configparser = ConfigParser | |
import arkos | |
import grp | |
import os | |
import pwd | |
import requests | |
import shutil | |
import subprocess | |
import sys | |
from arkos import applications | |
if __name__ == "__main__": | |
try: | |
input = raw_input | |
except NameError: | |
pass | |
print("arkOS - ownCloud to Nextcloud Migration Script") | |
print("-----") | |
print("You may wish to back up your existing installation before continuing.") | |
print() | |
sname = input("Please enter the name of your existing ownCloud site to migrate: ") | |
sdir = os.path.join("/srv/http/webapps", sname) | |
if not os.path.exists(sdir): | |
print("Site not found. Please check the ownCloud site's name and try again.") | |
sys.exit(1) | |
print("Downloading Nextcloud...") | |
data = requests.get("https://download.nextcloud.com/server/releases/nextcloud-10.0.0.zip") | |
with open("/tmp/nextcloud.zip", "wb") as f: | |
f.write(data.content) | |
for x in os.listdir(sdir): | |
if x in ["data", "config", ".arkos"]: | |
continue | |
if os.path.isdir(os.path.join(sdir, x)): | |
shutil.rmtree(os.path.join(sdir, x)) | |
else: | |
os.unlink(os.path.join(sdir, x)) | |
print("Extracting over your existing installation...") | |
subprocess.check_call(["bsdtar", "-xf", "/tmp/nextcloud.zip", "--strip-components=1", "-C", sdir]) | |
uid, gid = pwd.getpwnam("http").pw_uid, grp.getgrnam("http").gr_gid | |
os.chmod(sdir, 0o755) | |
os.chown(sdir, uid, gid) | |
for r, d, f in os.walk(sdir): | |
for x in d: | |
os.chmod(os.path.join(r, x), 0o755) | |
os.chown(os.path.join(r, x), uid, gid) | |
for x in f: | |
os.chmod(os.path.join(r, x), 0o644) | |
os.chown(os.path.join(r, x), uid, gid) | |
print("Upgrading database...") | |
mydir = os.getcwd() | |
os.chdir(sdir) | |
subprocess.check_call(["sudo", "-u", "http", "php", "occ", "upgrade"]) | |
os.chdir(mydir) | |
meta = configparser.SafeConfigParser() | |
meta.read(os.path.join(sdir, ".arkos")) | |
if meta.has_option("website", "app"): | |
meta.set("website", "app", "nextcloud") | |
else: | |
meta.set("website", "type", "nextcloud") | |
with open(os.path.join(sdir, ".arkos"), "w") as f: | |
meta.write(f) | |
if os.path.exists("/var/lib/arkos/applications/owncloud"): | |
shutil.rmtree("/var/lib/arkos/applications/owncloud") | |
arkos.init() | |
a = applications.get("nextcloud") | |
if a: | |
a.install(force=True) | |
print("Migration complete. Now visit the same address as your old ownCloud site to complete the setup!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment