diff --git a/.gitignore b/.gitignore index 99c459b..8c4cf16 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ man .* __pycache__/* +*.iml \ No newline at end of file diff --git a/translations/ya-setup-be.lang b/translations/ya-setup-be.lang index 1b80fc0..5bb21d4 100644 --- a/translations/ya-setup-be.lang +++ b/translations/ya-setup-be.lang @@ -18,3 +18,4 @@ _Select_folder="Выбар фолдэра для сінхранізацыі" _Token_title="Выбар шляху да файла токена" _Token_body="Увядзіце шлях да файла токена (або пакіньце значэнне па змаўчанні)" _YD_auth_title="Яндекс.Дыск - аўтарызацыя ..." +_YD_auth_success="Аўтарызацыя на Яндекс.Диске выканана" \ No newline at end of file diff --git a/translations/ya-setup-bg.lang b/translations/ya-setup-bg.lang index 5bca78d..4c66c23 100644 --- a/translations/ya-setup-bg.lang +++ b/translations/ya-setup-bg.lang @@ -18,3 +18,4 @@ _Select_folder="Избор на папка" _Token_title="Избор на токен файл" _Token_body="Изберете път до токен файла (или оставете както е по подразбиране)" _YD_auth_title="Yandex.Disk - авторизация..." +_YD_auth_success="Упълномощаването на Yandex.Disk е завършено" \ No newline at end of file diff --git a/translations/ya-setup-el.lang b/translations/ya-setup-el.lang index 0a3a055..059924d 100644 --- a/translations/ya-setup-el.lang +++ b/translations/ya-setup-el.lang @@ -18,3 +18,4 @@ _Select_folder="Επιλογή φακέλου για το συγχρονισμό _Token_title="Επιλέγοντας το δρόμο προς το συμβολικό αρχείο" _Token_body="Πληκτρολογήστε τη διαδρομή προς το συμβολικό αρχείο" _YD_auth_title="Yandex.Δίσκος - εξουσιοδότηση..." +_YD_auth_success="Η εξουσιοδότηση στο Yandex.Disk έχει ολοκληρωθεί" \ No newline at end of file diff --git a/translations/ya-setup-en.lang b/translations/ya-setup-en.lang index 7bd4852..da8fbcb 100644 --- a/translations/ya-setup-en.lang +++ b/translations/ya-setup-en.lang @@ -18,3 +18,4 @@ _Select_folder="Select folder" _Token_title="Select token file" _Token_body="Enter path to the token file (or leave the default)" _YD_auth_title="Yandex.Disk - authorization..." +_YD_auth_success="Yandex.Disk authorization success" \ No newline at end of file diff --git a/translations/ya-setup-ru.lang b/translations/ya-setup-ru.lang index ed4b205..e5bee56 100644 --- a/translations/ya-setup-ru.lang +++ b/translations/ya-setup-ru.lang @@ -18,3 +18,4 @@ _Select_folder="Выбор папки для синхронизации" _Token_title="Выбор пути до файла токена" _Token_body="Введите путь к файлу токена (или оставьте значение по умолчанию)" _YD_auth_title="Яндекс.Диск - авторизация..." +_YD_auth_success="Авторизация на Яндекс.Диске выполнена" \ No newline at end of file diff --git a/ya-setup b/ya-setup index 9011bad..e7b042f 100755 --- a/ya-setup +++ b/ya-setup @@ -2,19 +2,23 @@ #### Author: Snow Dimon #### #### Website: snowdimon.ru #### -#### modified by SlyTomCat: +#### modified by SlyTomCat: #### - adoption to alternative configuration of Yandex Disk daemon #### - addes quotes around config values #### modified by Ivan Burmin: #### - multi-language support +#### modified by s3r6: +#### - exiting setup dialogs on wrong password fix +#### - authorization error output without cutting text +#### - successfull authorization shows notification ### Command line positional argument: $1 - configfile path -if [ $# -eq 1 ];then +if [ $# -eq 1 ]; then conf=$1 -else +else conf="/home/$USER/.config/yandex-disk/config.cfg" -fi +fi ### Language @@ -23,59 +27,73 @@ lang_home="/usr/share/yd-tools/translations" lang_file="$lang_home/ya-setup-$(echo $LANG | cut -c 1-2).lang" if [ ! -f $lang_file ]; then - lang_file="$lang_home/ya-setup-en.lang" + lang_file="$lang_home/ya-setup-en.lang" fi source $lang_file ###Proxy -ans=$(zenity --list --cancel-label="$_Exit" --ok-label="$_Next" --title "$_YD_setup_title" --text "$_Welcome1 $conf.$_Welcome2" --radiolist --hide-header --column "" --column "$_Options" TRUE "$_No" FALSE "$_Yes" FALSE "$_System_set") -if [ $? -eq "0" ];then - if [ "$ans" = "$_No" ]; then - echo "proxy=\"no\"" > $conf - - else - if [ "$ans" = "$_System_set" ]; then - echo "proxy=\"auto\"" > $conf - - else - if [ "$ans" = "$_Yes" ]; then - echo "proxy=\"`zenity --entry --title="$_Proxy_title" --text="$_Proxy_body" \ - --entry-text="https,127.0.0.1,443,login,password"`\"" > $conf - fi - fi - fi +ans=$(zenity --list --cancel-label="$_Exit" --ok-label="$_Next" --title "$_YD_setup_title" --text "$_Welcome1 $conf.$_Welcome2" --radiolist --hide-header --column "" --column "$_Options" TRUE "$_No" FALSE "$_Yes" FALSE "$_System_set") +if [ $? -eq "0" ]; then + if [ "$ans" = "$_No" ]; then + echo "proxy=\"no\"" >$conf + + else + if [ "$ans" = "$_System_set" ]; then + echo "proxy=\"auto\"" >$conf + + else + if [ "$ans" = "$_Yes" ]; then + echo "proxy=\"$(zenity --entry --title="$_Proxy_title" --text="$_Proxy_body" \ + --entry-text="https,127.0.0.1,443,login,password")\"" >$conf + fi + fi + fi else -exit 1 + exit 1 fi ###Folder -ans=$(zenity --list --cancel-label="$_Exit" --ok-label="$_Next" --title "$_YD_setup_title" --text "$_Folder_body" --radiolist --hide-header --column "" --column "$_Options" TRUE "$_Default" FALSE "$_Existing") -if [ $? -eq "0" ];then - if [ "$ans" = "$_Default" ]; then - mkdir /home/$USER/Yandex.Disk - echo "dir=\"/home/$USER/Yandex.Disk\"" >> $conf - - else - if [ "$ans" = "$_Existing" ]; then - folder=`zenity --file-selection --directory --title="$_Select_folder"` - echo "dir=\"$folder\"" >> $conf - fi - fi +ans=$(zenity --list --cancel-label="$_Exit" --ok-label="$_Next" --title "$_YD_setup_title" --text "$_Folder_body" --radiolist --hide-header --column "" --column "$_Options" TRUE "$_Default" FALSE "$_Existing") +if [ $? -eq "0" ]; then + if [ "$ans" = "$_Default" ]; then + mkdir /home/$USER/Yandex.Disk + echo "dir=\"/home/$USER/Yandex.Disk\"" >>$conf + + else + if [ "$ans" = "$_Existing" ]; then + folder=$(zenity --file-selection --directory --title="$_Select_folder") + echo "dir=\"$folder\"" >>$conf + fi + fi else -exit 1 + exit 1 fi ###Token auth=$(zenity --entry --title="$_Token_title" --text="$_Token_body" --entry-text="/home/$USER/.config/yandex-disk/passwd") -echo auth=\"$auth\" >> $conf - -ENTRY=`zenity --password --username --title="$_YD_setup_title"` -if [ $? -eq "0" ];then -echo $ENTRY | cut -d'|' -f2 | yandex-disk -a $auth token `echo $ENTRY | cut -d'|' -f1` | cut -d':' -f2 | zenity --text-info --width=350 --height=200 --title="$_YD_auth_title" -exit 0 -else -exit 1 -fi - +echo auth=\"$auth\" >>$conf + +function showAuthDialog() { + auth_form=$(zenity --password --username --title="$_YD_setup_title") + if [ $? -eq "0" ]; then + auth_username=$(echo "$auth_form" | cut -d'|' -f1) + auth_pass=$(echo "$auth_form" | cut -d'|' -f2) + + auth_output=$(yandex-disk token -p "$auth_pass" -a $auth "$auth_username") + + if [ $? -eq "0" ]; then + # auth ok + zenity --notification --text "$_YD_auth_success" + else + # auth failed + zenity --warning --title="$_YD_auth_title" --text "$auth_output" --no-wrap + showAuthDialog + fi + else + exit 1 + fi +} + +showAuthDialog ##############################