Skip to content

Commit

Permalink
Merge pull request #21 from whats-this/master
Browse files Browse the repository at this point in the history
update v0.0.19
  • Loading branch information
OkashiOdayakana authored Jun 21, 2017
2 parents d4d78e1 + 1f5f4d4 commit e08a225
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.log
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sudo: required
language: generic

services:
- docker

script:
- wget -O- http://travis.debian.net/script.sh | sh -

branches:
except:
- /^debian\/\d/
38 changes: 17 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# owo.sh
# OwO.sh

A basic example/uploader for uploading to [owo-whats-th.is](https://owo.whats-th.is)'s image server. The aim was to have a script that allowed for users of all operating systems (that werent already supported by ShareX) to also be able to upload to whats-th.is related products.

Thank you to [jomo](https://github.com/jomo/) and his script [jomo/imgur-screenshot](https://github.com/jomo/imgur-screenshot), to which taking snippets and borrowing code has guided me to improving my own script. This script wouldn't be anywhere near what it is today without his efforts.

# Install

## dependencies
## Dependencies

| os | dependency | description
|--------------- |----------------------------- |-----------------------------------------------------------------------------------------------------
Expand All @@ -16,21 +14,19 @@ Thank you to [jomo](https://github.com/jomo/) and his script [jomo/imgur-screens
| | GREP | Comes standard with all UNIX OSes and is used to (in this case) decipher JSON.
| | cURL | Comes standard with all UNIX OSes and is used to (in this case) upload to the owo server.
| Linux | Notify-Send | Default Linux barely has any, if at all, notification support from terminal. This is a workaround.
| | Maim | A rich screenshotting client, that better than what comes default with Linux.
| | Maim | A rich screenshotting client, that better than what comes default with Linux.
| | XClip | Comes default with most UNIX based OSes and allows for things to copied to clipboards.
| | GREP | Comes standard with all UNIX OSes and is used to (in this case) decipher JSON.
| | cURL | Comes standard with all UNIX OSes and is used to (in this case) upload to the owo server.

## Instructions

1. Clone the repo with `git clone https://github.com/whats-this/owo.sh.git`
2. Make sure `script.sh` has permissions: `chmod a+x script.sh`.
3. Download the dependencies, you can check what you need with `./script.sh --check`
4. Put your token inside of `conf.cfg`, in `userkey="YOURUSERKEY"`
5. Run the command `./setup.sh` to add the owo command.
6. You can now run `owo file.png` from anywhere to upload `file.png`.
## Installation

# Usage
1. Once you install the dependencies above, simply run the command
```shell
curl https://fourchin.net/owo.sh | bash
```
in your terminal.
## Usage

Basic usage of the script is like so.

Expand Down Expand Up @@ -59,13 +55,13 @@ However the following flags can be placed after `owo` for the each of the result

Now when you press your selected shortcut, the screenshot uploader will be launched, without having to type anything in the shell.

# Contribute
### Contributing

1. Fork repo.
2. Edit code.
3. Make a PR.
4. Submit said PR.
Pull requests are accepted. Make sure you add test suites for new features and
make sure the code passes the spec (so the build doesn't break). Tests are
automatically run when commits are made in a pull request.

# License
### License

A copy of the MIT license can be found in `LICENSE.md`.
The contents of this repository are licensed under the MIT license. A
copy of the MIT license can be found in [LICENSE.md](LICENSE.md).
2 changes: 1 addition & 1 deletion conf.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ compatability=false
#Visit https://whats-th.is/faq.html#how-to-access-files for supported URLs

finished_url="owo.whats-th.is"

shorten_url="thats-a.link"
# ------

# Screenshots
Expand Down
117 changes: 110 additions & 7 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# | |
# |_|
#
# OWOUPLOADER.SH SCRIPT.
# OWO.SH SCRIPT.
# ----------------------
#
# This script allows for native support to upload to the image server
Expand All @@ -27,7 +27,7 @@ fi

owodir="$HOME/.config/owo"

current_version="v0.0.17"
current_version="v0.0.19"
##################################


Expand All @@ -47,9 +47,9 @@ output_url=$finished_url >&2
directoryname=$scr_directory >&2
filename=$scr_filename >&2
path=$scr_path >&2
no_notify=no_notify >&2
no_notify=$no_notify >&2
print_debug=$debug >&2

shorten_url=$shorten_url >&2
##################################

function is_mac() {
Expand Down Expand Up @@ -88,6 +88,101 @@ function clipboard() {
fi
}

function keyset() {
read -p "Please enter your API key: " keystring
sed -i /userkey=/c\userkey="$keystring" $owodir/conf.cfg
echo "Saved."
echo ""
settings
}

function finishset() {
read -p "Please enter your preferred URL for upload/screenshot: " finishstring
if [ $finishstring = "q" ]; then
settings
fi
sed -i /finished_url=/c\finished_url="$finishstring" $owodir/conf.cfg
echo "Saved."
echo ""
settings
}

function shortenset() {
read -p "Please enter your preferred URL for shortening: " shortenstring
if [ $finishstring = "q" ]; then
settings
fi
sed -i /shorten_url=/c\shorten_url="$shortenstring" $owodir/conf.cfg
echo "Saved."
echo ""
settings
}

function notif_prefs() {
read -p "Would you like to recieve notifications from OwO.sh? (y/n/q) " choice
case $choice in
y|Y ) sed -i /no_notify=/c\no_notify=false $owodir/conf.cfg; echo "Saved."; echo ""; misc;;
n|N ) sed -i /no_notify=/c\no_notify=true $owodir/conf.cfg; echo "Saved."; echo ""; misc;;
q|Q ) echo ""; misc;;
* ) echo "Invalid selection. Please choose y or n.";;
esac
}

function scrsave_prefs() {
read -p "Would you like to save screenshots to your local? (y/n/q) " choice
case $choice in
y|Y ) sed -i /keep_scr=/c\keep_scr=true $owodir/conf.cfg; echo "Saved."; echo ""; misc;;
n|N ) sed -i /keep_scr=/c\keep_scr=false $owodir/conf.cfg; echo "Saved."; echo ""; misc;;
q|Q ) echo ""; misc;;
* ) echo "Invalid selection. Please choose y or n.";;
esac
}

