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:
```bash
```shell
docker build --tag imgs .
```
Run container from image. Replace **/path/to/your/uploads/dir** with path to directory where you want to store images:
```
sudo docker run --rm --name imgs --detach --publish 127.0.0.1:5000:5000 --volume /path/to/your/uploads/dir:/opt/imgs/uploads imgs
```shell
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:
@ -59,7 +63,7 @@ server {
imgs has a simple CLI tool based on curl. Copy **imgs** script to your PATH.
```bash
```shell
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).
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
# This is an imgs <https://gitea.gch.icu/ge/imgs> "integration" for Nautilus.
#!/bin/sh
# This is an imgs https://git.nxhs.cloud/ge/imgs "integration" for Nautilus.
# Place this script into path: $HOME/.local/share/nautilus/scripts
# See more info at: <https://help.ubuntu.com/community/NautilusScriptsHowto>
imgs_check_vars() {
[ "$IMGSLOG" ] || IMGSLOG=$HOME/imgs_debug.log
[ "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
IMGSLOG="${IMGSLOG:-$HOME/imgs_debug.log}"
[ -n "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
if [ -f "$HOME/.imgsremote" ]; then
. $HOME/.imgsremote
fi
if [ -f "$HOME"/.imgsremote ]; then
# shellcheck source=/dev/null
. "$HOME"/.imgsremote
fi
if [ "$IMGSREMOTE" ]; then
:
else
echo "$0: Error: IMGSREMOTE variable is not set." >&2
exit 1
fi
}
if [ -z "$IMGSREMOTE" ]; then
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"
while read -r file; do
[ "$file" ] || break
if [ "$IMGSDEBUG" ]; then
echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | while read -r file; do
[ -z "$file" ] && break
if [ -n "$IMGSDEBUG" ]; then
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
image="$(curl -L -F "image=@$file" "$IMGSREMOTE")"
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"
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"

106
imgs
View File

@ -1,74 +1,74 @@
#!/usr/bin/env bash
# imgs CLI client.
# Home page: <https://gitea.gch.icu/ge/imgs>
#!/bin/sh
# imgs CLI https://git.nxhs.cloud/ge/imgs
imgs_usage() {
cat <<- EOF
Upload images to remote imgs server.
cat <<- EOF
Upload images to remote imgs server.
Usage: imgs [--version] [--help] [-r | --remote <URL>] <file>...
Usage: imgs [-rvh] <file>...
Options:
-r, --remote remote imgs instance URI. Example:
'https://user:password@example.org'
--version print version and exit.
--help print this help message and exit.
Options:
-r, --remote remote imgs instance URI e.g. https://user:password@example.org
-v, --version print version and exit.
-h, --help print this help message and exit.
Environment variables:
IMGSREMOTE remote imgs instance URI.
IMGSDEBUG enables verbose mode and logging.
IMGSLOG path to logfile. Default: ~/imgs_debug.log
Environment variables:
IMGSREMOTE remote imgs instance URI.
IMGSDEBUG enables verbose mode and logging.
IMGSLOG path to logfile. Default: ~/imgs_debug.log
You can set variables in ~/.imgsremote file instead of ~/.bashrc
See <https://gitea.gch.icu/ge/imgs> for more info.
EOF
exit 0
You can set variables in ~/.imgsremote file instead of ~/.bashrc
See <https://git.nxhs.cloud/ge/imgs> for more info.
EOF
}
imgs_check_vars() {
[ "$IMGSLOG" ] || IMGSLOG=$HOME/imgs_debug.log
[ "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
[ "$#" -eq 0 ] && { imgs_usage; exit 1; }
if [ -f "$HOME/.imgsremote" ]; then
. $HOME/.imgsremote
fi
if [ "$IMGSREMOTE" ]; then
:
else
echo "$0: Error: IMGSREMOTE variable is not set." >&2
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;;
# Transform long options to short ones
for arg in "$@"; do
shift
case "$arg" in
--remote) set -- "$@" "-r";;
--help) set -- "$@" "-h";;
--version) set -- "$@" "-v";;
*) set -- "$@" "$arg";;
esac
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")"
if [ "$IMGSDEBUG" ]; then
echo "Uploading $filepath" | tee -a "$IMGSLOG"
if [ -n "$IMGSDEBUG" ]; then
echo "Uploading $filepath ..." | tee -a "$IMGSLOG"
curl -v -L -F "image=@/$filepath" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG"
else
curl -L -F "image=@/$filepath" "$IMGSREMOTE"
fi
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">
<pre> __<br>|__| _____ ____ ______<br>| |/ \ / ___\/ ___/<br>| | Y Y / /_/ \___ \<br>|__|__|_| \___ /____ ><br> \/_____/ \/</pre>
</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>
</body>

131
style.css
View File

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