From 80edaeb8e27e87c400126ef717dfb08458c45adf Mon Sep 17 00:00:00 2001 From: Starnakin Date: Mon, 26 May 2025 17:34:34 +0200 Subject: [PATCH] init --- .gitignore | 1 + Dockerfile | 32 +++++++++++++++++++++++++ build.sh | 37 +++++++++++++++++++++++++++++ create-tables.sql | 57 +++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 11 +++++++++ docker-run.sh | 9 +++++++ initdb.sh | 5 ++++ 7 files changed, 152 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100755 build.sh create mode 100644 create-tables.sql create mode 100644 docker-compose.yaml create mode 100755 docker-run.sh create mode 100755 initdb.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6320cd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a480d8e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM alpine:latest + +RUN apk update + +RUN apk add alpine-sdk + +# Install microhttpd +RUN apk add autoconf automake libtool pkgconf git texinfo + +WORKDIR /root +RUN git clone https://git.gnunet.org/libmicrohttpd.git +WORKDIR /root/libmicrohttpd +RUN ./bootstrap +RUN ./configure +RUN make +RUN make install + +# Compile code +RUN apk add sqlite-dev argon2-dev libsodium-dev curl-dev xxd + +RUN git clone https://git.sr.ht/~kikoodx/betterboxd /app + +WORKDIR /app + +COPY ./build.sh . + +RUN ./build.sh + +COPY ./docker-run.sh . +COPY ./initdb.sh . + +ENTRYPOINT ["sh", "/app/docker-run.sh"] \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..e73abbe --- /dev/null +++ b/build.sh @@ -0,0 +1,37 @@ +#! /bin/sh -e +# This file is automatically generated with: tup generate build.sh +export tup_vardict="$(cd $(dirname $0) && pwd)/tup-generate.vardict" +(mkdir gen) +(xxd -i theme.css gen/theme.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/db.o src/db.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/fetch.o src/fetch.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_admin.o src/handler_admin.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_admin_newuser.o src/handler_admin_newuser.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_admin_setpass.o src/handler_admin_setpass.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_film.o src/handler_film.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_film_fetch.o src/handler_film_fetch.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_film_poster.o src/handler_film_poster.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_film_poster_set.o src/handler_film_poster_set.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_film_rate.o src/handler_film_rate.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_filmlist.o src/handler_filmlist.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_index.o src/handler_index.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_login.o src/handler_login.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_logout.o src/handler_logout.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_person.o src/handler_person.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_personlist.o src/handler_personlist.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_theme.o src/handler_theme.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_user.o src/handler_user.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/handler_userlist.o src/handler_userlist.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/hash.o src/hash.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/main.o src/main.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/request.o src/request.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/router.o src/router.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/session.o src/session.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/sessionmanager.o src/sessionmanager.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/string.o src/string.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/tmdb.o src/tmdb.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/userinfo.o src/userinfo.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/_.o vendors/_.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/cJSON.o vendors/cJSON.c) +(gcc -g3 -std=c2x -Wall -Wextra -iquoteinc -iquotevendors -include_.h -Dnullptr=NULL -c -o build/theme.o gen/theme.c) +(gcc -o betterboxd build/db.o build/fetch.o build/handler_admin.o build/handler_admin_newuser.o build/handler_admin_setpass.o build/handler_film.o build/handler_film_fetch.o build/handler_film_poster.o build/handler_film_poster_set.o build/handler_film_rate.o build/handler_filmlist.o build/handler_index.o build/handler_login.o build/handler_logout.o build/handler_person.o build/handler_personlist.o build/handler_theme.o build/handler_user.o build/handler_userlist.o build/hash.o build/main.o build/request.o build/router.o build/session.o build/sessionmanager.o build/string.o build/tmdb.o build/userinfo.o build/_.o build/cJSON.o build/theme.o -lmicrohttpd -lsqlite3 -lcurl -largon2 -lsodium -lm) diff --git a/create-tables.sql b/create-tables.sql new file mode 100644 index 0000000..dac0a7f --- /dev/null +++ b/create-tables.sql @@ -0,0 +1,57 @@ +CREATE TABLE film ( + rowid INTEGER PRIMARY KEY NOT NULL, + title TEXT NOT NULL, + ogtitle TEXT, + year INT NOT NULL, + poster INTEGER, + lastfetch INTEGER, + CONSTRAINT fk_film_poster FOREIGN KEY (poster) REFERENCES poster(rowid) ON DELETE SET NULL +) STRICT; + +CREATE TABLE poster ( + rowid INTEGER PRIMARY KEY NOT NULL, + film INTEGER NOT NULL, + path TEXT NOT NULL, + CONSTRAINT fk_poster_film FOREIGN KEY (film) REFERENCES film(rowid) ON DELETE CASCADE +) STRICT; + +CREATE TABLE person ( + rowid INTEGER PRIMARY KEY NOT NULL, + name TEXT NOT NULL, + birth INT, + death INT, + picture TEXT, + lastfetch INTEGER +) STRICT; + +CREATE TABLE crew ( + film INTEGER NOT NULL, + person INTEGER NOT NULL, + role TEXT NOT NULL, + PRIMARY KEY (film, person, role), + CONSTRAINT fk_crew_film FOREIGN KEY (film) REFERENCES film(rowid) ON DELETE CASCADE, + CONSTRAINT fk_crew_person FOREIGN KEY (person) REFERENCES person(rowid) ON DELETE CASCADE +) STRICT; + +CREATE TABLE user ( + rowid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + name TEXT UNIQUE NOT NULL, + pass TEXT NOT NULL, + salt TEXT NOT NULL, + perm INT NOT NULL DEFAULT 0 +) STRICT; + +CREATE TABLE rating ( + user INTEGER NOT NULL, + film INTEGER NOT NULL, + value INTEGER NOT NULL, + time TEXT NOT NULL, + PRIMARY KEY (user, film), + CONSTRAINT fk_rating_user FOREIGN KEY (user) REFERENCES user(rowid) ON DELETE CASCADE, + CONSTRAINT fk_rating_film FOREIGN KEY (film) REFERENCES film(rowid) ON DELETE CASCADE +) STRICT; + +INSERT INTO user + (name, perm, pass, salt) +VALUES + ('admin', 1, 'c487293be46cee0c75db63f11cf20c756efdc45c7fb024b517bdfb837ab68c33', 'uwubebou'); /* uwu */ diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..790d4b1 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,11 @@ +services: + betterboxd: + container_name: betterboxd + volumes: + - ./data:/app/db/ + ports: + - "8080:8080" + environment: + - PORT=8080 + - TMDB_KEY=PRIVATE_KEY + build: . \ No newline at end of file diff --git a/docker-run.sh b/docker-run.sh new file mode 100755 index 0000000..4e764b9 --- /dev/null +++ b/docker-run.sh @@ -0,0 +1,9 @@ +#!/bin/sh +DB=/app/db/main.db +if [ ! -f $DB ]; then + echo "Gen DB" + /app/initdb.sh + mkdir -p /app/db + mv /app/main.db $DB +fi +./betterboxd $PORT $TMDB_KEY $DB diff --git a/initdb.sh b/initdb.sh new file mode 100755 index 0000000..52eb320 --- /dev/null +++ b/initdb.sh @@ -0,0 +1,5 @@ +#!/bin/sh +sqlite3 <