Fix disk setup and documentation for Turnkey VMs (#141)

This commit is contained in:
Håvard Gjøby Thom 2024-11-08 22:27:01 +01:00 committed by GitHub
parent 4c46e9495d
commit 957f7e8ba2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 82 additions and 44 deletions

View File

@ -26,14 +26,14 @@ export default function ScriptAccordion({
undefined, undefined,
); );
const linkRefs = useRef<{ [key: string]: HTMLAnchorElement | null }>({}); const linkRefs = useRef<{ [key: string]: HTMLAnchorElement | null }>({});
const handleAccordionChange = (value: string | undefined) => { const handleAccordionChange = (value: string | undefined) => {
setExpandedItem(value); setExpandedItem(value);
}; };
const handleSelected = useCallback( const handleSelected = useCallback(
(title: string) => { (slug: string) => {
setSelectedScript(title); setSelectedScript(slug);
}, },
[setSelectedScript], [setSelectedScript],
); );
@ -41,7 +41,7 @@ export default function ScriptAccordion({
useEffect(() => { useEffect(() => {
if (selectedScript) { if (selectedScript) {
const category = items.find((category) => const category = items.find((category) =>
category.scripts.some((script) => script.name === selectedScript), category.scripts.some((script) => script.slug === selectedScript),
); );
if (category) { if (category) {
setExpandedItem(category.name); setExpandedItem(category.name);
@ -89,17 +89,17 @@ export default function ScriptAccordion({
<Link <Link
href={{ href={{
pathname: "/scripts", pathname: "/scripts",
query: { id: script.name }, query: { id: script.slug },
}} }}
prefetch={false} prefetch={false}
className={`flex cursor-pointer items-center justify-between gap-1 px-1 py-1 text-muted-foreground hover:rounded-lg hover:bg-accent/60 hover:dark:bg-accent/20 ${ className={`flex cursor-pointer items-center justify-between gap-1 px-1 py-1 text-muted-foreground hover:rounded-lg hover:bg-accent/60 hover:dark:bg-accent/20 ${
selectedScript === script.name selectedScript === script.slug
? "rounded-lg bg-accent font-semibold dark:bg-accent/30 dark:text-white" ? "rounded-lg bg-accent font-semibold dark:bg-accent/30 dark:text-white"
: "" : ""
}`} }`}
onClick={() => handleSelected(script.name)} onClick={() => handleSelected(script.slug)}
ref={(el) => { ref={(el) => {
linkRefs.current[script.name] = el; linkRefs.current[script.slug] = el;
}} }}
> >
<div className="flex items-center"> <div className="flex items-center">

View File

@ -85,7 +85,7 @@ export function LatestScripts({ items }: { items: Category[] }) {
<div className="min-w flex w-full flex-row flex-wrap gap-4"> <div className="min-w flex w-full flex-row flex-wrap gap-4">
{latestScripts.slice(startIndex, endIndex).map((script) => ( {latestScripts.slice(startIndex, endIndex).map((script) => (
<Card <Card
key={script.name} key={script.slug}
className="min-w-[250px] flex-1 flex-grow bg-accent/30" className="min-w-[250px] flex-1 flex-grow bg-accent/30"
> >
<CardHeader> <CardHeader>
@ -121,7 +121,7 @@ export function LatestScripts({ items }: { items: Category[] }) {
<Link <Link
href={{ href={{
pathname: "/scripts", pathname: "/scripts",
query: { id: script.name }, query: { id: script.slug },
}} }}
> >
View Script View Script
@ -153,7 +153,7 @@ export function MostViewedScripts({ items }: { items: Category[] }) {
<div className="min-w flex w-full flex-row flex-wrap gap-4"> <div className="min-w flex w-full flex-row flex-wrap gap-4">
{mostViewedScripts.map((script) => ( {mostViewedScripts.map((script) => (
<Card <Card
key={script.name} key={script.slug}
className="min-w-[250px] flex-1 flex-grow bg-accent/30" className="min-w-[250px] flex-1 flex-grow bg-accent/30"
> >
<CardHeader> <CardHeader>
@ -189,7 +189,7 @@ export function MostViewedScripts({ items }: { items: Category[] }) {
<Link <Link
href={{ href={{
pathname: "/scripts", pathname: "/scripts",
query: { id: script.name }, query: { id: script.slug },
}} }}
prefetch={false} prefetch={false}
> >

View File

@ -3,16 +3,16 @@
export const dynamic = "force-static"; export const dynamic = "force-static";
import ScriptItem from "@/app/scripts/_components/ScriptItem"; import ScriptItem from "@/app/scripts/_components/ScriptItem";
import { fetchCategories } from "@/lib/data";
import { Category, Script } from "@/lib/types"; import { Category, Script } from "@/lib/types";
import { Loader2 } from "lucide-react"; import { Loader2 } from "lucide-react";
import { Suspense, useEffect, useState } from "react";
import Sidebar from "./_components/Sidebar";
import { useQueryState } from "nuqs"; import { useQueryState } from "nuqs";
import { Suspense, useEffect, useState } from "react";
import { import {
LatestScripts, LatestScripts,
MostViewedScripts, MostViewedScripts,
} from "./_components/ScriptInfoBlocks"; } from "./_components/ScriptInfoBlocks";
import { fetchCategories } from "@/lib/data"; import Sidebar from "./_components/Sidebar";
function ScriptContent() { function ScriptContent() {
const [selectedScript, setSelectedScript] = useQueryState("id"); const [selectedScript, setSelectedScript] = useQueryState("id");
@ -24,7 +24,7 @@ function ScriptContent() {
const script = links const script = links
.map((category) => category.scripts) .map((category) => category.scripts)
.flat() .flat()
.find((script) => script.name === selectedScript); .find((script) => script.slug === selectedScript);
setItem(script); setItem(script);
} }
}, [selectedScript, links]); }, [selectedScript, links]);
@ -76,4 +76,4 @@ export default function Page() {
<ScriptContent /> <ScriptContent />
</Suspense> </Suspense>
); );
} }

View File

@ -92,11 +92,11 @@ export default function CommandMenu() {
> >
{category.scripts.map((script) => ( {category.scripts.map((script) => (
<CommandItem <CommandItem
key={`script:${script.name}`} key={`script:${script.slug}`}
value={script.name} value={script.slug}
onSelect={() => { onSelect={() => {
setOpen(false); setOpen(false);
router.push(`/scripts?id=${script.name}`); router.push(`/scripts?id=${script.slug}`);
}} }}
> >
<div className="flex gap-2" onClick={() => setOpen(false)}> <div className="flex gap-2" onClick={() => setOpen(false)}>

View File

@ -12,7 +12,7 @@
"documentation": null, "documentation": null,
"website": null, "website": null,
"logo": "https://github.com/home-assistant/brands/blob/master/core_integrations/jellyfin/icon.png?raw=true", "logo": "https://github.com/home-assistant/brands/blob/master/core_integrations/jellyfin/icon.png?raw=true",
"description": null, "description": "Jellyfin is a free and open-source media server and suite of multimedia applications designed to organize, manage, and share digital media files to networked devices.",
"install_methods": [ "install_methods": [
{ {
"type": "default", "type": "default",

34
json/nextcloud-vm.json Normal file
View File

@ -0,0 +1,34 @@
{
"name": "Nextcloud",
"slug": "nextcloud-vm",
"categories": [
12
],
"date_created": "2023-11-14",
"type": "vm",
"updateable": false,
"privileged": false,
"interface_port": "80",
"documentation": null,
"website": "https://www.turnkeylinux.org/nextcloud",
"logo": "https://raw.githubusercontent.com/loganmarchione/homelab-svg-assets/main/assets/nextcloud.svg",
"description": "TurnKey Nextcloud is an open-source file sharing server and collaboration platform that can store your personal content, like documents and pictures, in a centralized location.",
"install_methods": [
{
"type": "default",
"script": "vm/nextcloud-vm.sh",
"resources": {
"cpu": "2",
"ram": "2048",
"hdd": "12G",
"os": "debian",
"version": 12
}
}
],
"default_credentials": {
"username": "admin",
"password": null
},
"notes": []
}

View File

@ -21,13 +21,13 @@
"cpu": "2", "cpu": "2",
"ram": "2048", "ram": "2048",
"hdd": "12G", "hdd": "12G",
"os": null, "os": "debian",
"version": null "version": 12
} }
} }
], ],
"default_credentials": { "default_credentials": {
"username": null, "username": "admin",
"password": null "password": null
}, },
"notes": [] "notes": []

View File

@ -32,7 +32,7 @@ BFR="\\r\\033[K"
HOLD="-" HOLD="-"
CM="${GN}${CL}" CM="${GN}${CL}"
CROSS="${RD}${CL}" CROSS="${RD}${CL}"
THIN="discard=on,ssd=1," THIN="discard=on,ssd=1"
set -e set -e
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
trap cleanup EXIT trap cleanup EXIT
@ -207,7 +207,7 @@ function advanced_settings() {
exit-script exit-script
fi fi
if VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 $HN --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then if VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 turnkey-nextcloud-vm --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
if [ -z $VM_NAME ]; then if [ -z $VM_NAME ]; then
HN="$HN" HN="$HN"
echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
@ -393,7 +393,7 @@ btrfs)
THIN="" THIN=""
;; ;;
esac esac
for i in {0,1}; do for i in {0,1,2}; do
disk="DISK$i" disk="DISK$i"
eval DISK${i}=vm-${VMID}-disk-${i}${DISK_EXT:-} eval DISK${i}=vm-${VMID}-disk-${i}${DISK_EXT:-}
eval DISK${i}_REF=${STORAGE}:${DISK_REF:-}${!disk} eval DISK${i}_REF=${STORAGE}:${DISK_REF:-}${!disk}
@ -403,11 +403,13 @@ msg_info "Creating a $NAME"
qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios seabios${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \ qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios seabios${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \
-name $HN -tags proxmox-helper-scripts -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci -name $HN -tags proxmox-helper-scripts -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci
pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null
pvesm alloc $STORAGE $VMID $DISK1 12G 1>&/dev/null
qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null
qm set $VMID \ qm set $VMID \
-efidisk0 ${DISK0_REF}${FORMAT} \ -efidisk0 ${DISK0_REF}${FORMAT} \
-scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=12G \ -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN} \
-boot order=scsi0 \ -scsi1 ${DISK2_REF},${DISK_CACHE}${THIN} \
-boot order='scsi1;scsi0' \
-description "<div align='center'><a href='https://Helper-Scripts.com'><img src='https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/images/logo-81x112.png'/></a> -description "<div align='center'><a href='https://Helper-Scripts.com'><img src='https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/images/logo-81x112.png'/></a>
# $NAME # $NAME

View File

@ -19,7 +19,7 @@ header_info
echo -e "\n Loading..." echo -e "\n Loading..."
GEN_MAC=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//') GEN_MAC=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//')
NEXTID=$(pvesh get /cluster/nextid) NEXTID=$(pvesh get /cluster/nextid)
NAME="TurnKey ownCloud VM"
YW=$(echo "\033[33m") YW=$(echo "\033[33m")
BL=$(echo "\033[36m") BL=$(echo "\033[36m")
HA=$(echo "\033[1;34m") HA=$(echo "\033[1;34m")
@ -32,7 +32,7 @@ BFR="\\r\\033[K"
HOLD="-" HOLD="-"
CM="${GN}${CL}" CM="${GN}${CL}"
CROSS="${RD}${CL}" CROSS="${RD}${CL}"
THIN="discard=on,ssd=1," THIN="discard=on,ssd=1"
set -e set -e
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
trap cleanup EXIT trap cleanup EXIT
@ -59,7 +59,7 @@ function cleanup() {
TEMP_DIR=$(mktemp -d) TEMP_DIR=$(mktemp -d)
pushd $TEMP_DIR >/dev/null pushd $TEMP_DIR >/dev/null
if whiptail --backtitle "Proxmox VE Helper Scripts" --title "TurnKey-ownCloud VM" --yesno "This will create a New TurnKey-ownCloud VM. Proceed?" 10 58; then if whiptail --backtitle "Proxmox VE Helper Scripts" --title "$NAME" --yesno "This will create a New $NAME. Proceed?" 10 58; then
: :
else else
header_info && echo -e "⚠ User exited script \n" && exit header_info && echo -e "⚠ User exited script \n" && exit
@ -154,7 +154,7 @@ function default_settings() {
echo -e "${DGN}Using VLAN: ${BGN}Default${CL}" echo -e "${DGN}Using VLAN: ${BGN}Default${CL}"
echo -e "${DGN}Using Interface MTU Size: ${BGN}Default${CL}" echo -e "${DGN}Using Interface MTU Size: ${BGN}Default${CL}"
echo -e "${DGN}Start VM when completed: ${BGN}no${CL}" echo -e "${DGN}Start VM when completed: ${BGN}no${CL}"
echo -e "${BL}Creating a TurnKey ownCloud VM using the above default settings${CL}" echo -e "${BL}Creating a $NAME using the above default settings${CL}"
} }
function advanced_settings() { function advanced_settings() {
@ -313,8 +313,8 @@ function advanced_settings() {
START_VM="no" START_VM="no"
fi fi
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create a TurnKey ownCloud VM?" --no-button Do-Over 10 58); then if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create a $NAME?" --no-button Do-Over 10 58); then
echo -e "${RD}Creating a TurnKey ownCloud VM using the above advanced settings${CL}" echo -e "${RD}Creating a $NAME using the above advanced settings${CL}"
else else
header_info header_info
echo -e "${RD}Using Advanced Settings${CL}" echo -e "${RD}Using Advanced Settings${CL}"
@ -368,7 +368,7 @@ else
fi fi
msg_ok "Using ${CL}${BL}$STORAGE${CL} ${GN}for Storage Location." msg_ok "Using ${CL}${BL}$STORAGE${CL} ${GN}for Storage Location."
msg_ok "Virtual Machine ID is ${CL}${BL}$VMID${CL}." msg_ok "Virtual Machine ID is ${CL}${BL}$VMID${CL}."
msg_info "Retrieving the URL for the TurnKey ownCloud ISO Disk Image" msg_info "Retrieving the URL for the $NAME Disk Image"
URL=http://mirror.turnkeylinux.org/turnkeylinux/images/iso/turnkey-owncloud-18.0-bookworm-amd64.iso URL=http://mirror.turnkeylinux.org/turnkeylinux/images/iso/turnkey-owncloud-18.0-bookworm-amd64.iso
sleep 2 sleep 2
msg_ok "${CL}${BL}${URL}${CL}" msg_ok "${CL}${BL}${URL}${CL}"
@ -393,31 +393,33 @@ btrfs)
THIN="" THIN=""
;; ;;
esac esac
for i in {0,1}; do for i in {0,1,2}; do
disk="DISK$i" disk="DISK$i"
eval DISK${i}=vm-${VMID}-disk-${i}${DISK_EXT:-} eval DISK${i}=vm-${VMID}-disk-${i}${DISK_EXT:-}
eval DISK${i}_REF=${STORAGE}:${DISK_REF:-}${!disk} eval DISK${i}_REF=${STORAGE}:${DISK_REF:-}${!disk}
done done
msg_info "Creating a TurnKey ownCloud VM" msg_info "Creating a $NAME"
qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios seabios${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \ qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios seabios${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \
-name $HN -tags proxmox-helper-scripts -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci -name $HN -tags proxmox-helper-scripts -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci
pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null
pvesm alloc $STORAGE $VMID $DISK1 12G 1>&/dev/null
qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null
qm set $VMID \ qm set $VMID \
-efidisk0 ${DISK0_REF}${FORMAT} \ -efidisk0 ${DISK0_REF}${FORMAT} \
-scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=12G \ -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN} \
-boot order=scsi0 \ -scsi1 ${DISK2_REF},${DISK_CACHE}${THIN} \
-boot order='scsi1;scsi0' \
-description "<div align='center'><a href='https://Helper-Scripts.com'><img src='https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/images/logo-81x112.png'/></a> -description "<div align='center'><a href='https://Helper-Scripts.com'><img src='https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/images/logo-81x112.png'/></a>
# TurnKey ownCloud VM # $NAME
<a href='https://ko-fi.com/D1D7EP4GF'><img src='https://img.shields.io/badge/&#x2615;-Buy me a coffee-blue' /></a> <a href='https://ko-fi.com/D1D7EP4GF'><img src='https://img.shields.io/badge/&#x2615;-Buy me a coffee-blue' /></a>
</div>" >/dev/null </div>" >/dev/null
msg_ok "Created a TurnKey ownCloud VM ${CL}${BL}(${HN})" msg_ok "Created a $NAME ${CL}${BL}(${HN})"
if [ "$START_VM" == "yes" ]; then if [ "$START_VM" == "yes" ]; then
msg_info "Starting TurnKey ownCloud VM" msg_info "Starting $NAME"
qm start $VMID qm start $VMID
msg_ok "Started TurnKey ownCloud VM" msg_ok "Started $NAME"
fi fi
msg_ok "Completed Successfully!\n" msg_ok "Completed Successfully!\n"