Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EMAIL=
PASSWORD=
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env.local
session/
22 changes: 18 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
FROM debian:11.4-slim

ENV DEBIAN_FRONTEND=noninteractive
ENV DEBIAN_FRONTEND=noninteractive \
S6_OVERLAY_VERSION=3.1.6.2 \
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=300000

# updating and installing required components
RUN apt update \
# software-properties-common curl gnupg zip libvips42 git xz-utils sudo htop micro jq
&& apt install --no-install-recommends -y software-properties-common curl \
&& apt install --no-install-recommends -y software-properties-common curl xz-utils sudo \
#
&& curl -o /tmp/megacmd.deb https://mega.nz/linux/repo/Debian_11/amd64/megacmd-Debian_11_amd64.deb \
&& apt --no-install-recommends -y install /tmp/megacmd.deb \
#
# cleaning up
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* \
#
# installing s6
&& curl -sL https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz | tar -C / -Jxpf - \
&& curl -sL https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-$([ $(uname -m) = 'aarch64' ] && echo 'aarch64' || echo 'x86_64').tar.xz | tar -C / -Jxpf - \
#
# custom user
&& useradd -u 1000 -ms /bin/bash mega \
&& adduser mega sudo \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

COPY ./entrypoint.sh /
USER mega
WORKDIR /home/mega/.megaCmd
COPY --chown=mega rootfs /
CMD ["/entrypoint.sh"]

EXPOSE 80
VOLUME /home/mega/.megaCmd
12 changes: 12 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.7'

# for testing
services:
test:
build: .
env_file:
- .env.local
volumes:
- "./session:/home/mega/.megaCmd"
ports:
- "80:80"
21 changes: 0 additions & 21 deletions entrypoint.sh

This file was deleted.

3 changes: 3 additions & 0 deletions rootfs/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

exec /init
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/login/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
4 changes: 4 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/login/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/command/execlineb -P

with-contenv
exec /login.sh
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/reload/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/command/with-contenv sh

exec /reload.sh
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/reload/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/webdav/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/command/with-contenv sh

exec /webdav.sh
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/webdav/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
31 changes: 31 additions & 0 deletions rootfs/login.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

if [ -z "${MFA}" ];
then
mega-login "${EMAIL}" "${PASSWORD}"
else
mega-login "${EMAIL}" "${PASSWORD}" --auth-code="${MFA}"
fi
exitCode=$?

if [ $exitCode = "0" ];
# success, everything is great
then
# do nothing
sleep 0
elif [ $exitCode = "54" ];
# exit code 54 is returned when the session already exists
then
mega-reload
exitCode=$?
if [ $exitCode != "0" ];
then
# stop everything
/run/s6/basedir/bin/halt
exit $exitCode
fi
else
# stop everything
/run/s6/basedir/bin/halt
exit $exitCode
fi
15 changes: 15 additions & 0 deletions rootfs/reload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

while true
do
# default sleep interval for reload is 1 day
sleep "${RELOAD_INTERVAL:-86400}"
mega-reload
exitCode=$?
if [ $exitCode != "0" ];
then
# stop everything
/run/s6/basedir/bin/halt
exit $exitCode
fi
done
16 changes: 16 additions & 0 deletions rootfs/webdav.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

output=$(mega-webdav "${DIRECTORY:-/}" --public --port=80) # change port for caddy
exitCode=$?
if [ $exitCode != "0" ];
then
# stop everything
/run/s6/basedir/bin/halt
exit $exitCode
fi

path=$(echo $output | sed -n 's|.*http://.*/\([^/]*\)/.*|\1|p')
echo "prepared path for caddy: ${path}"

# tail log file as "long running" task
tail -f /home/mega/.megaCmd/megacmdserver.log*