function xclip_prefs() {
read -p "Would you like links to be copied to your clipboard? (y/n/q) " choice
case $choice in
y|Y ) sed -i /scr_copy=/c\scr_copy=true $owodir/conf.cfg; sed -i /url_copy=/c\url_copy=true $owodir/conf.cfg; echo "Saved."; echo ""; misc;;
n|N ) sed -i /scr_copy=/c\scr_copy=false $owodir/conf.cfg; sed -i /url_copy=/c\url_copy=false $owodir/conf.cfg; echo "Saved."; echo ""; misc;;
q|Q ) echo ""; misc;;
* ) echo "Invalid selection. Please choose y or n."; misc;;
esac
}

function misc() {
echo "Miscellaneous Settings"
echo "1) Notification preferences"
echo "2) Screenshot saving preferences"
echo "3) Clipboard copying preferences"
echo "4) Go back"
read -p "Please enter your selection: " selection
case $selection in
1 ) notif_prefs;;
2 ) scrsave_prefs;;
3 ) xclip_prefs;;
4 ) settings;;
* ) echo "Invalid selection. Please choose 1, 2 or 3."; misc;;
esac
}

function settings() {
echo "OwO.sh Settings"
echo "1) API Key"
echo "2) Upload/Screenshot URL"
echo "3) Shorten URL"
echo "4) Misc"
echo "q) Quit"
read -p "Please enter your selection: " selection
case $selection in
1 ) keyset;;
2 ) finishset;;
3 ) shortenset;;
4 ) misc;;
q ) exit 0;;
* ) echo "Invalid selection. Please choose 1, 2, 3, or 4."; settings;;
esac
}


