You are not logged in.

#1 2017-06-19 16:36:39

satriani
Member
Registered: 2015-06-26
Posts: 26

PKGBUILD - Dialog to selecting the local file does not work as desired

Hi folks.
After a few users had difficulties installing my package because it needed a local file, I decided to make the installation easier.
It works so far very good, here is my code snippet from the PKGBUILD

.....
options=('!strip')
conflicts=('davinci-resolve')

while [ ! -f ${pkgdir}/DaVinci_Resolve_${pkgver}_Linux.zip ]
do
  if [ -f $HOME/Downloads/DaVinci_Resolve_${pkgver}_Linux.zip ]; then
    ln -s $HOME/Downloads/DaVinci_Resolve_${pkgver}_Linux.zip ${pkgdir}
  else
    _dialog="$(command -v zenity kdialog Xdialog | awk -F/ '{print $NF}' | xargs)"
    case $_dialog in
    zenity)
        pkgzip=$(zenity --info --text="Please select the package archive DaVinci_Resolve_${pkgver}_Linux.zip"
                 zenity  --file-selection --title="Please select the package archive DaVinci_Resolve_${pkgver}_Linux.zip" --filename=$HOME/)
        if [ "$?" -eq 1 ]; then
          zenity --info --text="Installation canceled"
          exit 0
        else
          ln -s ${pkgzip} ${pkgdir}
          break
        fi
        ;;
    kdialog)
        pkgzip=$(kdialog --msgbox "Please select the package archive DaVinci_Resolve_${pkgver}_Linux.zip"
                 kdialog --getopenfilename $HOME/ '*.zip'
        if [ "$?" -eq 1 ]; then
          kdialog --msgbox "Installation canceled"
          exit 0
        else
          ln -s ${pkgzip} ${pkgdir}
          break
        fi
        ;;
    xdialog)
        pkgzip=$(Xdialog --msgbox "Please select the package archive DaVinci_Resolve_${pkgver}_Linux.zip"
                 Xdialog --title "Please select the package archive DaVinci_Resolve_${pkgver}_Linux.zip" --fselect $HOME 28 48 2>&1)
        if [ "$?" -eq 1 ]; then
          Xdialog --msgbox "Installation canceled"
          exit 0
        else
          ln -s ${pkgzip} ${pkgdir}
          break
        fi
        ;;
    *)
        msg2 "Please remember to put a tarball DaVinci_Resolve_${pkgver}_Linux.zip in to ${pkgdir}"
        sleep 3
        break
        ;;
    esac
  fi
done

source=("local://DaVinci_Resolve_${pkgver}_Linux.zip")
sha256sums=('1756c12c94af08a2b7a9d502aa63ab429ed756d47cdd0f1834f92add2f945191')
.....

Unfortunately, there is a small problem. The dialog box opens several times during the installation.
Although the path to the local file has already been selected. Has anyone any idea or suggestions for improvement.

Thank you in advance.

Offline

#2 2017-06-19 16:39:54

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,541

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

My suggestion: Don't do any of that. It has no place at all in a PKGBUILD.

Online

#3 2017-06-19 16:48:05

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,842
Website

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

You are trying to do too much in your PKGBUILD -- a good PKGBUILD should not be interactive at all, it should simply take the files listed in the source array and do whatever is needed to build the package structure under $pkgdir. If the source files cannot be obtained automatically via curl, then the user can be expected to obtain the files themselves and place them in the correct place (by default in the same directory as the PKGBUILD). This can be communicated to the user by way of a comment at the top of the PKGBUILD, or by a custom download agent if you want to be fancy.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#4 2017-06-19 16:55:29

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,521
Website

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

satriani wrote:

After a few users had difficulties installing my package because it needed a local file

I have a much better code snippet to deal with this problem, though it too should not be in the PKGBUILD, you should just run it yourself:

while [[ $few_users == $ignorant_of_aur ]]; do
  curl https://wiki.archlinux.org/index.php/Arch_User_Repository >> $few_users
