Compare commits

..

4 Commits

Author SHA1 Message Date
ge
71e1d87d32 feat: Improve and make scripts POSIX compliant 2022-09-29 10:47:48 +03:00
ge
921dd5d29d feat: Add dark theme via prefers-color-scheme 2022-09-29 10:46:51 +03:00
ge
cde343d159 update README 2022-09-29 10:44:41 +03:00
ge
cd258011be fix: Update link 2022-09-29 08:31:36 +03:00
5 changed files with 158 additions and 141 deletions

View File

@ -18,14 +18,18 @@ Clone repository and edit **imgs.ini**.
Build Docker image: Build Docker image:
```bash ```shell
docker build --tag imgs . docker build --tag imgs .
``` ```
Run container from image. Replace **/path/to/your/uploads/dir** with path to directory where you want to store images: Run container from image. Replace **/path/to/your/uploads/dir** with path to directory where you want to store images:
``` ```shell
sudo docker run --rm --name imgs --detach --publish 127.0.0.1:5000:5000 --volume /path/to/your/uploads/dir:/opt/imgs/uploads imgs docker run -d \
--name imgs \
--publish 127.0.0.1:5000:5000 \
--volume /path/to/your/uploads/dir:/opt/imgs/uploads \
imgs
``` ```
imgs will launched on `127.0.0.1:5000`. Set up reverse proxy server. I recommed to use basic authentication to prevent abuses. Nginx virtual host example: imgs will launched on `127.0.0.1:5000`. Set up reverse proxy server. I recommed to use basic authentication to prevent abuses. Nginx virtual host example:
@ -59,7 +63,7 @@ server {
imgs has a simple CLI tool based on curl. Copy **imgs** script to your PATH. imgs has a simple CLI tool based on curl. Copy **imgs** script to your PATH.
```bash ```shell
sudo cp imgs /usr/bin/imgs sudo cp imgs /usr/bin/imgs
``` ```
@ -68,3 +72,7 @@ sudo cp imgs /usr/bin/imgs
Push files to your imgs instance via GNOME Files (former name: Nautilus). Depends on: curl, libnotify (notify-send utility). Push files to your imgs instance via GNOME Files (former name: Nautilus). Depends on: curl, libnotify (notify-send utility).
Just place **Upload to imgs** script into **~/.local/share/nautilus/scripts/** directory. Just place **Upload to imgs** script into **~/.local/share/nautilus/scripts/** directory.
```shell
DIR=~/.local/share/nautilus/scripts/; mkdir -p $DIR && cp Upload\ to\ imgs $DIR
```

View File

@ -1,38 +1,32 @@
#!/usr/bin/env bash #!/bin/sh
# This is an imgs <https://gitea.gch.icu/ge/imgs> "integration" for Nautilus. # This is an imgs https://git.nxhs.cloud/ge/imgs "integration" for Nautilus.
# Place this script into path: $HOME/.local/share/nautilus/scripts # Place this script into path: $HOME/.local/share/nautilus/scripts
# See more info at: <https://help.ubuntu.com/community/NautilusScriptsHowto> # See more info at: <https://help.ubuntu.com/community/NautilusScriptsHowto>
imgs_check_vars() { IMGSLOG="${IMGSLOG:-$HOME/imgs_debug.log}"
[ "$IMGSLOG" ] || IMGSLOG=$HOME/imgs_debug.log [ -n "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
[ "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
if [ -f "$HOME/.imgsremote" ]; then if [ -f "$HOME"/.imgsremote ]; then
. $HOME/.imgsremote # shellcheck source=/dev/null
fi . "$HOME"/.imgsremote
fi
if [ "$IMGSREMOTE" ]; then if [ -z "$IMGSREMOTE" ]; then
: echo "$0: Error: IMGSREMOTE variable is not set." >&2; exit 1
else fi
echo "$0: Error: IMGSREMOTE variable is not set." >&2
exit 1
fi
}
imgs_check_vars [ -n "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" >> "$IMGSLOG"
[ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" >> "$IMGSLOG" echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | while read -r file; do
[ -z "$file" ] && break
while read -r file; do if [ -n "$IMGSDEBUG" ]; then
[ "$file" ] || break
if [ "$IMGSDEBUG" ]; then
image="$(curl -v -L -F "image=@$file" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG")" image="$(curl -v -L -F "image=@$file" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG")"
image="$(tail -n 1 <<< "$image")" image="$(echo "$image" | tail -n 1)"
else else
image="$(curl -L -F "image=@$file" "$IMGSREMOTE")" image="$(curl -L -F "image=@$file" "$IMGSREMOTE")"
fi fi
[ "$IMGSDEBUG" ] && echo "$(date +"[%d %b %Y %H:%M:%S]") $file --> $image" >> "$IMGSLOG" [ -n "$IMGSDEBUG" ] && echo "$(date +"[%d %b %Y %H:%M:%S]") $file --> $image" >> "$IMGSLOG"
notify-send "File uploaded to imgs!" "$image" notify-send "File uploaded to imgs!" "$image"
done <<< "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" done
[ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" >> "$IMGSLOG" [ -n "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" >> "$IMGSLOG"

100
imgs
View File

@ -1,74 +1,74 @@
#!/usr/bin/env bash #!/bin/sh
# imgs CLI client. # imgs CLI https://git.nxhs.cloud/ge/imgs
# Home page: <https://gitea.gch.icu/ge/imgs>
imgs_usage() { imgs_usage() {
cat <<- EOF cat <<- EOF
Upload images to remote imgs server. Upload images to remote imgs server.
Usage: imgs [--version] [--help] [-r | --remote <URL>] <file>... Usage: imgs [-rvh] <file>...
Options: Options:
-r, --remote remote imgs instance URI. Example: -r, --remote remote imgs instance URI e.g. https://user:password@example.org
'https://user:password@example.org' -v, --version print version and exit.
--version print version and exit. -h, --help print this help message and exit.
--help print this help message and exit.
Environment variables: Environment variables:
IMGSREMOTE remote imgs instance URI. IMGSREMOTE remote imgs instance URI.
IMGSDEBUG enables verbose mode and logging. IMGSDEBUG enables verbose mode and logging.
IMGSLOG path to logfile. Default: ~/imgs_debug.log IMGSLOG path to logfile. Default: ~/imgs_debug.log
You can set variables in ~/.imgsremote file instead of ~/.bashrc You can set variables in ~/.imgsremote file instead of ~/.bashrc
See <https://gitea.gch.icu/ge/imgs> for more info. See <https://git.nxhs.cloud/ge/imgs> for more info.
EOF EOF
exit 0
} }
imgs_check_vars() { [ "$#" -eq 0 ] && { imgs_usage; exit 1; }
[ "$IMGSLOG" ] || IMGSLOG=$HOME/imgs_debug.log
[ "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
if [ -f "$HOME/.imgsremote" ]; then # Transform long options to short ones
. $HOME/.imgsremote for arg in "$@"; do
fi shift
case "$arg" in
if [ "$IMGSREMOTE" ]; then --remote) set -- "$@" "-r";;
: --help) set -- "$@" "-h";;
else --version) set -- "$@" "-v";;
echo "$0: Error: IMGSREMOTE variable is not set." >&2 *) set -- "$@" "$arg";;
exit 1
fi
}
[[ "$@" ]] || imgs_usage
while (( "$#" )); do
case "$1" in
-r|--remote) if [ "$2" ] && [ "${2:0:1}" != '-' ]; then
IMGSREMOTE="$2"; shift
else
echo "$0: missing argument for $1" >&2; exit 1
fi; shift;;
--version) echo 'imgs CLI 1.0'; exit 0;;
--help) imgs_usage;;
-*) echo "$0: $1: bad option" >&2; exit 1;;
*) [ -f "$1" ] || { echo "$0: $1: no such file" >&2; exit 1; }
_files+=("$1"); shift;;
esac esac
done done
imgs_check_vars while getopts r:vh OPT; do
case "$OPT" in
r) IMGSREMOTE="$OPTARG";;
v) echo 'imgs CLI 1.1'; exit 0;;
h) imgs_usage; exit 0;;
*) echo "$0: Unknown option: $OPT" >&2; exit 1;;
esac
done
[ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" | tee -a "$IMGSLOG" shift $((OPTIND - 1)) # shift for parse positional args
for file in "${_files[@]}"; do # Check variables
IMGSLOG="${IMGSLOG:-$HOME/imgs_debug.log}"
[ -n "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
if [ -f "$HOME"/.imgsremote ]; then
# shellcheck source=/dev/null
. "$HOME"/.imgsremote
fi
if [ -z "$IMGSREMOTE" ]; then
echo "$0: Error: IMGSREMOTE variable is not set." >&2; exit 1
fi
[ -n "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" | tee -a "$IMGSLOG"
for file in "$@"; do
filepath="$(realpath "$file")" filepath="$(realpath "$file")"
if [ "$IMGSDEBUG" ]; then if [ -n "$IMGSDEBUG" ]; then
echo "Uploading $filepath" | tee -a "$IMGSLOG" echo "Uploading $filepath ..." | tee -a "$IMGSLOG"
curl -v -L -F "image=@/$filepath" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG" curl -v -L -F "image=@/$filepath" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG"
else else
curl -L -F "image=@/$filepath" "$IMGSREMOTE" curl -L -F "image=@/$filepath" "$IMGSREMOTE"
fi fi
done done
[ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" | tee -a "$IMGSLOG" [ -n "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" | tee -a "$IMGSLOG"

View File

@ -77,7 +77,7 @@
<div class="logo"> <div class="logo">
<pre> __<br>|__| _____ ____ ______<br>| |/ \ / ___\/ ___/<br>| | Y Y / /_/ \___ \<br>|__|__|_| \___ /____ ><br> \/_____/ \/</pre> <pre> __<br>|__| _____ ____ ______<br>| |/ \ / ___\/ ___/<br>| | Y Y / /_/ \___ \<br>|__|__|_| \___ /____ ><br> \/_____/ \/</pre>
</div> </div>
<p><a href="https://gitea.gch.icu/ge/imgs" target="_blank">v1.1</a></p> <p><a href="https://git.nxhs.cloud/ge/imgs" target="_blank">v1.1</a></p>
</main> </main>
</body> </body>

View File

@ -1,5 +1,18 @@
:root {
--b: #000;
--w: #fff;
}
@media (prefers-color-scheme: dark) {
:root {
--b: #fff;
--w: #000;
}
}
body { body {
background-color: #fff; color: var(--b);
background-color: var(--w);
font-family: 'Ubuntu Mono', monospace; font-family: 'Ubuntu Mono', monospace;
max-width: 720px; max-width: 720px;
margin: 0 auto; margin: 0 auto;
@ -7,11 +20,14 @@ body {
} }
main { margin: 4rem 2rem; } main { margin: 4rem 2rem; }
.not-found, .bad-mime-type { margin-bottom: 2rem; } a, a:visited { color: var(--b); }
a, a:visited { color: #000; }
img { width: 100%; } img { width: 100%; }
.not-found, .bad-mime-type { margin-bottom: 2rem; }
.logo pre {
display: flex;
justify-content: center;
text-align: left;
}
/* Drag and Drop */ /* Drag and Drop */
.drop-area { .drop-area {
@ -23,9 +39,7 @@ img { width: 100%; }
padding: 25px; padding: 25px;
border: 3px dashed #e1e1e1; border: 3px dashed #e1e1e1;
} }
.drop-area.dragover { border-color: var(--b); }
.drop-area.dragover { border-color: #000; }
.file-input { .file-input {
position: absolute; position: absolute;
left: 0; left: 0;
@ -36,7 +50,6 @@ img { width: 100%; }
align-items: center; align-items: center;
opacity: 0; opacity: 0;
} }
.file-input-label { .file-input-label {
display: block; display: block;
margin-top: 1rem; margin-top: 1rem;
@ -46,17 +59,17 @@ img { width: 100%; }
.copy-to-clipboard { .copy-to-clipboard {
display: flex; display: flex;
margin: 2rem 0; margin: 2rem 0;
border: 1px solid #000000; border: 1px solid var(--b);
} }
.copy-to-clipboard input[type=text] { .copy-to-clipboard input[type=text] {
flex: 50%; flex: 50%;
width: 100%; width: 100%;
padding: 12px 20px; padding: 12px 20px;
border: none; border: none;
outline: none; outline: none;
background-color: var(--w);
color: var(--b);
} }
.copy-to-clipboard button { .copy-to-clipboard button {
padding: 12px 20px; padding: 12px 20px;
margin: 0; margin: 0;
@ -64,8 +77,8 @@ img { width: 100%; }
cursor: pointer; cursor: pointer;
text-align: center; text-align: center;
border: none; border: none;
background-color: #000000; background-color: var(--b);
color: #ffffff; color: var(--w);
} }
/* cURL command */ /* cURL command */
@ -73,13 +86,15 @@ img { width: 100%; }
text-align: left; text-align: left;
padding: 12px 20px; padding: 12px 20px;
font-size: 14px; font-size: 14px;
background: #000000; background: var(--b);
color: #ffffff; color: var(--w);
overflow-x: auto; overflow-x: auto;
} }
.logo pre { /* SVG */
display: flex; svg {
justify-content: center; color: var(--b);
text-align: left; }
svg path {
stroke: currentcolor;
} }