function shorten() {
check_key

Expand All @@ -102,10 +197,12 @@ function shorten() {
#Check if the URL entered is valid.
regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if [[ $url =~ $regex ]]; then
result=$(curl -s "https://api.awau.moe/shorten/polr?action=shorten&key=$key&url=$url")
result=$(curl -s "https://api.awau.moe/shorten/polr?action=shorten&key=$key&url=$url" -H "User-Agent: WhatsThisClient (https://github.com/whats-this/owo.sh, v0.0.19)")

#Check if the URL got sucessfully shortened.
if grep -q "https://" <<< "${result}"; then
code=$(echo $result | sed 's/.*oe//')
result="https://$shorten_url$code"
d=$1
if [ "$d" = "true" ]; then
clipboard $result
Expand Down Expand Up @@ -142,7 +239,7 @@ function screenshot() {

# Open our new entry to use it!
entry=$path$filename
upload=$(curl -s -F "files[]=@"$entry";type=image/png" https://api.awau.moe/upload/pomf?key="$key")
upload=$(curl -s -F "files[]=@"$entry";type=image/png" https://api.awau.moe/upload/pomf?key="$key" -H "User-Agent: WhatsThisClient (https://github.com/whats-this/owo.sh, v0.0.19)")

if [ "$print_debug" = true ] ; then
echo $upload
Expand Down Expand Up @@ -188,7 +285,7 @@ function upload() {

filesize=$(wc -c <"$entry")
if [[ $filesize -le 83886081 ]]; then
upload=$(curl -s -F "files[]=@"$entry";type=$mimetype" https://api.awau.moe/upload/pomf?key="$key")
upload=$(curl -s -F "files[]=@"$entry";type=$mimetype" https://api.awau.moe/upload/pomf?key="$key" -H "User-Agent: WhatsThisClient (https://github.com/whats-this/owo.sh, v0.0.19)")
item="$(egrep -o '"url":\s*"[^"]+"' <<<"${upload}" | cut -d "\"" -f 4)"
else
echo "ERROR : File size too large or another error occured!"
Expand Down Expand Up @@ -241,6 +338,7 @@ if [ "${1}" = "-h" ] || [ "${1}" = "--help" ] || [ "${1}" = "" ]; then
echo " -s --screenshot Begins the screenshot uploading process."
echo " -sl Takes a screenshot and shortens the URL."
echo " -ul Uploads file and shortens URL."
echo " --settings Opens settings page for OwO.sh"
echo ""
exit 0
fi
Expand Down Expand Up @@ -306,6 +404,11 @@ fi
exit 0
fi

##################################
if [ "${1}" = "--settings" ]; then
settings
exit 0
fi
##################################

if [ "${1}" = "-l" ] || [ "${1}" = "--shorten" ]; then
Expand Down
14 changes: 10 additions & 4 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# | |
# |_|
#
# OWOUPLOADER.SH SCRIPT.
# OWO.SH SCRIPT.
# ----------------------
#
# This script is designed for you to be able to run the
Expand Down Expand Up @@ -37,17 +37,23 @@ fi
scriptdir=$(dirname $(which $0))
owodir="$HOME/.config/owo"

if [ -d $owodir ]; then
cp $owodir/conf.cfg $owodir/conf.cfg.bak
fi

if [ ! -d $owodir ]; then
mkdir $owodir
cp -r $scriptdir/* $owodir
fi

cp -r $scriptdir/* $owodir

# Give directory ownership to the actual user
chown -R $(whoami | awk '{print $1}') $owodir

# Create a symbolic link to /usr/local/bin
sudo ln -s $owodir/script.sh /usr/local/bin/owo

if [ ! -f /usr/local/bin/owo ]; then
sudo ln -s $owodir/script.sh /usr/local/bin/owo
fi
function is_mac() {
uname | grep -q "Darwin"
}
Expand Down

0 comments on commit e08a225

Please sign in to comment.