You are not logged in.

#1 2015-12-04 07:18:02

Falstaff
Member
Registered: 2008-11-03
Posts: 81

My first PKGBUILD, need some advices.

Here's what I've written this past week:

# Maintainer: Des S <*****@gmail.com>
pkgname=plexpy-git
pkgver=v1.2.7.r0.81b22a8
pkgrel=1
pkgdesc="A Python based monitoring and tracking tool for Plex Media Server."
arch=('i686' 'x86_64')
url="https://github.com/drzoidberg33/plexpy"
license=('GPL')
depends=('python2')
makedepends=('git')
provides=("plexpy")
install=('plexpy-git.install')
source=("$pkgname::git+https://github.com/drzoidberg33/plexpy/#branch=master" 'plexpy.service' 'plexpy-git.install')
md5sums=('SKIP'
         '162b2ec991ff31684f91f1fcc6f0aefc'
         'a21cc197a0b2cdd184f26b9c92de7a97')

pkgver() {
        cd "${srcdir}/${pkgname%-VCS}"
        printf "%s" "$(git describe --long | sed 's/\([^-]*-\)g/r\1/;s/-/./g')"
}

package() {
        cd "${srcdir}/${pkgname%-VCS}"
        install -Dm744 PlexPy.py "${pkgdir}/opt/plexpy/PlexPy.py"
        install -Dm644 pylintrc "${srcdir}/$pkgname/CHANGELOG.md" "${pkgdir}/opt/plexpy/"
	install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

        install -dm744 "${pkgdir}/opt/plexpy/data" "${pkgdir}/opt/plexpy/lib" "${pkgdir}/opt/plexpy/plexpy"
        cp -r "data/" "${pkgdir}/opt/plexpy/"
        cp -r "lib/" "${pkgdir}/opt/plexpy/"
        cp -r "plexpy/" "${pkgdir}/opt/plexpy/"

        chmod -R 744 "${pkgdir}/opt/plexpy/data/" "${pkgdir}/opt/plexpy/lib/" "${pkgdir}/opt/plexpy/plexpy/"

        cd ${srcdir}
        install -Dm644 plexpy.service "${pkgdir}/usr/lib/systemd/system/plexpy.service"
}

I studied the multiple Wiki pages related to creating packages and also based myself on PKGBUILD, .install, etc. files from already availaible packages.
There's also plexpy-git.install and plexpy.service files but I'm confident that they're written properly.

I'm mostly not certain about the permissions. Also I'm not aware of another way to add folders into the $pkgdir than using the "cp -r" command.

Please let me know if I need to correct anything else.

Last edited by Falstaff (2015-12-04 07:23:12)

Offline

#2 2015-12-04 08:19:03

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

Re: My first PKGBUILD, need some advices.

The master branch is default. No reason to specify it in the source entry.

You usually want to remove the leading "v" from the pkgver.

No need to use printf in the pkgver function.

What's with all of the 744 permissions? That's most likely going to cause problems. Either 755 or 644 are more common.

All of those "cp" commands could be combined. I would generally use cp -a instead of cp -r. The install command just before them doesn't really do anything.

On the last two lines, why cd then install instead of just installing with an absolute path? You also forgot quotes on the cd.

Offline

#3 2015-12-04 08:37:47

Falstaff
Member
Registered: 2008-11-03
Posts: 81

Re: My first PKGBUILD, need some advices.

Thanks Scimmia for the tips. Here's an update:

# Maintainer: Des S <*****@gmail.com>
pkgname=plexpy-git
pkgver=1.2.7.r0.81b22a8
pkgrel=1
pkgdesc="A Python based monitoring and tracking tool for Plex Media Server."
arch=('i686' 'x86_64')
url="https://github.com/drzoidberg33/plexpy"
license=('GPL')
depends=('python2')
makedepends=('git')
provides=("plexpy")
install=('plexpy-git.install')
source=("$pkgname::git+https://github.com/drzoidberg33/plexpy/" 'plexpy.service' 'plexpy-git.install')
md5sums=('SKIP'
         '6d8479cdb77fadc38d93b6d7a3026864'
         'a21cc197a0b2cdd184f26b9c92de7a97')

