diff --git a/config/zymp3.conf b/config/zymp3.conf index 5cf0a92..5c721eb 100644 --- a/config/zymp3.conf +++ b/config/zymp3.conf @@ -3,11 +3,14 @@ #Zymp3 Configuration File - -#FILE SETTINGS +#FILE PATHS +INSTALLPATH="/opt/zymp3" #your choice +IMGDIR="/usr/share/pixmaps" #keep set +DESKTOPFILEDIR="/usr/share/applications" #keep set +SET_GUI_BIN="zenity" #MUSICDIR must have trailing forward slash -MUSICDIR="/home/$USER/Music/" +MUSICDIR="/home/$USER/Music/" #your choice #You shouldn't need to change this filename but just in case VIDEOFILE=/tmp/youtube-dl-$RANDOM-$RANDOM.flv diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..9620fd4 --- /dev/null +++ b/install.sh @@ -0,0 +1,195 @@ +#!/bin/bash + +source config/zymp3.conf + +if [[ $EUID -ne 0 ]]; then + echo "$0 : This script must be run as root" + exit 1 +fi + +#List of cuntions to check dependencies (will re-work this later) +checkYoutubedl(){ + + if [ ! -f /usr/bin/youtube-dl ];then + false + else + true + fi +} + + +checkFfmpeg(){ + if [ ! -f /usr/bin/ffmpeg ];then + false + else + true + fi +} + + +checkZenity(){ + if [ ! -f /usr/bin/zenity ];then + false + else + true + fi + +} + +checkYad(){ + if [ ! -f /usr/bin/yad ];then + false + else + true + fi +} + +checkXdg(){ + if [ ! -f /usr/bin/xdg-open ];then + false + else + true + fi +} + +checkNotify(){ + if [ ! -f /usr/bin/notify-send ];then + false + else + true + fi +} + +checkInstall(){ + if [ ! -d ${INSTALLPATH} ];then + false + else + true + fi +} + + +echo "Checking dependencies...";echo + +#Check the status of each function +#each variable contains a number based on exit status of each function +checkYoutubedl +if [ $? -eq "1" ];then + YSTATUS=0 + echo "is youtube-dl installed?: no" +else + YSTATUS=1 + echo "is youtube-dl installed?: yes" +fi + +checkFfmpeg +if [ $? -eq "1" ];then + FSTATUS=0 + echo "is ffmpeg installed?: no" +else + FSTATUS=1 + echo "is ffmpeg installed?: yes" +fi + +checkZenity +if [ $? -eq "1" ];then + ZSTATUS=0 + echo "is zenity installed?: no" +else + ZSTATUS=1 + echo "is zenity installed?: yes" +fi + +checkYad +if [ $? -eq "1" ];then + YASTATUS=0 + echo "is yad install?: no" +else + YASTATUS=1 + echo "is yad installed?: yes" +fi + +checkXdg +if [ $? -eq "1" ];then + XSTATUS=0 + echo "is xdg-utils install?: no" +else + XSTATUS=1 + echo "is xdg-utils installed?: yes" +fi + + +checkNotify +if [ $? -eq "1" ];then + NSTATUS=0 + echo "is libnotify install?: no" +else + NSTATUS=1 + echo "is libnotify installed?: yes" +fi + + +checkInstall +if [ $? -eq "1" ];then + ISTATUS=0 + echo "does ${INSTALLPATH} exist?: no" +else + ISTATUS=1 + echo "does ${INSTALLPATH} exist?: yes" +fi + +if [ ${ISTATUS} = 0 ];then + echo -n "${INSTALLPATH} does not exist, do you want to create it?[y/n]: " + read answer + if [ ${answer} = "y" ];then + mkdir -v ${INSTALLPATH} + ISTATUS=1 + else + echo "$0 : ERROR: could not create ${INSTALLPATH}" + fi +fi + +#add all exit status variables and check the sum +#if a certain number is not reached, the check fails +#if the check succeeds, files are installed +#TODO add checks to verify installation +ALLSTATUS=$(expr ${YSTATUS} + ${FSTATUS} + ${ZSTATUS} + ${YASTATUS} + ${XSTATUS} + ${NSTATUS} + ${ISTATUS}) + +if [ ${ALLSTATUS} != 7 ];then + echo "$0 : ERROR : not all dependencies installed!" + exit 0; +else + echo "Everything looks good!" + echo + echo -n "Continue installation?[y/n]: " + read confirm + + if [ "${confirm}" = "y" ];then + cp -v zymp3 ${INSTALLPATH} + cp -v -R lib ${INSTALLPATH} + cp -v -R config ${INSTALLPATH} + cp -v uninstall.sh ${INSTALLPATH} + cp -v assets/zymp3.png ${IMGDIR} + cp -v assets/zymp3.desktop ${DESKTOPFILEDIR} + echo '#!/bin/bash' > ${INSTALLPATH}/zymp3-run.sh + echo "cd ${INSTALLPATH}" >> ${INSTALLPATH}/zymp3-run.sh + echo "./zymp3" >> ${INSTALLPATH}/zymp3-run.sh + chmod -R 777 /opt/zymp3 + mv ${INSTALLPATH}/zymp3-run.sh /usr/bin/zymp3 + + if [ ! -d ${INSTALLPATH} ];then + echo "Zymp3 not installed successfully" + echo "Please file a bug report at: https://github.com/silvernode/zymp3/issues" + else + echo "Zymp3 successfully installed to: ${INSTALLPATH}" + echo "An icon has been created in your application menu under the multimedia category." + fi + else + echo "Installation cancelled..." + exit 0; + fi + +fi + + + diff --git a/lib/logic.lib b/lib/logic.lib index 6241af9..7ad8b7d 100644 --- a/lib/logic.lib +++ b/lib/logic.lib @@ -1,11 +1,13 @@ #!/bin/bash - +source config/zymp3.conf if [ ! -f /usr/bin/yad ];then SET_GUI_BIN="zenity" -else +elif [ ! -f /usr/bin/zenity ];then SET_GUI_BIN="yad" +else + SET_GUI_BIN="${SET_GUI_BIN}" fi if [ ! -f /usr/bin/ffmpeg ];then @@ -37,7 +39,7 @@ fi #first zenity gui window (paste youtube link) gui() { - VIDURL=$(${SET_GUI_BIN} --title="Zymp3 0.1-5" --height=${URL_BOX_HEIGHT} --width=${URL_BOX_WIDTH} --entry --text "Paste youtube link here: ") + VIDURL=$(${SET_GUI_BIN} --title="Zymp3 0.1-6" --height=${URL_BOX_HEIGHT} --width=${URL_BOX_WIDTH} --entry --text "Paste youtube link here: ") if [[ $? == 0 ]] ; then gui2 diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..94e1645 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +source config/zymp3.conf #get $INSTALLPATH variable from config + +if [[ $EUID -ne 0 ]]; then + echo "$0 : This script must be run as root" + exit 1 +fi + + +if [ ! -d ${INSTALLPATH} ];then + INSTALLDIR=0 +else + INSTALLDIR=1 +fi + +if [ ! -f /usr/bin/zymp3 ];then + BINFILE=0 +else + BINFILE=1 +fi + +if [ ! -f /usr/share/applications/zymp3.desktop ];then + DESKTOPFILE=0 +else + DESKTOPFILE=1 +fi + +COUNT=$(expr ${INSTALLDIR} + ${BINFILE} + ${DESKTOPFILE}) + +if [ "${COUNT}" = "3" ];then + echo "Looks like zymp3 is still installed" + echo -n "Would you like to remove all files?[y/n]: " + read CHOICE + + if [ "${CHOICE}" = "y" ];then + rm -v -R ${INSTALLPATH} && INSTALLDIR=0 + rm -v /usr/bin/zymp3 && BINFILE=0 + rm -v /usr/share/applications/zymp3.desktop && DESKTOPFILE=0 + + COUNT=$(expr ${INSTALLDIR} + ${BINFILE} + ${DESKTOPFILE}) + + if [ "${COUNT}" = "0" ];then + echo "Zymp3 has been successfully is uninstalled" + else + echo "$COUNT" + echo "It seems the uninstall did not go smoothly." + echo "Please file a bug report at: https://github.com/silvernode/zymp3/issues" + fi + fi +else + echo "Zymp3 is not installed, please run install.sh" +fi + + + diff --git a/zymp3 b/zymp3 index 0f78b19..b170106 100755 --- a/zymp3 +++ b/zymp3 @@ -1,10 +1,10 @@ #!/bin/bash ############################################## -# Title: Zymp3 v0.1-5 +# Title: Zymp3 v0.1-6 # Description: Convert youtube video to mp3 # Author: Justin Moore # Created: Oct 12, 2011 -# Updated: Jan 16, 2015 +# Updated: Feb 25, 2015 # Contact: mollusk@homebutter.com # github: https://github.com/silvernode/zymp3 ############################################## @@ -14,31 +14,28 @@ - - #check for config file in two locations chk_conf(){ -if [ -f ~/.config/Zymp3/zymp3.conf ];then - source ~/.config/Zymp3/zymp3.conf - - -elif [ -f config/zymp3.conf ];then +if [ -f config/zymp3.conf ];then source config/zymp3.conf + + else - echo -e "\e[1;31mERROR: No config file in $HOME/.config/Zymp3/ or /config/ \e[0m" - zenity --error --text "No config file in $HOME/.config/Zymp3/ or /config" + echo -e "\e[1;31mERROR: No config file found, report bugs to: https://github.com/silvernode/zymp3/issues \e[0m" + zenity --error --text "No config file found, report bugs to: https://github.com/silvernode/zymp3/issues" exit 0; fi } chk_libs(){ if [ -f lib/logic.lib ];then - source lib/logic.lib + source lib/logic.lib + else - echo -e "\e[1;31mERROR: No libraries file found in ../libs \e[0m" - zenity --error --text "No libraries file found in ../libs" + echo -e "\e[1;31mERROR: logic.lib not found, report bugs to https://github.com/silvernode/zymp3/issues \e[0m" + zenity --error --text "logic.lib not found, report bugs to: https://github.com/silvernode/zymp3/issues" exit 0; fi