Skip to content

Commit

Permalink
Add option to logout
Browse files Browse the repository at this point in the history
  • Loading branch information
coditva committed Feb 5, 2017
1 parent 5c20c18 commit e41857b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Use terminal to issue this command: ```bitsnet```
Use specific username
-p PASSWORD
Specify a different password
-o
logout
-d
Turn debug on
-U
Expand Down
8 changes: 5 additions & 3 deletions bitsnet
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source ~/.local/lib/bitsnet/util.sh
source ~/.bitsnetrc

# Parse arguments
while getopts "u:p:dhU" o; do
while getopts "u:p:dhUo" o; do
case "${o}" in
u)
username=${OPTARG}
Expand All @@ -23,6 +23,9 @@ while getopts "u:p:dhU" o; do
U)
update
;;
o)
logOut
;;
h | * | [?])
show_help
;;
Expand Down Expand Up @@ -90,8 +93,7 @@ reply=$(wget -qO- --no-check-certificate --post-data="mode=191&username=$usernam

# Extract reply
debug_msg "Extracting reply"
reply="${reply##*\<message><\![CDATA[}"
reply=$(echo "$reply" | cut -d']' -f1)
reply=$(extract_msg $reply)


# Display reply or send a notification
Expand Down
15 changes: 15 additions & 0 deletions util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function show_help {
use specific username
-p PASSWORD
specify a different password
-o
logout
-d
turn debug on
-U
Expand All @@ -27,6 +29,12 @@ function debug_msg {
fi
}

function extract_msg {
reply="${reply##*\<message><\![CDATA[}"
reply=$(echo "$reply" | cut -d']' -f1)
echo $reply
}

function send_msg {
if [[ debug -eq 0 ]]; then
notify-send 'BITSnet' "$1" --icon=network-transmit
Expand All @@ -49,3 +57,10 @@ function update {
debug_msg "Exiting"
exit
}

function logOut() {
reply=$(wget -qO- --no-check-certificate --post-data="mode=193&username=$username&submit=Logout" $login_url)
reply=$(extract_msg $reply)
send_msg "$reply"
exit
}

0 comments on commit e41857b

Please sign in to comment.