pkgver() {
        cd "${srcdir}/${pkgname%-VCS}"
        git describe --long | sed -e 's/\([^-]*-\)g/r\1/;s/-/./g' -e 's/^v//'
}

package() {
        cd "${srcdir}/${pkgname%-VCS}"
        install -Dm755 PlexPy.py "${pkgdir}/opt/plexpy/PlexPy.py"
        install -Dm644 pylintrc "${srcdir}/$pkgname/CHANGELOG.md" "${pkgdir}/opt/plexpy/"
	install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

        cp -a "data/" "${pkgdir}/opt/plexpy/"
        cp -a "lib/" "${pkgdir}/opt/plexpy/"
        cp -a "plexpy/" "${pkgdir}/opt/plexpy/"

        chmod -R 755 "${pkgdir}/opt/plexpy/data/" "${pkgdir}/opt/plexpy/lib/" "${pkgdir}/opt/plexpy/plexpy/"

        install -Dm644 ${srcdir}/plexpy.service "${pkgdir}/usr/lib/systemd/system/plexpy.service"
}
Scimmia wrote:

The master branch is default. No reason to specify it in the source entry.

You usually want to remove the leading "v" from the pkgver.

No need to use printf in the pkgver function.

What's with all of the 744 permissions? That's most likely going to cause problems. Either 755 or 644 are more common.

All of those "cp" commands could be combined. I would generally use cp -a instead of cp -r. The install command just before them doesn't really do anything.

On the last two lines, why cd then install instead of just installing with an absolute path? You also forgot quotes on the cd.

- So anybody can execute the main script? Thought it only should be the "plexpy:plexpy" user and group that could only be allowed to do so.

- Not sure what you mean to combining them.

Last edited by Falstaff (2015-12-04 08:41:38)

Offline

#4 2015-12-04 16:04:39

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

Re: My first PKGBUILD, need some advices.

It would be unusual for only plexpy:plexpy to be able to execute the script, but if that's what you want, you could do it. You'd need to pick a UID and  GID then chown it to that user.

As for combining the cp commands, I mean something like

cp -a data/ lib/ plexpy/ "${pkgdir}/opt/plexpy/"

Offline

#5 2015-12-04 16:24:35

Falstaff
Member
Registered: 2008-11-03
Posts: 81

Re: My first PKGBUILD, need some advices.

Scimmia wrote:

It would be unusual for only plexpy:plexpy to be able to execute the script, but if that's what you want, you could do it. You'd need to pick a UID and  GID then chown it to that user.

As for combining the cp commands, I mean something like

cp -a data/ lib/ plexpy/ "${pkgdir}/opt/plexpy/"

- I'll just follow the norm for the permissions

- ... d'uh, this should have been obvious to me!

Latest update:

pkgname=plexpy-git
pkgver=1.2.7.r0.81b22a8
pkgrel=1
pkgdesc="A Python based monitoring and tracking tool for Plex Media Server."
arch=('i686' 'x86_64')
url="https://github.com/drzoidberg33/plexpy"
license=('GPL')
depends=('python2')
makedepends=('git')
provides=("plexpy")
install=('plexpy-git.install')
source=("$pkgname::git+https://github.com/drzoidberg33/plexpy/" 'plexpy.service' 'plexpy-git.install')
md5sums=('SKIP'
         '6d8479cdb77fadc38d93b6d7a3026864'
         'a21cc197a0b2cdd184f26b9c92de7a97')

pkgver() {
        cd "${srcdir}/${pkgname%-VCS}"
        git describe --long | sed -e 's/\([^-]*-\)g/r\1/;s/-/./g' -e 's/^v//'
}

