python
This commit is contained in:
parent
f4594c90b3
commit
ae6c397120
|
|
@ -0,0 +1,84 @@
|
||||||
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use Config::Any;
|
||||||
|
|
||||||
|
unless(-f 'docker-compose.yml') {
|
||||||
|
die "Needs to be run from compose directory! $!";
|
||||||
|
};
|
||||||
|
|
||||||
|
my @files = (
|
||||||
|
'.env'
|
||||||
|
);
|
||||||
|
my $config = Config::Any->load_files( { files => \@files } );
|
||||||
|
|
||||||
|
my $INSTALL="nextc-install.log";
|
||||||
|
my $P1="sudo docker-compose exec -u 1000";
|
||||||
|
my $P2="cd /config/www/nextcloud; php occ";
|
||||||
|
|
||||||
|
# RE=$($P1 nextc bash -c "$P2 status" |grep "installed: false")
|
||||||
|
# if [[ $? -eq 0 && -n $RE ]]; then
|
||||||
|
# read -p "Enter Admin name: " USERNAME
|
||||||
|
# if [[ -z $USERNAME ]]; then printf "Nothing in username\n"; exit; fi
|
||||||
|
# if [[ -d $DATA/ncdata/$USERNAME ]]; then printf "Files exist for user $USERNAME\n"; exit 1; fi
|
||||||
|
#
|
||||||
|
# LOG=""
|
||||||
|
# if [[ -f "${INSTALL}" ]]; then
|
||||||
|
# LOG=$(cat "${INSTALL}")
|
||||||
|
# ROOTPASS="${LOG#*: }"
|
||||||
|
# printf "Found existing database password\n"
|
||||||
|
# else
|
||||||
|
# ROOTPASS="$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 | head -c 10)"
|
||||||
|
# fi
|
||||||
|
#
|
||||||
|
# USERPASS="$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 | head -c 4)"
|
||||||
|
# printf "Admin Name: $USERNAME\n"
|
||||||
|
# printf "Admin Pass: $USERPASS\n"
|
||||||
|
# printf "Database Password: $ROOTPASS\n"
|
||||||
|
# printf "\n"
|
||||||
|
# read -r -s -N 1 -p "Press 'Enter' to continue " ENTER
|
||||||
|
# if [[ $ENTER != $'\n' ]]; then exit; fi
|
||||||
|
# printf "\n"
|
||||||
|
#
|
||||||
|
# if [[ -z $LOG ]]; then
|
||||||
|
# RE=$($P1 nextc-db bash -c "mysqladmin -u root password $ROOTPASS")
|
||||||
|
# if [[ $? -eq 0 ]]; then
|
||||||
|
# printf "Root password changed\n"
|
||||||
|
# printf "ROOTPASS: $ROOTPASS\n" > "${INSTALL}"
|
||||||
|
# else
|
||||||
|
# printf "Error trying to set password\n"
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
|
#
|
||||||
|
# RE=$($P1 nextc bash -c "$P2 maintenance:install --database mysql \
|
||||||
|
# --database-host nextc-db --database-name ncdb --database-user root \
|
||||||
|
# --database-pass $ROOTPASS --admin-user $USERNAME --admin-pass $USERPASS --data-dir /ncdata")
|
||||||
|
# if [[ $? -eq 0 ]]; then
|
||||||
|
# printf "USERNAME: $USERNAME\nUSERPASS: $USERPASS\n" >> "${INSTALL}"
|
||||||
|
# printf "Install success\n"
|
||||||
|
# else
|
||||||
|
# printf "Error installing nextcloud: $RE\n"
|
||||||
|
# exit 1;
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
|
#
|
||||||
|
# read -p "Enter Trusted domain: " DOMAIN
|
||||||
|
#
|
||||||
|
# RE=$($P1 nextc bash -c "$P2 config:system:set trusted_domains 1 --value=nextc")
|
||||||
|
# if [[ $? -eq 0 ]]; then
|
||||||
|
# printf "Trusted Domain nextc set\n"
|
||||||
|
# else
|
||||||
|
# exit 1;
|
||||||
|
# fi
|
||||||
|
# RE=$($P1 nextc bash -c "$P2 config:system:set trusted_domains 2 --value=$DOMAIN")
|
||||||
|
# if [[ $? -eq 0 ]]; then
|
||||||
|
# printf "Trusted Domain $DOMAIN set\n"
|
||||||
|
# else
|
||||||
|
# exit 1;
|
||||||
|
# fi
|
||||||
|
#
|
||||||
|
# set +o xtrace
|
||||||
|
#
|
||||||
|
|
@ -0,0 +1,171 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import dotenv
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import docker
|
||||||
|
import string
|
||||||
|
import random
|
||||||
|
|
||||||
|
def main():
|
||||||
|
INSENV = ".env-nextc"
|
||||||
|
DOCOMP = "docker-compose"
|
||||||
|
USRCMP = ("sudo", DOCOMP, "exec", "-u", "1000")
|
||||||
|
|
||||||
|
if not os.path.exists("docker-compose.yml"):
|
||||||
|
raise ProgramError("Needs to be run from compose directory\n")
|
||||||
|
|
||||||
|
if not os.path.exists(".env"):
|
||||||
|
raise ProgramError("Missing .env file")
|
||||||
|
|
||||||
|
dotenv.load_dotenv(os.environ["PWD"] + "/.env")
|
||||||
|
try:
|
||||||
|
CONF = os.getenv("CONF")
|
||||||
|
except KeyError:
|
||||||
|
raise ProgramError("Missing CONF in .env file")
|
||||||
|
try:
|
||||||
|
DATA = os.getenv("DATA")
|
||||||
|
except KeyError:
|
||||||
|
raise ProgramError("Missing DATA in .env file")
|
||||||
|
|
||||||
|
try:
|
||||||
|
out = open (INSENV, 'a')
|
||||||
|
except PermissionError:
|
||||||
|
raise ProgramError("Error: cannot open " + INSENV + " file")
|
||||||
|
finally:
|
||||||
|
out.close()
|
||||||
|
|
||||||
|
print("Checking for environment file...")
|
||||||
|
if os.path.exists(INSENV):
|
||||||
|
print("...found env file")
|
||||||
|
env = dotenv.dotenv_values(os.environ["PWD"] + "/" + INSENV)
|
||||||
|
else:
|
||||||
|
print("none\n")
|
||||||
|
env = {}
|
||||||
|
|
||||||
|
print("Set DB password attempt...")
|
||||||
|
try:
|
||||||
|
ROOTPASS = env["ROOTPASS"]
|
||||||
|
print("...DB password already applied")
|
||||||
|
except KeyError:
|
||||||
|
print ("...making password")
|
||||||
|
ROOTPASS = "".join(random.choices(string.ascii_uppercase + string.digits, k=10))
|
||||||
|
print ("...setting")
|
||||||
|
cmd = USRCMP + ("nextc-db", "mysqladmin", "-u", "root", "password", ROOTPASS)
|
||||||
|
print (cmd)
|
||||||
|
try:
|
||||||
|
out = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True)
|
||||||
|
except subprocess.CalledProcessError as err:
|
||||||
|
print (err.stderr)
|
||||||
|
print (err.stdout)
|
||||||
|
raise ProgramError("Failure to create DB password")
|
||||||
|
with open (INSENV, 'a') as out:
|
||||||
|
print("ROOTPASS=" + ROOTPASS, file=out)
|
||||||
|
print("...success\n")
|
||||||
|
|
||||||
|
try:
|
||||||
|
USERNAME = env["USERNAME"]
|
||||||
|
except KeyError:
|
||||||
|
USERNAME = input("Enter admin name: ")
|
||||||
|
if USERNAME == "":
|
||||||
|
raise ProgramError("Empty admin name")
|
||||||
|
if os.path.exists(DATA + "/cndata/ncdata/" + USERNAME):
|
||||||
|
raise ProgramError("Data exists for user (please move or delete)")
|
||||||
|
with open (INSENV, 'a') as out:
|
||||||
|
print ("USERNAME=" + USERNAME, file=out)
|
||||||
|
try:
|
||||||
|
USERPASS = env["USERPASS"]
|
||||||
|
except KeyError:
|
||||||
|
USERPASS = "".join(random.choices(string.ascii_uppercase + string.digits, k=4))
|
||||||
|
with open (INSENV, 'a') as out:
|
||||||
|
print("USERPASS=" + USERPASS, file=out)
|
||||||
|
|
||||||
|
print("Checking installed status...")
|
||||||
|
cmd = USRCMP + ("-w", "/config/www/nextcloud", "nextc", "php", "occ", "status")
|
||||||
|
try:
|
||||||
|
out = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
print(out.stderr)
|
||||||
|
raise ProgramError("Failure to check install status (" + out.stderr + ")")
|
||||||
|
if "installed:" not in out.stdout:
|
||||||
|
raise ProgramError("No result from install status test")
|
||||||
|
if "installed: true" in out.stdout:
|
||||||
|
raise ProgramError("Nextcloud is installed")
|
||||||
|
print("...not installed yet")
|
||||||
|
|
||||||
|
print("Attempting install...")
|
||||||
|
cmd = USRCMP + ("-w", "/config/www/nextcloud", "nextc", "php", "occ", "maintenance:install",
|
||||||
|
"--database", "mysql", "--database-host", "nextc-db", "--database-name", "ncdb",
|
||||||
|
"--database-user", "root", "--database-pass", ROOTPASS, "--admin-user", USERNAME,
|
||||||
|
"--admin-pass", USERPASS, "--data-dir", "/ncdata")
|
||||||
|
print (cmd)
|
||||||
|
try:
|
||||||
|
out = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True)
|
||||||
|
except subprocess.CalledProcessError as err:
|
||||||
|
print(err.stderr)
|
||||||
|
print(err.stdout)
|
||||||
|
raise ProgramError("Failure to install")
|
||||||
|
print("...success")
|
||||||
|
|
||||||
|
|
||||||
|
class ProgramError(Exception):
|
||||||
|
""" Program Exception """
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except ProgramError as err:
|
||||||
|
print("Setup of Database and/or Nextcloud failed: " + err.args[0])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# read -p "Enter Trusted domain: " DOMAIN
|
||||||
|
#
|
||||||
|
# RE=$($P1 nextc bash -c "$P2 config:system:set trusted_domains 1 --value=nextc")
|
||||||
|
# if [[ $? -eq 0 ]]; then
|
||||||
|
# printf "Trusted Domain nextc set\n"
|
||||||
|
# else
|
||||||
|
# exit 1;
|
||||||
|
# fi
|
||||||
|
# RE=$($P1 nextc bash -c "$P2 config:system:set trusted_domains 2 --value=$DOMAIN")
|
||||||
|
# if [[ $? -eq 0 ]]; then
|
||||||
|
# printf "Trusted Domain $DOMAIN set\n"
|
||||||
|
# else
|
||||||
|
# exit 1;
|
||||||
|
# fi
|
||||||
|
#
|
||||||
|
# set +o xtrace
|
||||||
|
#
|
||||||
|
#print("%s%s" % (os.environ, "\n"))
|
||||||
|
#globals_ = set(globals());
|
||||||
|
#for name in globals_:
|
||||||
|
# val = eval(name)
|
||||||
|
# print(name, "is", type(val), "and is equal to ", val)
|
||||||
|
#parent_dir = os.path.dirname(__file__)
|
||||||
|
#dotenv.load_dotenv(os.environ["PWD"] + "/.env")
|
||||||
|
#CONF = os.getenv("CONF")
|
||||||
|
#print (CONF, "\n")
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#set -o xtrace
|
set -o xtrace
|
||||||
|
|
||||||
if [[ ! -f docker-compose.yml ]]; then
|
if [[ ! -f docker-compose.yml ]]; then
|
||||||
printf "Needs to be run from compose directory\n"
|
printf "Needs to be run from compose directory\n"
|
||||||
|
|
@ -11,7 +11,7 @@ INSTALL="nextc-install.log"
|
||||||
|
|
||||||
source .env
|
source .env
|
||||||
|
|
||||||
P1="sudo docker compose exec -u 1000"
|
P1="sudo docker-compose exec -u 1000"
|
||||||
P2="cd /config/www/nextcloud; php occ"
|
P2="cd /config/www/nextcloud; php occ"
|
||||||
|
|
||||||
RE=$($P1 nextc bash -c "$P2 status" |grep "installed: false")
|
RE=$($P1 nextc bash -c "$P2 status" |grep "installed: false")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue