Script updates and README update

This commit is contained in:
kayos@tcp.direct 2022-04-23 18:18:26 -07:00
parent c18f640595
commit 4be8b1bcea
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
5 changed files with 124 additions and 17 deletions

View File

@ -1,15 +1,20 @@
**tcp.ac** - it's things
# tcp.ac
img
its images, online
txt
its txt, binned, online (probably optional client side encryption)
[ smol ]
url
its urls, shortened, online
- [x] img
images online
yup
using bitcask databases to store everything
- [x] txt
text online
- [ ] url
smol rsrc locatrs
### Credits
proudly powered by [bitcask](https://git.mills.io/prologic/bitcask).
All images and text data is stored within bitcask key/value stores.

74
config/config.go Normal file
View File

@ -0,0 +1,74 @@
package config
import (
"fmt"
"os"
"strconv"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
// //////////// global declarations
var (
// config directives
debugBool bool
baseURL string
webPort string
webIP string
dbDir string
logDir string
uidSize int
keySize int
txtPort string
maxSize int
// utilitarian globals
err error
fn string
s string
i int
f *os.File
)
func configRead() {
// name of the file
// and the extension
viper.SetConfigName("config")
viper.SetConfigType("toml")
// potential config paths
viper.AddConfigPath("./")
viper.AddConfigPath("")
viper.AddConfigPath("/etc/tcpac/")
// this should be replaced with more intelligent handling
err = viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error reading config file: %s \n", err))
}
// read config
debugBool = viper.GetBool("global.debug") // we need to load the debug boolean first
if debugBool {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
log.Debug().Msg("Debug mode enabled")
} else {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
baseURL = viper.GetString("http.baseurl")
i := viper.GetInt("http.port")
webPort = strconv.Itoa(i)
webIP = viper.GetString("http.bindip")
dbDir = viper.GetString("files.data")
logDir = viper.GetString("files.logs")
uidSize = viper.GetInt("global.uidsize")
keySize = viper.GetInt("global.delkeysize")
txtPort = viper.GetString("txt.port")
maxSize = viper.GetInt("files.maxuploadsize")
//
}

View File

@ -1,5 +1,8 @@
#!/bin/sh
# https://git.tcp.direct/S4D
# https://git.tcp.direct/tcp.direct/tcp.ac/commit/c18f64059542e35144fd7a479e6758549d017753
function tcpup {
options="Upload an Image\nRecent Uploads\nCancel"
selected=$(echo -e $options | dmenu -l 3 )

14
scripts/tcpurge.sh Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
echo "Deleting all remote copies of tcp.ac images made by uploader.sh in $(pwd)/...."
echo "sleeping for 5 seconds, CTRL+C to cancel"
sleep 5
find "$(pwd)/" -maxdepth 1 -iname "*.DELETEKEY" -print | while read -r line; do
echo "$line"
cat "$line" | \
grep "ToDelete" | \
awk '{print $2}' | tr -d '"' | \
while read -r line; do
curl -s "$line" & sleep 0.5;
done
done;

View File

@ -1,5 +1,17 @@
#!/usr/bin/env bash
#
# tcp.ac uploader script, works in terminal or can be used with scrot.
#
# example openbox configuration to use scrot on the printscreen keybinding for easy image uploads:
#
# <keybind key="Print">
# <action name="Execute">
# <command>scrot -f -s -e 'tcpac $f'</command>
# </action>
# </keybind>
#
####################### https://github.com/tlatsas/bash-spinner
function _spinner() {
@ -11,7 +23,6 @@ function _spinner() {
local on_success="DONE"
local on_fail="FAIL"
local white="\e[1;37m"
local green="\e[1;32m"
local red="\e[1;31m"
local nc="\e[0m"
@ -83,10 +94,10 @@ if ! [[ "$OUT" == *"Imgurl"* ]]; then
stop_spinner 2
exit 2
else
CLEAN=$(echo $OUT | sed 's|\\||g' | sed 's|"{"|{"|g' | sed 's|"}"|"}|g')
echo $CLEAN | jq | tee $1.DELETEKEY
IMGURL=$(echo $CLEAN | awk -F ':' '{print $2 $3}' | awk -F ',' '{print $1}' | awk -F '}' '{print $1}' | sed -e 's|"||g' -e 's|"||g' -e 's|https|https:|g' -e 's|http\/\/|http:\/\/|g')
echo -n $IMGURL | xclip -sel clip
notify-send -i image-x-generic 'tcp.ac upload success' 'link copied to clipboard, delete key saved' -t 5000
_CLEAN=$(echo "$OUT" | sed 's|\\||g' | sed 's|"{"|{"|g' | sed 's|"}"|"}|g')
echo "$_CLEAN" | jq | tee "$1.DELETEKEY"
_IMGURL=$(echo "$_CLEAN" | awk -F ':' '{print $2 $3}' | awk -F ',' '{print $1}' | awk -F '}' '{print $1}' | sed -e 's|"||g' -e 's|"||g' -e 's|https|https:|g' -e 's|http\/\/|http:\/\/|g')
echo -n "$_IMGURL" | xclip -sel clip
notify-send -i image-x-generic 'tcp.ac upload success' 'link copied to clipboard, delete key saved in file adjacent to original image' -t 5000
fi
stop_spinner $?