package() {
        cd "${srcdir}/${pkgname%-VCS}"
        install -Dm755 PlexPy.py "${pkgdir}/opt/plexpy/PlexPy.py"
        install -Dm644 pylintrc "${srcdir}/$pkgname/CHANGELOG.md" "${pkgdir}/opt/plexpy/"
	install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

        cp -a data/ lib/ plexpy/ "${pkgdir}/opt/plexpy/"

        chmod -R 755 "${pkgdir}/opt/plexpy/data/" "${pkgdir}/opt/plexpy/lib/" "${pkgdir}/opt/plexpy/plexpy/"

        install -Dm644 ${srcdir}/plexpy.service "${pkgdir}/usr/lib/systemd/system/plexpy.service"
}

I think I'm good smile

Thanks again Scimmia!

Offline

#6 2015-12-04 16:43:34

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

Re: My first PKGBUILD, need some advices.

Taking a last look:

arch=('i686' 'x86_64') seems wrong. Is there anything architecture specific?

Do you really want every single file in ${pkgdir}/opt/plexpy/{data,lib,plexpy}/ to be executable?

You're missing quotes when installing the service file. Becomes a problem if $srcdir contains spaces.

Offline

#7 2015-12-04 23:30:39

Falstaff
Member
Registered: 2008-11-03
Posts: 81

Re: My first PKGBUILD, need some advices.

Scimmia wrote:

Taking a last look:

arch=('i686' 'x86_64') seems wrong. Is there anything architecture specific?

Do you really want every single file in ${pkgdir}/opt/plexpy/{data,lib,plexpy}/ to be executable?

You're missing quotes when installing the service file. Becomes a problem if $srcdir contains spaces.

- Wasn't sure which arch to put so I went with the safe bet. But if its written in Python, it should work on every architecture... Will fix.

- Yeah, I only PleyPy.py in the main directory needs to be executed. In my mind, I was thinking that any *.py == needs to be executable.

pkgname=plexpy-git
pkgver=1.2.7.r0.81b22a8
pkgrel=1
pkgdesc="A Python based monitoring and tracking tool for Plex Media Server."
arch=('any')
url="https://github.com/drzoidberg33/plexpy"
license=('GPL')
depends=('python2')
makedepends=('git')
provides=("plexpy")
install=('plexpy-git.install')
source=("$pkgname::git+https://github.com/drzoidberg33/plexpy/" 'plexpy.service' 'plexpy-git.install')
md5sums=('SKIP'
         '6d8479cdb77fadc38d93b6d7a3026864'
         'a21cc197a0b2cdd184f26b9c92de7a97')

pkgver() {
        cd "${srcdir}/${pkgname%-VCS}"
        git describe --long | sed -e 's/\([^-]*-\)g/r\1/;s/-/./g' -e 's/^v//'
}

package() {
        cd "${srcdir}/${pkgname%-VCS}"
        install -Dm755 PlexPy.py "${pkgdir}/opt/plexpy/PlexPy.py"
        install -Dm644 pylintrc "${srcdir}/$pkgname/CHANGELOG.md" "${pkgdir}/opt/plexpy/"
	install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
	install -Dm644 CHANGELOG.md "${pkgdir}/opt/plexpy/"

        cp -a data/ lib/ plexpy/ "${pkgdir}/opt/plexpy/"

        install -Dm644 "${srcdir}/plexpy.service" "${pkgdir}/usr/lib/systemd/system/plexpy.service"
}

While I'm at it, here's my plexpy-git.install and plex.service files.

post_install(){
	getent group plexpy &>/dev/null || groupadd -r plexpy >/dev/null
	getent passwd plexpy &>/dev/null || useradd -r -g plexpy -s /bin/false plexpy >/dev/null
	chown plexpy:plexpy -R /opt/plexpy
	true
}

post_remove(){
	getent passwd plexpy &>/dev/null && userdel plexpy >/dev/null
	getent group plexpy &>/dev/null && groupdel plexpy >/dev/null
	true
}
[Unit]
Description=PlexPy Service