done

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2017-06-19 17:07:34

progandy
Member
Registered: 2012-05-17
Posts: 5,190

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

If you really want to hold the hands of your users, then you could simply error out with a cleaner error message, e.g.

filename="foo.bar"

if ! get_filepath "local://$filename"; then
  error "Package requires file '$filename' in the same location as the PKGBUILD:"
  msg2 "$startdir"
  [ x"$startdir" = x"$SRCDEST" ] || msg2 "alternative: $SRCDEST"
  exit 1
fi

Last edited by progandy (2017-06-19 17:09:40)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#6 2017-06-19 17:09:44

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,541

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

Simpler would be something like "DLAGENTS+=("local::/usr/bin/echo Unable to find %u, please read the PKGBUILD")

Online

#7 2017-06-19 17:19:54

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

First, you should not do this in a PKGBUILD. As others have pointed out, the PKGBUILD should not be interactive.

For the technical explanation, the problem is that your executable code is at the top level of the PKGBUILD. Everyone time the PKGBUILD is sourced, your code will execute. There is a way to work around this, but you shouldn't. Even with the workaround, instructing users to put a file in $pkgdir will fail to package that file without additional commands.

Possible solutions:

  • If DaVinci_Resolve_${pkgver}_Linux.zip is available online, add it to the sources array. If there are multiple archives, add the most common one, and provide additional commented sources arrays that users can uncomment for the other archives, with a note in the comments.

  • If that file is not available online, add it to the sources array as a local file and instruct users to copy the correct file there via comments in the PKGBUILD.

Where is that file normally located? If it's already available on the system, then including it in your package is redundant. I suspect that this is an XY problem. What are you actually trying to do?


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#8 2017-06-19 18:13:43

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,521
Website

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

Xyne, it's from here:
https://www.blackmagicdesign.com/produc … nciresolve

It is a no-cost download, but you must register through their website in order to access it.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#9 2017-06-19 19:13:08

satriani
Member
Registered: 2015-06-26
Posts: 26

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

Thanks for your very helpful answers. I do not know what to say to that now.
My intention was to improve the usability, of course not at the expense of security wink

Offline

#10 2017-06-24 13:04:30

satriani
Member
Registered: 2015-06-26
Posts: 26

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

OK, I've solved it as follows.

if [ ! -f ${pkgdir}/DaVinci_Resolve_${pkgver}_Linux.zip ]; then
  if [ -f $HOME/Downloads/DaVinci_Resolve_${pkgver}_Linux.zip ]; then
    ln -s $HOME/Downloads/DaVinci_Resolve_${pkgver}_Linux.zip ${pkgdir}
  else
    msg2 "Please remember to put a package archive DaVinci_Resolve_${pkgver}_Linux.zip in to ${pkgdir}"
    sleep 3
  fi
fi

I think this is a good compromise and elegant enough tongue

Offline

#11 2017-06-24 13:40:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,521
Website

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

That sleep does absolutely nothing but serve as an annoyance.  And your message is redundant as makepkg will give a comparable error message if the source file is not found.  Arch users know how to interpret makepkg errors and they'll even be presented in the user's own language (most of the time).

Really, quit trying to reinvent the wheel and making it square.  Just put the file:// as the source.

EDIT: oops - see below.  My comments above would be fitting if you had srcdir everywhere you currently have pkgdir.  linking the file into srcdir, or telling the user to put the file there in msg output is just silly.  Doing this for pkgdir is not silly, it's just completely wrong and will not work at all.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2017-06-24 13:56:03

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,541

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

Not only redundant, but makes no sense; that file should never be in $pkgdir. Stop overcomplicating things.

Online

#13 2017-06-24 20:59:16

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: PKGBUILD - Dialog to selecting the local file does not work as desired

The package should not contain a symlink to a user's home directory either.

Just add the file to the source array as a local source and let the user deal with it.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB