From eecdc0e6ec8627615a2c3a46faf783b4b2ba5d14 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Sun, 17 Nov 2024 17:01:05 +0200 Subject: [PATCH] Add installer and wrapper --- README.md | 12 ++++++++++-- install.sh | 29 +++++++++++++++++++++++++++++ wrapper.sh | 19 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100755 install.sh create mode 100644 wrapper.sh diff --git a/README.md b/README.md index edd07a1..e065643 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,18 @@ ### Linux - ```bash -pip install . +To install for example in your ~/.local/bin folder: +```bash +./install.sh --destination ~/.local/bin ``` +To install system-wide: +```bash +sudo ./install.sh --destination /usr/local/bin +``` + +Change your configuration file in "${HOME}/.config/get_youtube_videos.conf" (see the example in the config folder). + ### Windows (from PowerShell) Ensure you have "C:\Users\${env:USERNAME}\AppData\Roaming\Python\Python${python_version}\Scripts\" in your Path environment variable. diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..fb94374 --- /dev/null +++ b/install.sh @@ -0,0 +1,29 @@ +#!/bin/bash +destination="/usr/local/bin" +while [ $# -gt 0 ] +do + case "$1" in + "--help"|"-h"|"-?") + usage + exit 0 + ;; + "--destination"|"-d") + shift + destination="${1}" + shift + ;; + *) + echo "Ignoring unknwon parameter '${1}'" + shift + ;; + esac +done + +if [ ! -x "${HOME}/.config/get_youtube_videos.conf" ]; then + touch "${HOME}/.config/get_youtube_videos.conf" +fi +chmod go-rwx "${HOME}/.config/get_youtube_videos.conf" + +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +sed "s#__src_folder__#${script_dir}#g" wrapper.sh > "${destination}/get_youtube_videos.sh" +chmod +x "${destination}/get_youtube_videos.sh" diff --git a/wrapper.sh b/wrapper.sh new file mode 100644 index 0000000..c0e17a0 --- /dev/null +++ b/wrapper.sh @@ -0,0 +1,19 @@ +#!/bin/bash +CONFIG_FILE="${HOME}/.config/get_youtube_videos.conf" +cd "__src_folder__" || exit 1 +if [ -r "${CONFIG_FILE}" ]; then + perms=$(stat -c %A "${CONFIG_FILE}") + if [ "${perms:4:6}" != '------' ]; then + echo "Permissions too open for config file '${CONFIG_FILE}' ($perms). Remove all permissions to group and others." + exit 1 + fi + config=(--config "${CONFIG_FILE}") +else + config=() +fi +"__src_folder__/get_youtube_videos.sh" "${config[@]}" "${@}" + +download_dir="${HOME}/downloaded_youtube_videos" +# shellcheck disable=SC1090 +source "${CONFIG_FILE}" +chmod 0777 "${download_dir}" -R