[Service]
ExecStart=/usr/bin/python2 /opt/plexpy/PlexPy.py --quiet --daemon --nolaunch --config /opt/plexpy/config.ini --datadir /opt/plexpy --nolaunch
User=plexpy
Group=plexpy
GuessMainPID=no
Type=forking

[Install]
WantedBy=default.target

Last edited by Falstaff (2015-12-04 23:32:28)

Offline

#8 2015-12-04 23:40:55

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

Re: My first PKGBUILD, need some advices.

OK, the install scriptlet. chowning the entire dir is bad. If you need to chown it, you need to do it in the PKGBUILD, which requires a static UID and GID.

What does "true" get you? It's a null command.

You should not remove the user and group. It becomes a security problem if files are left over owned by that user.

Offline

#9 2015-12-04 23:59:58

Falstaff
Member
Registered: 2008-11-03
Posts: 81

Re: My first PKGBUILD, need some advices.

Scimmia wrote:

OK, the install scriptlet. chowning the entire dir is bad. If you need to chown it, you need to do it in the PKGBUILD, which requires a static UID and GID.

What does "true" get you? It's a null command.

You should not remove the user and group. It becomes a security problem if files are left over owned by that user.

- Then what plexpy:plexpy needs to own, the main script and that's it? Or should I leave it to root?
Basically, plexpy is simply used to limit the process' permission in the system and also filesystem permissions, am I correct?

- Does only the /opt/plexpy folder needs to be chowned by plexpy and that's it?
"chown plexpy:plexpy /opt/pleypy"?

Last edited by Falstaff (2015-12-05 00:00:30)

Offline

#10 2015-12-05 00:10:42

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

Re: My first PKGBUILD, need some advices.

It will need to own anything it needs to write to at runtime. Since I know nothing about plexpy, I have no idea what that would be. I wouldn't chown anything and see what happens.

Offline

#11 2015-12-05 00:21:30

Falstaff
Member
Registered: 2008-11-03
Posts: 81

Re: My first PKGBUILD, need some advices.

Got this when trying to start plexpy through systemctl without chown:

