Created
August 23, 2015 22:48
-
-
Save peakwinter/f5142137f10135f0bcd7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python2 | |
import ConfigParser | |
import getpass | |
import glob | |
import os | |
import pacman | |
import shutil | |
import subprocess | |
import arkos | |
from arkos import secrets, applications, config | |
from arkos.system import users, domains, services | |
def start(): | |
print "=====================================" | |
print "arkOS 0.7 Migration Script" | |
print "=====================================" | |
print "" | |
print "This script will help you transition to arkOS 0.7 from an existing installation of Genesis 0.6.x." | |
print "It makes no warranties as to the state or accuracy of your installation after the migration, as the best way is to run a fresh install." | |
print "Please press Enter to begin, or Ctrl+C to quit." | |
raw_input() | |
def sitedata(): | |
print " >>> STEP 1: Migrating your site metadata and certificates..." | |
for x in glob.glob('/etc/nginx/sites-available/.*.ginf'): | |
old, new = ConfigParser.RawConfigParser(), ConfigParser.RawConfigParser() | |
old.read(x) | |
new.add_section("website") | |
new.set("website", "id", old.get("website", "name")) | |
new.set("website", "type", old.get("website", "stype")) | |
new.set("website", "version", old.get("website", "version")) | |
new.set("website", "ssl", old.get("website", "ssl")) | |
if old.get("website", "dbengine"): | |
new.set("website", "dbengine", "db-"+old.get("website", "dbengine").lower()) | |
if old.get("website", "stype") == "owncloud": | |
print "ownCloud site detected. Are you using a custom data directory? If so, enter the path below. If not, leave blank." | |
p = raw_input() | |
if p: | |
new.set("website", "data_path", p) | |
with open(os.path.join("/srv/http/webapps", old.get("website", "name"), ".arkos"), "w") as f: | |
new.write(f) | |
os.unlink(x) | |
if not os.path.exists("/etc/arkos/ssl"): | |
os.makedirs("/etc/arkos/ssl") | |
if not os.path.exists("/etc/arkos/ssl/certs"): | |
os.makedirs("/etc/arkos/ssl/certs") | |
if not os.path.exists("/etc/arkos/ssl/keys"): | |
os.makedirs("/etc/arkos/ssl/keys") | |
if not os.path.exists("/etc/arkos/ssl/ca_certs"): | |
os.makedirs("/etc/arkos/ssl/ca_certs") | |
if not os.path.exists("/etc/arkos/ssl/ca_keys"): | |
os.makedirs("/etc/arkos/ssl/ca_keys") | |
for x in glob.glob("/etc/ssl/certs/genesis/*.crt"): | |
os.rename(x, os.path.join("/etc/arkos/ssl/certs", os.path.basename(x))) | |
for x in glob.glob("/etc/ssl/private/genesis/*.key"): | |
os.rename(x, os.path.join("/etc/arkos/ssl/keys", os.path.basename(x))) | |
for x in glob.glob("/etc/ssl/certs/genesis/ca/*.crt"): | |
os.rename(x, os.path.join("/etc/arkos/ssl/ca_certs", os.path.basename(x))) | |
for x in glob.glob("/etc/ssl/private/genesis/ca/*.key"): | |
os.rename(x, os.path.join("/etc/arkos/ssl/ca_keys", os.path.basename(x))) | |
if os.path.exists("/etc/ssl/certs/genesis"): | |
shutil.rmtree("/etc/ssl/certs/genesis") | |
if os.path.exists("/etc/ssl/private/genesis"): | |
shutil.rmtree("/etc/ssl/private/genesis") | |
def newplugins(): | |
print " >>> STEP 2: Removing old applications and downloading latest versions..." | |
if not os.path.exists("/var/lib/arkos/applications"): | |
os.makedirs("/var/lib/arkos/applications") | |
for x in glob.glob("/var/lib/genesis/plugins/*"): | |
name = os.path.basename(x) | |
if name in ["etherpad", "gitweb", "nodejs", "php", "python", | |
"ruby", "reverseproxy", "sparkleshare", "ssh", "transmission", "umurmur"]: | |
continue | |
app = applications.get(name) | |
if app and not app.installed: | |
app.install() | |
shutil.rmtree(x) | |
def updconf(): | |
print " >>> STEP 3: Updating configuration..." | |
if "db-mariadb" in os.listdir("/var/lib/arkos/applications"): | |
print "Please enter your MariaDB root password:" | |
data = getpass.getpass() or "admin" | |
secrets.set("mysql", data) | |
secrets.save() | |
old = ConfigParser.RawConfigParser() | |
old.read("/etc/genesis/genesis.conf") | |
if not domains.get("arkos.local"): | |
d = domains.Domain("arkos.local") | |
d.add() | |
for x in old.options("users"): | |
passwd = passwd_prompt(x) | |
u = users.User(name=x, first_name=x, last_name="", domain="arkos.local", admin=True, sudo=True) | |
u.add(passwd) | |
config.set("genesis", "anonymous", old.get("genesis", "auth_enabled") == 0) | |
config.set("genesis", "host", old.get("genesis", "bind_host") or "0.0.0.0") | |
config.set("genesis", "port", old.get("genesis", "bind_port") or 8000) | |
config.set("genesis", "ssl", old.get("genesis", "ssl") == 1) | |
config.set("genesis", "cert_file", old.get("genesis", "cert_file") or "") | |
config.set("genesis", "key_file", old.get("genesis", "cert_key") or "") | |
config.set("genesis", "firstrun", True) | |
config.save() | |
def passwd_prompt(name): | |
print "Please enter a new password for user %s:" % name | |
passwd = getpass.getpass() | |
print "Confirm password:" | |
passwd2 = getpass.getpass() | |
if passwd != passwd2: | |
print "Passwords are not the same, please try again" | |
passwd = passwd_prompt(name) | |
return passwd | |
if __name__ == '__main__': | |
start() | |
subprocess.call(["systemctl", "start", "arkos-redis", "slapd"]) | |
arkos.init() | |
sitedata() | |
newplugins() | |
updconf() | |
subprocess.call(["systemctl", "start", "avahi-daemon", "krakend"]) | |
pacman.remove("genesis") | |
print "Finished migration!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment