Hey guys,
I just finished an ebuild for Gentoo's portage system with a modification of a super old setup.py script (0.2.7 i think). It accomplishes much of what you guys are looking for as far as installation that is consistent with how other packages install.
sabnzbd-0.4.2.ebuild (I follow rullerz's idea of net-nntp/sabnzbd as the atom name, this is an ebuild file -just a glorified bash script)
Code: Select all
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
inherit distutils
DESCRIPTION="Binary Newsgrabber written in Python, server-oriented using a web-interface.The active successor of the abandoned SABnzbd project."
HOMEPAGE="http://sourceforge.net/projects/sabnzbd/"
SRC_URI="mirror://sourceforge/sabnzbdplus/sabnzbd-${PV}-src.tar.gz"
HOMEDIR="${ROOT}var/lib/${PN}"
DHOMEDIR="var/lib/${PN}"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64"
IUSE="symlink unrar unzip feedparser par yenc"
RDEPEND=">=dev-lang/python-2.4.4
~dev-python/cherrypy-2.2.1
>=dev-python/cheetah-2.0.1
>=dev-python/elementtree-1.2.6
app-text/dos2unix
unrar? ( >=app-arch/unrar-3.6.6 )
unzip? ( >=app-arch/unzip-5.5.2 )
feedparser? ( >=dev-python/feedparser-4.1 )
par? ( >=app-arch/par2cmdline-0.4 )
yenc? ( >=dev-python/yenc-0.3 )"
DEPEND=""
src_unpack() {
unpack "${A}" || die
mv ${WORKDIR}/SABnzbd-${PV}/* "${WORKDIR}/"
einfo "copy setup.py to ${WORKDIR}/setup.py"
cp "${FILESDIR}/${PN}-${PV}-gentoo-setup.py" "${WORKDIR}/setup.py"
}
src_compile() {
distutils_src_compile
}
pkg_preinst() {
#Create group and user
enewgroup "${PN}"
enewuser "${PN}" -1 /bin/false "${HOMEDIR}" "${PN}"
}
src_install() {
distutils_src_install
#Init scripts
newinitd "${FILESDIR}"/"${PN}".init "${PN}"
newconfd "${FILESDIR}"/"${PN}".conf "${PN}"
cd "${D}"
#Config file (permissions for this are really up in the air, should this be sabnzbd owned with mask=600?)
insinto /etc
newins "${FILESDIR}/${PN}-${PV}".ini "${PN}".conf
fowners root:"${PN}" etc/"${PN}".conf
fperms 660 etc/"${PN}".conf
#Create all default dirs
keepdir "${DHOMEDIR}"
fowners "${PN}":"${PN}" "${DHOMEDIR}"
keepdir "${DHOMEDIR}"/download
fowners "${PN}":"${PN}" "${DHOMEDIR}"/download
fperms 775 "${DHOMEDIR}"/download
keepdir "${DHOMEDIR}"/complete
fowners "${PN}":"${PN}" "${DHOMEDIR}"/complete
fperms 775 "${DHOMEDIR}"/complete
keepdir "${DHOMEDIR}"/nzb_backup
fowners "${PN}":"${PN}" "${DHOMEDIR}"/nzb_backup
fperms 775 "${DHOMEDIR}"/nzb_backup
keepdir "${DHOMEDIR}"/cache
fowners "${PN}":"${PN}" "${DHOMEDIR}"/cache
keepdir /var/log/sabnzbd
fowners "${PN}":"${PN}" "${ROOT}"var/log/"${PN}"
keepdir "${DHOMEDIR}"/dirscan
fowners "${PN}":"${PN}" "${DHOMEDIR}"/dirscan
fperms 775 "${DHOMEDIR}"/dirscan
#Add themes
cd "${D}"
mv usr/interfaces usr/share/"${PN}"-"${PV}"/
#cp -R "${WORKDIR}"/interfaces/Plush usr/share/"${PN}"-"${PV}"/Plush
#cp -R "${WORKDIR}"/interfaces/smpl usr/share/"${PN}"-"${PV}"/smpl
#cp -R "${WORKDIR}"/interfaces/iphone usr/share/"${PN}"-"${PV}"/iphone
#Symlink /usr/share/SABnzbd to this version
if use symlink; then
cd "${D}"usr/share/
dosym "${PN}-${PV}" "${PN}"
fi
#fix permission on themes
fowners root:sabnzbd -R usr/share/${PN}-${PV}
}
pkg_postinst() {
einfo "Default directory: ${HOMEDIR}"
einfo "Templates can be found in: ${ROOT}usr/share/${PN}-${PV}"
einfo ""
einfo "Run: gpasswd -a <user> sabnzbd"
einfo "to add an user to the sabnzbd group so it can edit sabnzbd files"
einfo ""
ewarn "Please configure ${ROOT}etc/conf.d/${PN} before starting!"
einfo ""
einfo "Start with ${ROOT}etc/init.d/${PN} start"
}
files/sabnzbd-0.4.2-gentoo-setup.py (used by distutils to install sabnzbd in python)
Code: Select all
#!/usr/bin/env python
Win32ConsoleName = 'SABnzbd-console.exe'
Win32WindowName = 'SABnzbd.exe'
import sabnzbd
from distutils.core import setup
# py2exe usage: python setup.py py2exe
try:
import glob
import sys
import os
import py2exe
except ImportError:
py2exe = None
print sys.argv[0]
if (len(sys.argv) < 2) or sys.argv[1] != 'py2exe':
py2exe = None
options = dict(
name = 'SABnzbd',
version = sabnzbd.__version__,
url = 'http://sourceforge.net/projects/sabnzbdplus',
author = 'The ShyPike & Gregor Kaufmann',
author_email = '[email protected]',
description = 'SABnzbd ' + str(sabnzbd.__version__),
scripts = ['SABnzbd.py'],
packages = ['sabnzbd', 'sabnzbd.utils', 'sabnzbd.utils.multiauth'],
platforms = ['posix'],
license = 'GNU General Public License 2 (GPL2)',
data_files = [
('interfaces/Default/templates', glob.glob("interfaces/Default/templates/*.tmpl")),
('interfaces/Default/templates/static/stylesheets', glob.glob('interfaces/Default/templates/static/stylesheets/*.*')),
('interfaces/Default/templates/static/stylesheets/colorschemes', glob.glob('interfaces/Default/templates/static/stylesheets/colorschemes/*.*')),
('interfaces/Default/templates/static/images', glob.glob('interfaces/Default/templates/static/images/*.ico')),
('interfaces/Default/templates/static/javascript', glob.glob('interfaces/Default/templates/static/javascript/*.js')),
('interfaces/smpl/templates', glob.glob("interfaces/smpl/templates/*.*")),
('interfaces/smpl/templates/static', glob.glob("interfaces/smpl/templates/static/*.*")),
('interfaces/smpl/templates/static/images', glob.glob("interfaces/smpl/templates/static/images/*.*")),
('interfaces/smpl/templates/static/images/nuvola', glob.glob("interfaces/smpl/templates/static/images/nuvola/*.*")),
('interfaces/smpl/templates/static/MochiKit', glob.glob("interfaces/smpl/templates/static/MochiKit/*.*")),
('interfaces/smpl/templates/static/PlotKit', glob.glob("interfaces/smpl/templates/static/PlotKit/*.*")),
('interfaces/smpl/templates/static/excanvas', glob.glob("interfaces/smpl/templates/static/excanvas/*.*")),
('interfaces/smpl/templates/static/stylesheets', glob.glob("interfaces/smpl/templates/static/stylesheets/*.*")),
('interfaces/smpl/templates/static/stylesheets/colorschemes', glob.glob("interfaces/smpl/templates/static/stylesheets/colorschemes*.*")),
('interfaces/Plush/templates', glob.glob("interfaces/Plush/templates/*.*")),
('interfaces/Plush/templates/static', glob.glob("interfaces/Plush/templates/static/*.*")),
('interfaces/Plush/templates/static/images', glob.glob("interfaces/Plush/templates/static/images/*.*")),
('interfaces/Plush/templates/static/images/plush-default', glob.glob("interfaces/Plush/templates/static/images/plush-default/*.*")),
('interfaces/Plush/templates/static/images/plush-default/config', glob.glob("interfaces/Plush/templates/static/images/plush-default/config/*.*")),
('interfaces/Plush/templates/static/images/plush-default/nzo', glob.glob("interfaces/Plush/templates/static/images/plush-default/nzo/*.*")),
('interfaces/Plush/templates/static/javascripts', glob.glob("interfaces/Plush/templates/static/javascripts/*.*")),
('interfaces/Plush/templates/static/stylesheets', glob.glob("interfaces/Plush/templates/static/stylesheets/*.*")),
('interfaces/iphone/templates', glob.glob("interfaces/iphone/templates/*.*")),
('interfaces/iphone/templates/static', glob.glob("interfaces/iphone/templates/static/*.*")),
('interfaces/iphone/templates/static/iui', glob.glob("interfaces/iphone/templates/static/iui/*.*")),
('interfaces/iphone/templates/MochiKit', glob.glob("interfaces/iphone/templates/static/MochiKit/*.*")),
]
)
if py2exe:
program = [ {'script' : 'SABnzbd.py', 'icon_resources' : [(0, "interfaces/Default/templates/static/images/favicon.ico")] } ]
options['options'] = {"py2exe": {"bundle_files": 1, "packages": "xml,cherrypy.filters,Cheetah", "optimize": 2, "compressed": 0}}
# Generate the console-app
options['console'] = program
setup(**options)
try:
if os.path.exists("dist/%s" % Win32ConsoleName):
os.remove("dist/%s" % Win32ConsoleName)
os.rename("dist/%s" % Win32WindowName, "dist/%s" % Win32ConsoleName)
except:
print "Cannot create dist/%s" % Win32ConsoleName
exit(1)
# Make sure that the root files are DOS format
for file in options['data_files'][0][1]:
os.system("unix2dos --safe dist/%s" % file)
os.remove('dist/Sample-PostProc.sh')
# Generate the windowed-app (skip datafiles now)
del options['console']
del options['data_files']
options['windows'] = program
setup(**options)
else:
# Prepare Source distribution package.
# Make sure all source files are Unix format
import shutil
root = 'srcdist'
root = os.path.normpath(os.path.abspath(root))
if not os.path.exists(root):
os.mkdir(root)
# Copy the data files
for set in options['data_files']:
dest, src = set
ndir = root + '/' + dest
ndir = os.path.normpath(os.path.abspath(ndir))
if not os.path.exists(ndir):
os.makedirs(ndir)
for file in src:
shutil.copy2(file, ndir)
front, ext = os.path.splitext(file)
base = os.path.basename(file)
if ext.lower() in ('.py', '.pl', '.txt', '.html', '.css', '.tmpl', ''):
os.system("dos2unix --quiet --safe %s" % ndir + '/' + base)
# Copy the script files
for name in options['scripts']:
file = os.path.normpath(os.path.abspath(name))
shutil.copy2(file, root)
base = os.path.basename(file)
fullname = os.path.normpath(os.path.abspath(root + '/' + base))
os.system("dos2unix --quiet --safe %s" % fullname)
# Copy all content of the packages (but skip backups and pre-compiled stuff)
for unit in options['packages']:
unitpath = unit.replace('.','/')
dest = os.path.normpath(os.path.abspath(root + '/' + unitpath))
if not os.path.exists(dest):
os.makedirs(dest)
for name in glob.glob("%s/*.*" % unitpath):
file = os.path.normpath(os.path.abspath(name))
front, ext = os.path.splitext(file)
base = os.path.basename(file)
fullname = os.path.normpath(os.path.abspath(dest + '/' + base))
if ext.lower() not in ('.pyc', '.pyo', '.bak'):
shutil.copy2(file, dest)
os.system("dos2unix --quiet --safe %s" % fullname)
setup(**options)
/files/sabnzbd-0.4.2-ini (/etc/sabnzbd.conf - this is the default config generated by sabnzbd-0.4.2 with some default directorties set)
Code: Select all
__version__ = 18
[misc]
log_dir = /var/log/sabnzbd
auto_browser = 0
permissions = 0775
check_new_rel = 1
replace_spaces = 0
fail_on_crc = 0
enable_filejoin = 0
enable_unzip = 1
enable_unrar = 1
enable_par_cleanup = 1
par_option = ""
config_lock = 0
safe_postproc = 0
pause_on_post_processing = 0
cleanup_list = ""
ignore_samples = 0
send_group = 0
download_dir = /var/lib/sabnzbd/download
download_free = 0
complete_dir = /var/lib/sabnzbd/complete
script_dir = "/var/lib/sabnzbd/scripts"
nzb_backup_dir = /var/lib/sabnzbd/nzb_backup
cache_dir = /var/lib/sabnzbd/cache
dirscan_dir = /var/lib/sabnzbd/dirscan
dirscan_speed = 5
refresh_rate = 0
rss_rate = 60
bandwith_limit = 0
cache_limit = 0
email_server = ""
email_to = ""
email_from = ""
email_account = ""
email_pwd = ""
email_endjob = 0
email_full = 0
schedlines = ,
dirscan_opts = 3
dirscan_script = ""
top_only = 1
auto_sort = 0
enable_tv_sorting = 0
tv_sort_string = ""
web_color = ""
web_color2 = ""
host = 192.168.200.22
port = 8080
web_dir = /usr/share/sabnzbd-0.4.2/Default
web_dir2 = ""
username = ""
password = ""
[logging]
enable_cherrypy_logging = 1
log_level = 1
max_log_size = 5M
log_backups = 5
[newzbin]
username = ""
password = ""
bookmarks = 0
unbookmark = 0
bookmark_rate = 60
[servers]
[rss]
[categories]
[[unknown]]
newzbin = Unknown
dir = Unknown
[[anime]]
newzbin = Anime
dir = Anime
[[apps]]
newzbin = Apps
dir = Apps
[[books]]
newzbin = Books
dir = Books
[[consoles]]
newzbin = Consoles
dir = Consoles
[[emulation]]
newzbin = Emulation
dir = Emulation
[[games]]
newzbin = Games
dir = Games
[[misc]]
newzbin = Misc
dir = Misc
[[movies]]
newzbin = Movies
dir = Movies
[[music]]
newzbin = Music
dir = Music
[[pda]]
newzbin = PDA
dir = PDA
[[resources]]
newzbin = Resources
dir = Resources
[[tv]]
newzbin = TV
dir = TV
/files/sabnzbd.conf (this goes in /etc/conf.d/sabnzbd)
Code: Select all
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
# /etc/conf.d/sabnzbd
# Config file for sabnzbd init script
# Which user to run sabnzbd as, you should change this.
SAB_USER="sabnzbd"
SAB_GROUP="sabnzbd"
# This overrides the contents of /etc/sabnzbd.conf, needed for wget shutdown to work in init (short of writing some crazy regex for the config)
SAB_HOSTNAME="127.0.0.1"
SAB_PORT="8080"
# Location of config file.
# Make sure the user specified above can read this file. (if you want to change options from the webUI, give it write)
SAB_CONFIGFILE="/etc/sabnzbd.conf"
/files/sabnzbd.init (/etc/init.d/sabnzbd):
Code: Select all
#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
opts="start stop"
depend() {
need net
}
start() {
ebegin "Starting SABnzbd"
if ! check_config ; then
eend 1
return 1
fi
start-stop-daemon --quiet --start -c ${SAB_USER}:${SAB_GROUP} \
--exec /usr/bin/SABnzbd.py -- \
-s ${SAB_HOSTNAME}:${SAB_PORT} -f ${SAB_CONFIGFILE} -d &> /dev/null
eend $?
}
stop() {
ebegin "Stopping SABnzbd"
URL="http://${SAB_HOSTNAME}:${SAB_PORT}/sabnzbd/shutdown"
if [ -x /usr/bin/wget ] ; then
/usr/bin/wget -q --delete-after "${URL}"
elif [ -x /usr/bin/curl ] ; then
/usr/bin/curl --silent "${URL}" > /dev/null 2> /dev/null
else
ewarn "missing wget and curl, ending all processes named SABnzbd.py"
start-stop-daemon --quiet --stop --name SABnzbd.py
fi
eend $?
}
check_config() {
if [ ! -e ${SAB_CONFIGFILE} ] ; then
eerror "ERROR: can't find ${SAB_CONFIGFILE}."
return 1
else
return 0
fi
}
I might take the symlink useflag part out in the future and just make the installer select the most recently installed version by default. SABnzbd isn't gcc or python so it's not as important to have multiple versions at your fingertips...
as always, corretions/suggestions are welcome.
EDIT: bug for sabnzbd ebuilds has these files uploaded there:
http://bugs.gentoo.org/show_bug.cgi?id=132590