From 88051b5b2d22174b8483ccb06789e0bbb640a9f7 Mon Sep 17 00:00:00 2001 From: AmirrezaFiroozi Date: Mon, 9 May 2016 12:35:46 +0430 Subject: [PATCH] Add files via upload --- installer.sh | 17 +++++++++++ wttr | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 installer.sh create mode 100644 wttr diff --git a/installer.sh b/installer.sh new file mode 100644 index 0000000..6e798ac --- /dev/null +++ b/installer.sh @@ -0,0 +1,17 @@ +#!/bin/bash +#author : Amirreza Firooz +#installer of wttr +clear +echo -e "******************************\nWelcome to installer of wttr \n *************************** \n Installing ..." +sudo cp -R "wttr" /usr/bin + st_0=$? +cd /usr/bin +echo -e "******************************\n Giving permission ..." +sudo chmod +x wttr + st_1=$? +if [ $st_0 == 0 ] && [ $st_1 == 0 ];then + echo -e "\n********* Congratulations!!! installation has just completed *********\n" + wttr -h +else + echo -e "\n There were some problems while installing :(\n Installation failed :( " +fi diff --git a/wttr b/wttr new file mode 100644 index 0000000..541e7a2 --- /dev/null +++ b/wttr @@ -0,0 +1,79 @@ +#!/bin/bash +#Author : Amirreza Firoozi +#name : wttr + +wttr_ver="1.2" #define script version +if [ -f "$HOME/.wttr/default.txt" ];then #check if user set default city or not . if user did load it to variable def + cd $HOME/.wttr + def=$(cat default.txt) + +elif [ ! -d $HOME/.wttr ];then #if he/she didn`t make a blank file + mkdir ".wttr" + echo "" > default.txt + def="" +fi +if [ "$#" == "0" ] && [ "$def" == "" ];then + echo -e "You have not entered any parameters \n Needs help? try wttr -h" +elif [ "$#" -gt "2" ];then + + echo -e "too many parameters. \n Needs help? try wttr -h" + else + case $1 in + "-h") #showing help + echo -e "\n This is a simple app to check weather condition.\n wttr is under GPL3 License. source is available on Github : https://Github.com/AmirrezaFiroozi/wttr \n Created by : Amirreza Firoozi \n Thanks to : Jadi & Alireza Amirsamimi & Mostafa Asadi \n Write wttr {your city name} to check the weather condition of your city. example : wttr fasa \n -m for photo of moon \n -h for some help (this page) \n -v for script version \n -i to install curl which is necessary for script to run correctly\n -rm to remove the script :( \n -sdef to define a city as your default city \n Any bugs? Any suggestions? Contact us : firoozi128.af&gmail.com " + ;; + "-v") + echo -e " wttr_VERSION is : "$wttr_ver" " + ;; + "-m") + curl http://wttr.in/moon + ;; + "-i") + sudo apt install curl + ;; + "-rm") + read -p "Do you Really want to remove wttr?(y/n)" response + if [ "$response" == "y" ];then + cd /usr/bin + sudo rm -R "wttr" + if [ -d "$HOME/.wttr" ];then + sudo rm -d "$HOME/.wttr" + fi + echo -e "Script has deleted :(" + else + echo -e "Opration canceled" + fi + ;; + "-sdef") # set the default city + if [ ! -d $HOME/.wttr ];then + cd $HOME + mkdir ".wttr" + fi + if [ "$#" == "2" ];then + cd $HOME/.wttr + echo "$2" > default.txt + else + read -p " Enter your city name to set as the default city (example : fasa) : " def + if [ "$def" == "" ] && [ "$#" -ls "2" ];then + echo "you did NOT enter anything ..." + else + cd $HOME/.wttr + echo $def > default.txt + fi + fi #end of the second if + echo -e "\n Congratulations!! we set $def as your default city. You can check its weather condition by typing only wttr Since now :)" + ;; + "") + cd $HOME + curl http://wttr.in/"$def" + ;; + *) + + curl http://wttr.in/"$1" + + ;; + esac +fi + + +