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
Changes from 1 commit
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
104 changes: 59 additions & 45 deletions ya-setup
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

#### 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

### 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 +23,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 "Yandex disk client authorization success"
slytomcat marked this conversation as resolved.
Show resolved Hide resolved
else
# auth failed
zenity --warning --title="$_YD_auth_title" --text "$auth_output"
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
##############################