You are not logged in.

#1 2011-07-31 13:58:17

bladesuk1
Member
Registered: 2011-02-01
Posts: 10

New package for review: Headphones

hi all,

i've just found this project, and found it useful/interesting, so decided to put together a package as i couldn't find one already for it.  given that it's the first time i've attempted to do this (and given that this course of action was suggested in the wiki) i thought it probably best to submit the PKGBUILD (and other files) here first for review before submitting it officially as i'm bound to have missed something along the way smile

i've based the files on those for sickbeard, so i doubt that i'll be a million miles away, but please feel free to point out where i've gone wrong so i can sort it out and get this package submitted.

thanks in advance,

b

edit: added bbcode tags as requested.

PKGBUILD:

# Maintainer: blades <blades at gecko dot org dot uk>

pkgname=headphones-git
pkgver=20110731
pkgrel=1
pkgdesc="Headphones is an automated NZB downloader, similar to Sick Beard and CouchPotato, but for music!"
arch=('i686' 'x86_64')
url="http://github.com/rembo10/headphones"
license=('GPL3')
depends=('python2')
makedepends=('git')
install='headphones.install'
source=('headphones' 'headphones.init')
md5sums=('87371d36fa0f02e32b313931b8c15f8c'
         'bb8b4fd5fbf1fed6ff1de7a72b34b811')

_gitroot="git://github.com/rembo10/headphones.git"
_gitname="headphonespvr"

build() {
  cd "$srcdir"
  msg "Connecting to GIT server...."

  if [ -d $_gitname ]; then
     cd $_gitname && git pull origin
     msg "The local files are updated."
  else
     git clone $_gitroot $_gitname
  fi

  msg "GIT checkout done or server timeout"
  msg "Starting install..."

  mkdir -p "${pkgdir}/opt/"
  cp -r "$srcdir/$_gitname" "${pkgdir}/opt/headphones"

  install -D -m755 "${srcdir}/headphones" "${pkgdir}/usr/bin/headphones"
  install -D -m755 "${srcdir}/headphones.init" "${pkgdir}/etc/rc.d/headphones"
}

headphones:

#!/bin/sh

python2 /opt/headphones/Headphones.py "$@"

headphones.init

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
  start)
    stat_busy "Starting Headphones"
    
    if [ -f /var/run/daemons/headphones ]; then
        echo -n "Headphones is already running as a daemon!"
        stat_fail 
    else
        su - headphones -c "python2 /opt/headphones/Headphones.py -q &> /dev/null &" -s /bin/sh
        if [ $? -gt 0 ]; then
            stat_fail
        else
            add_daemon headphones
            stat_done
        fi
    fi
    ;;
  stop)
    stat_busy "Stopping Headphones"
    
    curl -f http://localhost:8181/shutdown/ &> /dev/null

    if [ $? -gt 0 ]; then
              stat_fail
    else
        rm_daemon headphones
              stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
esac
exit 0

headphones.install

## arg 1:  the new package version
post_install() {
  groupadd headphones &> /dev/null
  useradd -g headphones -d /opt/headphones -s /bin/false headphones &> /dev/null
  chown -R headphones:headphones /opt/headphones
  echo "  >> If you change Headphones's port in the general configuration page, you will need to edit /etc/rc.d/headphones to have it point to the new port number"
  sed -i 's/python/python2/g' "${pkgdir}/opt/headphones/Headphones.py"
}
## arg 1:  the new package version
## arg 2:  the old package version
post_upgrade() {
  chown -R headphones:headphones /opt/headphones
  sed -i 's/python/python2/g' "${pkgdir}/opt/headphones/Headphones.py"
}
## arg 1:  the old package version
pre_remove() {
  userdel headphones &> /dev/null
  groupdel headphones &> /dev/null
}

Last edited by bladesuk1 (2011-07-31 14:48:25)

Offline

#2 2011-07-31 14:27:23

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: New package for review: Headphones

code tags are nice for this sort of thing...

One thing to definitely point out: don't ever modify files from the install script. This should be done in the build function of the PKGBUILD.

Offline

#3 2011-07-31 14:38:07

bladesuk1
Member
Registered: 2011-02-01
Posts: 10

Re: New package for review: Headphones

falconindy wrote:

code tags are nice for this sort of thing....

i'm not sure what you mean by that...  something to do with comments in the files?

falconindy wrote:

One thing to definitely point out: don't ever modify files from the install script. This should be done in the build function of the PKGBUILD.

is this in reference to the 'sed' command in the .install file that ?  if so, whereabouts should this go - after the 'cp -r' to put the files into the appropriate directory?

thanks,

b

Offline

#4 2011-07-31 14:40:27

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: New package for review: Headphones

Please use [ code ] tags when pasting code in the forums https://bbs.archlinux.org/help.php#bbcode

like this

That's what falconindy meant.

Offline

#5 2011-07-31 14:50:18

bladesuk1
Member
Registered: 2011-02-01
Posts: 10

Re: New package for review: Headphones

thanks, karol!  admittedly, i feel like a dumbass for missing that and doubly so for not understanding, but at least it's a quick one for me to correct.

Offline

#6 2011-07-31 15:13:58

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: New package for review: Headphones

bladesuk1 wrote:
falconindy wrote:

One thing to definitely point out: don't ever modify files from the install script. This should be done in the build function of the PKGBUILD.

is this in reference to the 'sed' command in the .install file that ?  if so, whereabouts should this go - after the 'cp -r' to put the files into the appropriate directory?

thanks,

b

Put the sed and chown commands at the end of the build() function in the PKGBUILD.

EDIT: beware to not  just copy and paste them because the paths should be relative to ${pkgdir} when inside the PKGBUILD.

Last edited by Ramses de Norre (2011-07-31 15:15:07)

Offline

#7 2011-07-31 15:38:00

bladesuk1
Member
Registered: 2011-02-01
Posts: 10

Re: New package for review: Headphones

Ramses de Norre wrote:

Put the sed and chown commands at the end of the build() function in the PKGBUILD.
EDIT: beware to not  just copy and paste them because the paths should be relative to ${pkgdir} when inside the PKGBUILD.

does that mean i should also change the post_install() method to a pre_install for creating the user/group, and if so will this be fired before the build() method in the PKGBUILD?  wouldn't it cause an issue during the build if the user/group doesn't exist?

Offline

#8 2011-07-31 16:01:17

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: New package for review: Headphones

Right. You can't even reference $pkgdir in an install scriptlet as its meaningless in that context. I'd also split up the build function into a package function...

build() {
  cd "$srcdir"
  msg "Connecting to GIT server...."

  if [ -d $_gitname ]; then
     cd $_gitname && git pull origin
     msg "The local files are updated."
  else
     git clone $_gitroot $_gitname
  fi

  msg "GIT checkout done or server timeout"
}

package() {
  mkdir -p "${pkgdir}/opt/"
  cp -r "$srcdir/$_gitname" "${pkgdir}/opt/headphones"

  install -D -m755 "${srcdir}/headphones" "${pkgdir}/usr/bin/headphones"
  install -D -m755 "${srcdir}/headphones.init" "${pkgdir}/etc/rc.d/headphones"
  sed -i 's/python/python2/g' "${pkgdir}/opt/headphones/Headphones.py"
}

Offline

#9 2011-08-01 10:37:13

bladesuk1
Member
Registered: 2011-02-01
Posts: 10

Re: New package for review: Headphones

thanks to all of the suggestions and corrections from everybody so far.  i've made the following changes to this build a a result of these changes:

PKGBUILD

# Maintainer: blades <blades at gecko dot org dot uk>

pkgname=headphones-git
pkgver=20110731
pkgrel=1
pkgdesc="Headphones is an automated NZB downloader, similar to Sick Beard and CouchPotato, but for music!"
arch=('i686' 'x86_64')
url="http://github.com/rembo10/headphones"
license=('GPL3')
depends=('python2')
makedepends=('git')
install='headphones.install'
source=('headphones' 'headphones.init')
md5sums=('87371d36fa0f02e32b313931b8c15f8c'
         'bb8b4fd5fbf1fed6ff1de7a72b34b811')

_gitroot="git://github.com/rembo10/headphones.git"
_gitname="headphonespvr"

build() {
  cd "$srcdir"
  msg "Connecting to GIT server...."

  if [ -d $_gitname ]; then
     cd $_gitname && git pull origin
     msg "The local files are updated."
  else
     git clone $_gitroot $_gitname
  fi

  msg "GIT checkout done or server timeout"
}

package() {
  mkdir -p "${pkgdir}/opt/"
  cp -r "$srcdir/$_gitname" "${pkgdir}/opt/headphones"

  install -D -m755 "${srcdir}/headphones" "${pkgdir}/usr/bin/headphones"
  install -D -m755 "${srcdir}/headphones.init" "${pkgdir}/etc/rc.d/headphones"
  sed -i 's/python/python2/g' "${pkgdir}/opt/headphones/Headphones.py"
}

headphones.install

## arg 1:  the new package version
post_install() {
  groupadd headphones &> /dev/null
  useradd -g headphones -d /opt/headphones -s /bin/false headphones &> /dev/null
  chown -R headphones:headphones /opt/headphones
  echo "  >> If you change Headphones's port in the general configuration page, you will need to edit /etc/rc.d/headphones to ha$
}
## arg 1:  the new package version
## arg 2:  the old package version
post_upgrade() {
  chown -R headphones:headphones /opt/headphones
}
## arg 1:  the old package version
pre_remove() {
  userdel headphones &> /dev/null
  groupdel headphones &> /dev/null
}

i'll monitor the thread for a while longer to make sure that there are no other additions/changes/suggestions, and then i'll submit it.  thanks to all for the comments so far.

Offline

Board footer

Powered by FluxBB