add options to configure the default schedule in the docker container via environment variables
All checks were successful
ci/woodpecker/push/tests Pipeline was successful

This commit is contained in:
Ivan Schaller 2022-07-18 18:41:41 +02:00
parent 82a764e7d5
commit a8477591f0
9 changed files with 134 additions and 15 deletions

View file

@ -15,14 +15,21 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- The `--read` option now filters empty lines, so it will not generate an error anymore
- An error which was caused by the interactive input method when you did not specify a chapter or to list them
- Some typos
### Added
- Options to configure the default schedule in the docker container via environment variables
- Section the the docker [README.md](docker/README.md) for the new environment variables
- `autoflake` test in `justfile`
- Some more things which get logged
### Changed
- **BREAKING**: renamed the default schedule from `daily` to `daily.sh`. Don't forget to fix your bind-mounts to
overwrite
the default schedule
- Added the `.sh` suffix to the s6 init scripts for better compatibility
- Adjusted the new logging implementation. It shows now more info about the module the log is from, and some other
improvements

View file

@ -31,6 +31,26 @@ environment:
docker run -e PUID=<userid> -e PGID=<groupid>
```
## Environment variables
You can configure the default schedule via environment variables. Don't forget to set `MDLP_GENERATE_SCHEDULE` to "true"
, else
it will not generate it (it will just use the default one).
For more info's about the options, you can look in the main scripts [README.md](../README.md)
| ENV Variable | Default | manga-dlp option | Info |
|:-----------------------|:----------------|:-------------------------|--------------------------------------------------------------------------|
| MDLP_GENERATE_SCHEDULE | false | none | Has to be set to "true" to generate the config via environment variables |
| MDLP_PATH | /app/downloads | --path | |
| MDLP_READ | /app/mangas.txt | --read | |
| MDLP_LANGUAGE | en | --language | |
| MDLP_CHAPTERS | all | --chapter | |
| MDLP_FILE_FORMAT | cbz | --format | |
| MDLP_WAIT | 0.5 | --wait | |
| MDLP_FORCEVOL | false | --forcevol | |
| MDLP_LOG_LEVEL | lean | --lean/--verbose/--debug | Can either be set to: "lean", "verbose" or "debug" |
## Run commands in container
> You don't need to use the full path of manga-dlp.py because `/app` already is the working directory
@ -68,15 +88,15 @@ To use your own schedule you need to mount (override) the default schedule or ad
volumes:
- ./crontab:/etc/cron.d/mangadlp # overwrites the default crontab
- ./crontab2:/etc/cron.d/something # adds a new one crontab file
- ./schedule1:/app/schedules/daily # overwrites the default schedule
- ./schedule2:/app/schedules/weekly # adds a new schedule
- ./schedule1.sh:/app/schedules/daily.sh # overwrites the default schedule
- ./schedule2.sh:/app/schedules/weekly.sh # adds a new schedule
```
```sh
docker run -v ./crontab:/etc/cron.d/mangadlp # overwrites the default crontab
docker run -v ./crontab2:/etc/cron.d/something # adds a new one crontab file
docker run -v ./schedule1:/app/schedules/daily # overwrites the default schedule
docker run -v ./schedule2:/app/schedules/weekly # adds a new schedule
docker run -v ./schedule1.sh:/app/schedules/daily.sh # overwrites the default schedule
docker run -v ./schedule2.sh:/app/schedules/weekly.sh # adds a new schedule
```
#### The default crontab file:
@ -91,7 +111,7 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# "/proc/1/fd/1 2>&1" is to show the logs in the container
# "s6-setuidgid abc" is used to set the permissions
0 12 * * * root s6-setuidgid abc /app/schedules/daily > /proc/1/fd/1 2>&1
0 12 * * * root s6-setuidgid abc /app/schedules/daily.sh > /proc/1/fd/1 2>&1
```
## Add mangas to mangas.txt

View file

@ -13,15 +13,13 @@ services:
- ./downloads/:/app/downloads/ # default manga download directory
- ./mangas.txt:/app/mangas.txt # default file for manga links to download
#- ./crontab:/etc/cron.d/mangadlp # path to default crontab
#- ./schedule:/app/schedules/daily # path to the default schedule which is run daily
#- ./schedule.sh:/app/schedules/daily.sh # path to the default schedule which is run daily
environment:
- TZ=Europe/Zurich
# - PUID= # custom userid - defaults to 4444
# - PGID= # custom groupid - defaults to 4444
#- PUID= # custom user id - defaults to 4444
#- PGID= # custom group id - defaults to 4444
networks:
appnet:
name: mangadlp
driver: bridge

View file

@ -4,8 +4,12 @@
# set all env variables for further use. If variable is unset, it will have the defaults on the right side after ":="
# custom env vars
: "${MDLP_GENERATE_SCHEDULE:=false}"
: "${MDLP_PATH:=/app/downloads}"
: "${MDLP_READ:=/app/mangas.txt}"
: "${MDLP_LANGUAGE:=en}"
: "${MDLP_FORCEVOL:=false}"
: "${MDLP_CHAPTERS:=all}"
: "${MDLP_FILE_FORMAT:=cbz}"
: "${MDLP_DOWNLOAD_WAIT:=2}"
: "${MDLP_VERBOSE:=false}"
: "${MDLP_WAIT:=0.5}"
: "${MDLP_FORCEVOL:=false}"
: "${MDLP_LOG_LEVEL:=lean}"

View file

@ -0,0 +1,28 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
# source env variables
source /etc/cont-init.d/20-setenv.sh
# check schedule
[[ -f "/app/schedules/daily.sh" ]] && DAILYSH=true
[[ -f "/app/schedules/daily" ]] && DAILY=true
# check crontab
if grep -q -e "/app/schedules/daily.sh\s" /etc/cron.d/mangadlp; then
CRONSH=true
elif grep -q -e "/app/schedules/daily\s" /etc/cron.d/mangadlp; then
CRON=true
fi
# fix new .sh schedule if its not synced with the crontab
if [[ "${CRONSH}" == "true" ]] && [[ "${DAILYSH}" != "true" ]]; then
echo "Fixing new .sh schedule"
if ! ln -s /app/schedule/daily /app/schedule/daily.sh; then
echo "Cant fix schedule. Maybe the file is missing."
fi
elif [[ "${CRON}" == "true" ]] && [[ "${DAILY}" != "true" ]]; then
echo "Fixing new .sh schedule"
if ! ln -s /app/schedule/daily.sh /app/schedule/daily; then
echo "Cant fix schedule. Maybe the file is missing."
fi
fi

View file

@ -0,0 +1,62 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
# source env variables
source /etc/cont-init.d/20-setenv.sh
function prepare_vars() {
# set log level
case "${MDLP_LOG_LEVEL}" in
"lean")
MDLP_LOG_LEVEL_FLAG=" --lean"
;;
"verbose")
MDLP_LOG_LEVEL_FLAG=" --verbose"
;;
"debug")
MDLP_LOG_LEVEL_FLAG=" --debug"
;;
esac
# check if forcevol should be used
if [[ "${MDLP_FORCEVOL,,}" == "true" ]]; then
# add backslash if log level is also specified
if [[ -n "${MDLP_LOG_LEVEL_FLAG}" ]]; then
MDLP_FORCEVOL_FLAG="\n --forcevol \\"
else
MDLP_FORCEVOL_FLAG="\n --forcevol"
fi
fi
}
# set schedule with env variables
function set_vars() {
echo -n "
#!/bin/bash
python3 /app/manga-dlp.py \\
--path ${MDLP_PATH} \\
--read ${MDLP_READ} \\
--language ${MDLP_LANGUAGE} \\
--chapters ${MDLP_CHAPTERS} \\
--format ${MDLP_FILE_FORMAT} \\
--wait ${MDLP_WAIT}" \
> /app/schedules/daily.sh
# set forcevol or log level if specified
if [[ -n "${MDLP_FORCEVOL_FLAG}" ]] || [[ -n "${MDLP_LOG_LEVEL_FLAG}" ]]; then
sed -i 's/--wait '"${MDLP_WAIT}"'/--wait '"${MDLP_WAIT}"' \\/g' /app/schedules/daily.sh
echo -e "${MDLP_FORCEVOL_FLAG:-}" >> /app/schedules/daily.sh
echo -e "${MDLP_LOG_LEVEL_FLAG:-}" >> /app/schedules/daily.sh
else
# add final newline of not added before
echo -ne "\n" >> /app/schedules/daily.sh
fi
}
# check if schedule should be generated
if [[ "${MDLP_GENERATE_SCHEDULE,,}" == "true" ]]; then
echo "Generating schedule"
prepare_vars
set_vars
fi

View file

@ -2,7 +2,7 @@
# shellcheck shell=bash
# source env variables
source /etc/cont-init.d/20-setenv
source /etc/cont-init.d/20-setenv.sh
# fix permissions
find '/app' -type 'd' \( -not -perm 775 -and -not -path '/app/downloads*' \) -exec chmod 775 '{}' \+

View file

@ -7,5 +7,5 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# "/proc/1/fd/1 2>&1" is to show the logs in the container
# "s6-setuidgid abc" is used to set the permissions
0 12 * * * root s6-setuidgid abc /app/schedules/daily > /proc/1/fd/1 2>&1
0 12 * * * root s6-setuidgid abc /app/schedules/daily.sh > /proc/1/fd/1 2>&1