Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup fixes #216

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
man
.*
__pycache__/*
*.iml
1 change: 1 addition & 0 deletions translations/ya-setup-be.lang
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ _Select_folder="Выбар фолдэра для сінхранізацыі"
_Token_title="Выбар шляху да файла токена"
_Token_body="Увядзіце шлях да файла токена (або пакіньце значэнне па змаўчанні)"
_YD_auth_title="Яндекс.Дыск - аўтарызацыя ..."
_YD_auth_success="Аўтарызацыя на Яндекс.Диске выканана"
1 change: 1 addition & 0 deletions translations/ya-setup-bg.lang
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ _Select_folder="Избор на папка"
_Token_title="Избор на токен файл"
_Token_body="Изберете път до токен файла (или оставете както е по подразбиране)"
_YD_auth_title="Yandex.Disk - авторизация..."
_YD_auth_success="Упълномощаването на Yandex.Disk е завършено"
1 change: 1 addition & 0 deletions translations/ya-setup-el.lang
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ _Select_folder="Επιλογή φακέλου για το συγχρονισμό
_Token_title="Επιλέγοντας το δρόμο προς το συμβολικό αρχείο"
_Token_body="Πληκτρολογήστε τη διαδρομή προς το συμβολικό αρχείο"
_YD_auth_title="Yandex.Δίσκος - εξουσιοδότηση..."
_YD_auth_success="Η εξουσιοδότηση στο Yandex.Disk έχει ολοκληρωθεί"
1 change: 1 addition & 0 deletions translations/ya-setup-en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions translations/ya-setup-ru.lang
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ _Select_folder="Выбор папки для синхронизации"
_Token_title="Выбор пути до файла токена"
_Token_body="Введите путь к файлу токена (или оставьте значение по умолчанию)"
_YD_auth_title="Яндекс.Диск - авторизация..."
_YD_auth_success="Авторизация на Яндекс.Диске выполнена"
108 changes: 63 additions & 45 deletions ya-setup
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем повторый вызов авторизации через рекурсию делать? В цикле что-ли нельзя?

Copy link
Author

@14v 14v Jan 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В цикле - while $notAuthorized? Используя функцию не нужно заводить переменную, повторный вызов явно указывает на точку входа, не нужно проверять возможную вложнность циклов - функциональный вариант более читабельный.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Завести функцию и заваливать стек рекурсивными ее вызовами это конечно экономнее чем завести одну переменную для одного (не вложенного) простого цикла. :)

Извините, но я в душе максималист-оптимизатор и рекурсия вместо цикла - для мня - стрельба из пушки по воробьям.

Рекурсия бывает нужна - не спорю. Но не тут.

Где там нужна проверка вложенности каких циклов, и чем это вредит читабельности - мне тоже не понять...

fi
else
exit 1
fi
}

showAuthDialog
##############################