From e631ad6009100515933ad35f6902cfd779b53f7d Mon Sep 17 00:00:00 2001 From: r4 Date: Thu, 23 Jun 2022 20:35:29 +0200 Subject: [PATCH] allow symlinks to executable --- config.sh | 3 ++- southpark-downloader.sh | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config.sh b/config.sh index 30028b1..fe60ccc 100644 --- a/config.sh +++ b/config.sh @@ -2,7 +2,8 @@ # South Park Downloader Configuration File # ############################################ -# Relative or absolute paths are allowed. Please DON'T use ~/, but rather $HOME or /home/$USER. +# Absolute paths or paths relative to the executable are allowed. +# Please DON'T use ~/, but rather $HOME or /home/$USER. # youtube-dl (or youtube-dlc) executable path YOUTUBE_DL="./yt-dlc/youtube-dlc" diff --git a/southpark-downloader.sh b/southpark-downloader.sh index d46d7fd..0014a4f 100755 --- a/southpark-downloader.sh +++ b/southpark-downloader.sh @@ -1,14 +1,17 @@ #!/usr/bin/env bash -source "$(dirname "$0")/config.sh" +# Resolve executable directory +DIR="$(dirname "$(readlink -e "$0")")" -# Turn paths into absolute ones, if they aren't already. Will be necessary, since we'll change directories later. +source "$DIR/config.sh" + +# Turn paths into absolute ones if they aren't already. Will be necessary since we'll change directories later. [ ! "${CACHEDIR::1}" = "/" ] && - CACHEDIR="$(readlink -f "$(dirname "$0")/$CACHEDIR")" + CACHEDIR="$DIR/$CACHEDIR" [ ! "${OUTDIR::1}" = "/" ] && - OUTDIR="$(readlink -f "$(dirname "$0")/$OUTDIR")" + OUTDIR="$DIR/$OUTDIR" [ ! "${YOUTUBE_DL::1}" = "/" ] && - YOUTUBE_DL="$(readlink -f "$(dirname "$0")/$YOUTUBE_DL")" + YOUTUBE_DL="$DIR/$YOUTUBE_DL" [ ! -e "$OUTDIR" ] && mkdir -p "$OUTDIR" [ ! -e "$CACHEDIR" ] && mkdir -p "$CACHEDIR"