From 89addd6649a3e676346a6c0c1ed2cb09ee16a5e8 Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Thu, 4 Jan 2024 18:12:08 +0100 Subject: [PATCH] pairdrop-cli: Exit application if config file cannot be created on first run --- docs/how-to.md | 4 ++-- pairdrop-cli/pairdrop | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/how-to.md b/docs/how-to.md index 7db17fc..d47cc41 100644 --- a/docs/how-to.md +++ b/docs/how-to.md @@ -24,7 +24,7 @@ This opens PairDrop in the default browser where you can choose the receiver. ```bash pairdrop -h ``` -```bash +``` Send files or text with PairDrop via command-line interface. Current domain: https://pairdrop-dev.onrender.com/ @@ -35,7 +35,7 @@ Send text: pairdrop -t "text" Specify domain: pairdrop -d "https://pairdrop.net/" Show this help text: pairdrop (-h|--help) -This pairdrop-cli version was released alongside v1.10.0 +This pairdrop-cli version was released alongside v1.10.4 ```
diff --git a/pairdrop-cli/pairdrop b/pairdrop-cli/pairdrop index d9edacb..e4c662a 100644 --- a/pairdrop-cli/pairdrop +++ b/pairdrop-cli/pairdrop @@ -1,6 +1,9 @@ #!/bin/bash set -e +# PairDrop version when this file was last changed +version="v1.10.4" + ############################################################ # Help # ############################################################ @@ -17,7 +20,7 @@ help() echo -e "Specify domain:\t\t$(basename "$0") -d \"https://pairdrop.net/\"" echo -e "Show this help text:\t$(basename "$0") (-h|--help)" echo - echo "This pairdrop-cli version was released alongside v1.10.0" + echo "This pairdrop-cli version was released alongside ${version}" } openPairDrop() @@ -337,12 +340,15 @@ popd > '/dev/null'; config_path="${script_path}/.pairdrop-cli-config" +# If config file does not exist, try to create it. If it fails log error message and exit [ ! -f "$config_path" ] && specifyDomain "https://pairdrop.net/" && [ ! -f "$config_path" ] && - echo "Could not create config file. Add 'DOMAIN=https://pairdrop.net/' to a file called .pairdrop-cli-config in the same file as this 'pairdrop' bash file" + echo "Could not create config file. Add 'DOMAIN=https://pairdrop.net/' to a file called .pairdrop-cli-config in the same file as this 'pairdrop' bash file (${script_path})" && + exit -[ ! -f "$config_path" ] || export "$(grep -v '^#' "$config_path" | xargs)" +# Read config variables +export "$(grep -v '^#' "$config_path" | xargs)" setOs