Skip to content

Commit

Permalink
rework config to use nextcloud user (#27)
Browse files Browse the repository at this point in the history
* rework config to use nextcloud user

* migrate to new source format

* fix migrations and paths
  • Loading branch information
elvece authored Feb 12, 2024
1 parent 606ce01 commit 56ca41c
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 130 deletions.
30 changes: 23 additions & 7 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,29 @@ server {
}
EOT
elif [[ $home_type = "web-page" ]]; then
directory=$(yq e '.homepage.folder' start9/config.yaml)
source=$(yq e '.homepage.source' start9/config.yaml)
directory=$(yq e '.homepage.source.folder' start9/config.yaml)
source=$(yq e '.homepage.source.type' start9/config.yaml)
path=""

if ! test -d "/mnt/${source}"
then
echo "${source} mountpoint does not exist"
exit 0
fi

if [[ $source = "nextcloud" ]]; then
user=$(yq e '.homepage.source.user' start9/config.yaml)
path="/mnt/${source}/data/${user}/files/${directory}"
else
path="/mnt/${source}/${directory}"
fi
cat >> /etc/nginx/http.d/default.conf <<EOT
server {
autoindex on;
listen 80;
listen [::]:80;
server_name ${tor_address};
root "/mnt/${source}/${directory}";
root ${path};
}
EOT
else
Expand All @@ -73,22 +81,30 @@ fi

for subdomain in "${subdomains[@]}"; do
subdomain_type=$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings |.type" start9/config.yaml)
if [[ $subdomain_type == "web-page" ]]; then
directory="$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings | .folder" start9/config.yaml)"
source="$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings | .source" start9/config.yaml)"\
path=""
if [[ $subdomain_type = "web-page" ]]; then
directory="$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings | .source | .folder" start9/config.yaml)"
source="$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings | .source | .type" start9/config.yaml)"\

if ! test -d "/mnt/${source}"
then
echo "${source} mountpoint does not exist"
exit 0
fi

if [[ $source = "nextcloud" ]]; then
user="$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings | .source | .user" start9/config.yaml)"
path="/mnt/${source}/data/${user}/files/${directory}"
else
path="/mnt/${source}/${directory}"
fi
cat >> /etc/nginx/http.d/default.conf <<EOT
server {
autoindex on;
listen 80;
listen [::]:80;
server_name ${subdomain}.${tor_address};
root "/mnt/${source}/${directory}";
root ${path};
}
EOT
elif [ $subdomain_type = "redirect" ]; then
Expand Down
7 changes: 3 additions & 4 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ build = ["make"]
id = "embassy-pages"
license = "MIT"
release-notes = """
* Update Nextcloud dependency version and data path \n
* Add startup logging \n
* Update Nextcloud configuration option to include user \n
"""
support-site = "https://matrix.to/#/!lMnRwPWnyQvOfAoEnD:matrix.start9labs.com"
title = "Start9 Pages"
upstream-repo = "https://github.com/Start9Labs/start9-pages-startos"
version = "0.1.7.4"
version = "0.1.7.5"
wrapper-repo = "https://github.com/Start9Labs/start9-pages-startos"

[description]
Expand Down Expand Up @@ -70,7 +69,7 @@ volume-id = "main"

[volumes.nextcloud]
package-id = "nextcloud"
path = "/data/admin/files"
path = "/"
readonly = true
type = "pointer"
volume-id = "nextcloud"
Expand Down
47 changes: 47 additions & 0 deletions scripts/migrations/0_1_7_5_down.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { types as T } from "../deps.ts";
import {
matchSubdomains,
matchWebPageHomepageConfig,
matchWebPageHomepageOld,
matchWebPageSubdomain,
matchWebPageSubdomainOld,
} from "./types.ts";

export const revertHomepageConfigSource = (config: T.Config) => {
if (matchWebPageHomepageConfig.test(config)) {
const newHomepage: typeof matchWebPageHomepageOld._TYPE = {
type: config.homepage.type,
source: config.homepage.source.type,
folder: config.homepage.source.folder,
};
return {
...config,
homepage: newHomepage,
};
}
return config;
};

export const revertSubdomainConfigSource = (config: T.Config) => {
if (matchSubdomains.test(config)) {
const newSubdomains = config.subdomains.map((sub) => {
if (matchWebPageSubdomain.test(sub)) {
const newSubdomain: typeof matchWebPageSubdomainOld._TYPE = {
name: sub.name,
settings: {
type: "web-page",
source: sub.settings.source.type,
folder: sub.settings.source.folder,
},
};
return newSubdomain;
}
return sub;
});
return {
...config,
subdomains: newSubdomains,
};
}
return config;
};
94 changes: 94 additions & 0 deletions scripts/migrations/0_1_7_5_up.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { types as T } from "../deps.ts";
import {
matchSubdomains,
matchWebPageHomepage,
matchWebPageHomepageConfigOld,
matchWebPageSubdomain,
matchWebPageSubdomainOld,
} from "./types.ts";

export const convertHomepageConfigSource = (config: T.Config) => {
if (matchWebPageHomepageConfigOld.test(config)) {
switch (config.homepage.source) {
case "nextcloud": {
const newHomepage: typeof matchWebPageHomepage._TYPE = {
type: config.homepage.type,
source: {
type: config.homepage.source,
folder: config.homepage.folder,
user: "embassy",
},
};
return {
...config,
homepage: newHomepage,
};
}
case "filebrowser": {
const newHomepage: typeof matchWebPageHomepage._TYPE = {
type: config.homepage.type,
source: {
type: config.homepage.source,
folder: config.homepage.folder!,
},
};
return {
...config,
homepage: newHomepage,
};
}
default: {
break;
}
}
}
return config;
};