● plexpy.service - PlexPy Service
   Loaded: loaded (/usr/lib/systemd/system/plexpy.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since ven 2015-12-04 18:56:29 EST; 23min ago
  Process: 6114 ExecStart=/usr/bin/python2 /opt/plexpy/PlexPy.py --quiet --daemon --nolaunch --config /opt/plexpy/config.ini --datadir /opt/plexpy --nolaunch (code=exited, status=1/FAILURE)

déc 04 18:56:26 server systemd[1]: Starting PlexPy Service...
[b]déc 04 18:56:29 server python2[6114]: Cannot write to the data directory: /opt/plexpy. Exiting...[/b]
déc 04 18:56:29 server systemd[1]: plexpy.service: Control process exited, code=exited status=1
déc 04 18:56:29 server systemd[1]: Failed to start PlexPy Service.
déc 04 18:56:29 server systemd[1]: plexpy.service: Unit entered failed state.
déc 04 18:56:29 server systemd[1]: plexpy.service: Failed with result 'exit-code'.

Folder perms.

drwxr-xr-x 7 couchpotato couchpotato 4,0K 26 jan  2015 couchpotato
drwxr-xr-x 3 root        root        4,0K 17 nov 11:32 plexmediaserver
drwxr-xr-x 5 root        root        4,0K  4 déc 18:53 plexpy
drwxr-xr-x 9 sickrage    sickrage    4,0K  7 oct 22:54 sickrage

Last edited by Falstaff (2015-12-05 00:25:09)

Offline

#12 2015-12-05 00:30:42

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

Re: My first PKGBUILD, need some advices.

What does "datadir" mean? Is that were it looks for it's resources or where it stores it's runtime data? Or both?

Offline

#13 2015-12-05 00:32:48

Falstaff
Member
Registered: 2008-11-03
Posts: 81

Re: My first PKGBUILD, need some advices.

Scimmia wrote:

What does "datadir" mean? Is that were it looks for it's resources or where it stores it's runtime data? Or both?

Where it stores it data, for example the config.ini file.

Oh, maybe this should another folder, like "/var/lib/plexpy"?

Offline

#14 2015-12-05 00:36:54

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

Re: My first PKGBUILD, need some advices.

That's where I would put it. You still run into permission issues, though, unless you get systemd to make it.

Offline

#15 2015-12-05 00:46:04

Falstaff
Member
Registered: 2008-11-03
Posts: 81

Re: My first PKGBUILD, need some advices.

Scimmia wrote:

That's where I would put it. You still run into permission issues, though, unless you get systemd to make it.

I suppose you're talking about the ExecStartPre option?

Found an example on a website:

[Service]
Type=forking
PrivateTmp=yes
User=nobody
Group=nobody
# Run ExecStartPre with root-permissions
PermissionsStartOnly=true
ExecStartPre=-/usr/bin/mkdir /var/run/dhis
ExecStartPre=/usr/bin/chown -R nobody:nobody /var/run/dhis/
# Run ExecStart with User=nobody / Group=nobody
ExecStart=/usr/sbin/dhid -P /var/run/dhis/dhid.pid
PIDFile=/var/run/dhis/dhid.pid

https://blog.hqcodeshop.fi/archives/93- … stemd.html

Last edited by Falstaff (2015-12-05 00:46:58)

Offline

#16 2015-12-05 00:50:17

Falstaff
Member
Registered: 2008-11-03
Posts: 81

Re: My first PKGBUILD, need some advices.

Can you point me to an .service file that does this?

Edit: Nevermind, did it myself like a big boy.

[Unit]
Description=PlexPy Service

[Service]
User=plexpy
Group=plexpy
GuessMainPID=no
Type=forking

PermissionsStartOnly=true
ExecStartPre=-/usr/bin/mkdir /var/lib/plexpy
ExecStartPre=/usr/bin/chown -R plexpy:plexpy /var/lib/plexpy/
ExecStart=/usr/bin/python2 /opt/plexpy/PlexPy.py --quiet --daemon --nolaunch --config /var/lib/plexpy/config.ini --datadir /var/lib/plexpy --nolaunch

[Install]
WantedBy=default.target

And it's working properly:

ll /opt/plexpy/

drwxr-xr-x  3 root root 4,0K  4 déc 03:30 data
drwxr-xr-x 25 root root 4,0K  4 déc 03:30 lib
drwxr-xr-x  2 root root 4,0K  4 déc 03:30 plexpy
-rwxr-xr-x  1 root root 7,6K  4 déc 21:06 PlexPy.py
-rw-r--r--  1 root root 9,1K  4 déc 21:06 pylintrc
ll /var/lib/plexpy

drwxr-xr-x 2 plexpy plexpy 4,0K  4 déc 21:07 cache
drwxr-xr-x 2 plexpy plexpy 4,0K  4 déc 21:07 logs
-rw-r--r-- 1 plexpy plexpy 8,7K  4 déc 21:06 CHANGELOG.md
-rw-r--r-- 1 plexpy plexpy 7,0K  4 déc 21:15 config.ini
-rw-r--r-- 1 plexpy plexpy  61K  4 déc 21:24 plexpy.db

Last edited by Falstaff (2015-12-05 02:39:15)

Offline

#17 2015-12-05 20:03:07

Falstaff
Member
Registered: 2008-11-03
Posts: 81

Re: My first PKGBUILD, need some advices.

OK, did more modifications including the creation a patch to disable the embedded automatic Git Update functionality in this app.

Here's the initial AUR: https://aur.archlinux.org/packages/plexpy-git/

Thanks again for your help Scimmia!

Offline

Board footer

Powered by FluxBB