export const convertSubdomainConfigSource = (config: T.Config) => {
if (matchSubdomains.test(config)) {
const newSubdomains = config.subdomains.map((sub) => {
if (matchWebPageSubdomainOld.test(sub)) {
switch (sub.settings.source) {
case "nextcloud": {
const newSubdomain: typeof matchWebPageSubdomain._TYPE = {
name: sub.name,
settings: {
type: "web-page",
source: {
type: sub.settings.source,
folder: sub.settings.folder,
// default username prior to nextcloud v26 when it was changed to admin
user: "embassy",
},
},
};
return newSubdomain;
}
case "filebrowser": {
const newSubdomain: typeof matchWebPageSubdomain._TYPE = {
name: sub.name,
settings: {
type: "web-page",
source: {
type: sub.settings.source,
folder: sub.settings.folder,
},
},
};
return newSubdomain;
}
default: {
break;
}
}
}
return sub;
});
return {
...config,
subdomains: newSubdomains,
};
}
return config;
};
14 changes: 8 additions & 6 deletions scripts/migrations/0_1_7_down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import {
matchFilebrowserHomepage,
matchFilebrowserSubdomain,
matchSubdomains,
matchWebPageHomepageConfig,
matchWebPageSubdomain,
matchWebPageHomepageConfigOld,
matchWebPageSubdomainOld,
} from "./types.ts";

export const revertHomepageConfig = (config: T.Config) => {
if (matchWebPageHomepageConfig.test(config)) {
if (matchWebPageHomepageConfigOld.test(config)) {
const newHomepage: typeof matchFilebrowserHomepage._TYPE = {
type: "filebrowser",
directory: config.homepage.folder,
};
delete config.homepage.source;
delete config.homepage.folder;
// deno-lint-ignore no-explicit-any
delete (config.homepage as any).source;
// deno-lint-ignore no-explicit-any
delete (config.homepage as any).folder;
return {
...config,
homepage: newHomepage
Expand All @@ -26,7 +28,7 @@ export const revertHomepageConfig = (config: T.Config) => {
export const revertSubdomainConfig = (config: T.Config) => {
if (matchSubdomains.test(config)) {
const newSubdomains = config.subdomains.map((sub) => {
if (matchWebPageSubdomain.test(sub)) {
if (matchWebPageSubdomainOld.test(sub)) {
const newSubdomain: typeof matchFilebrowserSubdomain._TYPE = {
name: sub.name,
settings: {
Expand Down
8 changes: 4 additions & 4 deletions scripts/migrations/0_1_7_up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {
matchFilebrowserHomepageConfig,
matchFilebrowserSubdomain,
matchSubdomains,
matchWebPageHomepage,
matchWebPageSubdomain,
matchWebPageHomepageOld,
matchWebPageSubdomainOld,
} from "./types.ts";

export const convertHomepageConfig = (config: T.Config) => {
if (matchFilebrowserHomepageConfig.test(config)) {
const newHomepage: typeof matchWebPageHomepage._TYPE = {
const newHomepage: typeof matchWebPageHomepageOld._TYPE = {
type: "web-page",
source: "filebrowser",
folder: config.homepage.directory!,
Expand All @@ -26,7 +26,7 @@ export const convertSubdomainConfig = (config: T.Config) => {
if (matchSubdomains.test(config)) {
const newSubdomains = config.subdomains.map((sub) => {
if (matchFilebrowserSubdomain.test(sub)) {
const newSubdomain: typeof matchWebPageSubdomain._TYPE = {
const newSubdomain: typeof matchWebPageSubdomainOld._TYPE = {
name: sub.name,
settings: {
type: "web-page",
Expand Down
50 changes: 37 additions & 13 deletions scripts/migrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,42 @@ import { matches } from "../deps.ts";

const { shape, string, literal, any, arrayOf } = matches;


export const matchFilebrowserHomepage = shape({
type: literal("filebrowser"),
directory: string,
}, ["directory"])
type: literal("filebrowser"),
directory: string,
}, ["directory"]);

export const matchWebPageHomepageOld = shape({
type: string,
source: string,
folder: string,
});

export const matchWebPageHomepage = shape({
type: string,
source: shape({
type: string,
source: string,
folder: string,
}, ["source", "folder"])
user: string,
}, ["user"]),
});

export const matchFuckOffHomepageConfig = shape({
homepage: shape({
type: literal("fuck-off"),
})
})
homepage: shape({
type: literal("fuck-off"),
}),
});

export const matchFilebrowserHomepageConfig = shape({
homepage: matchFilebrowserHomepage
homepage: matchFilebrowserHomepage,
});

export const matchWebPageHomepageConfig = shape({
homepage: matchWebPageHomepage
homepage: matchWebPageHomepage,
});

export const matchWebPageHomepageConfigOld = shape({
homepage: matchWebPageHomepageOld,
});

export const matchFilebrowserSubdomain = shape({
Expand All @@ -36,7 +48,7 @@ export const matchFilebrowserSubdomain = shape({
}),
});

export const matchWebPageSubdomain = shape({
export const matchWebPageSubdomainOld = shape({
name: string,
settings: shape({
type: string,
Expand All @@ -45,6 +57,18 @@ export const matchWebPageSubdomain = shape({
}),
});

export const matchWebPageSubdomain = shape({
name: string,
settings: shape({
type: string,
source: shape({
type: string,
folder: string,
user: string,
}, ["user"]),
}),
});

export const matchSubdomains = shape({
subdomains: arrayOf(shape({
name: string,
Expand Down
Loading

0 comments on commit 56ca41c

Please sign in to comment.