Tftpd

Материал из pNp Wiki
Перейти к: навигация, поиск

Необходимость

Иногда, требуется некое программное обеспечение, отсуствующее в репозитории, либо собранное не так, как требуется в данном, конкретном, случае. Исходя из этого, для поддержания системы в работоспособном состоянии и простоты сопровождения, ВСЕГДА небходимо собирать пакет

Specfile

%define tftp tftpd

Summary: The client for the Trivial File Transfer Protocol (TFTP)
Name: tftp
Version: 5.2
Release: 7%{?dist}
License: BSD
Group: Applications/Internet
URL: http://www.kernel.org/pub/software/network/tftp/
Source0: http://www.kernel.org/pub/software/network/tftp/tftp-hpa/tftp-hpa-%{version}.tar.bz2
Source1: tftpd.sh
Source2: tftpd

Patch0: tftp-0.40-remap.patch
Patch2: tftp-hpa-0.39-tzfix.patch
Patch3: tftp-0.42-tftpboot.patch
Patch4: tftp-0.49-chk_retcodes.patch
Patch5: tftp-hpa-0.49-fortify-strcpy-crash.patch
Patch6: tftp-0.49-cmd_arg.patch
Patch7: tftp-hpa-0.49-stats.patch
Patch8: tftp-hpa-5.2-pktinfo.patch 

BuildRequires: tcp_wrappers-devel readline-devel autoconf

%description
The Trivial File Transfer Protocol (TFTP) is normally used only for
booting diskless workstations.  The tftp package provides the user
interface for TFTP, which allows users to transfer files to and from a
remote machine.  This program and TFTP provide very little security,
and should not be enabled unless it is expressly needed. 

%package server
Group: System Environment/Daemons
Summary: The server for the Trivial File Transfer Protocol (TFTP)
Requires(post): chkconfig
Requires(preun): chkconfig
# This is for /sbin/service
Requires(preun): initscripts
Requires(postun): initscripts

%description server
The Trivial File Transfer Protocol (TFTP) is normally used only for
booting diskless workstations.  The tftp-server package provides the
server for TFTP, which allows users to transfer files to and from a
remote machine. TFTP provides very little security, and should not be
enabled unless it is expressly needed. 

%prep
%setup -q -n tftp-hpa-%{version}
%patch0 -p1 -b .zero
%patch2 -p1 -b .tzfix
%patch3 -p1 -b .tftpboot
%patch4 -p1 -b .chk_retcodes
%patch5 -p1 -b .fortify-strcpy-crash
%patch6 -p1 -b .cmd_arg
%patch7 -p1 -b .stats
%patch8 -p1 -b .pktinfo

%build
autoreconf -fisv
%configure
make %{?_smp_mflags}

%install
rm -rf ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}%{_bindir}
mkdir -p ${RPM_BUILD_ROOT}%{_mandir}/man{1,8}
mkdir -p ${RPM_BUILD_ROOT}%{_sbindir}
mkdir -p ${RPM_BUILD_ROOT}%{_initrddir}
mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/
mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/lib/tftpboot

make INSTALLROOT=${RPM_BUILD_ROOT} SBINDIR=%{_sbindir} MANDIR=%{_mandir} INSTALL='install -p' install

install -p -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_initrddir}/tftpd
mv ${RPM_BUILD_ROOT}%{_sbindir}/in.tftpd ${RPM_BUILD_ROOT}%{_sbindir}/tftpd
install -p -m 755 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/tftpd

%post server
# This adds the proper /etc/rc*.d links for the script
/sbin/chkconfig --add %{tftp}

%preun server
if [ $1 -eq 0 ] ; then
    /sbin/service %{tftp} stop >/dev/null 2>&1
    /sbin/chkconfig --del %{tftp}
fi

%postun server
if [ "$1" -ge "1" ] ; then
    /sbin/service %{tftp} condrestart >/dev/null 2>&1 || :
fi

%clean
rm -rf ${RPM_BUILD_ROOT} 

%files
%doc README README.security CHANGES
%{_bindir}/tftp
%{_mandir}/man1/*

%files server
%doc README README.security CHANGES
%config(noreplace) %{_sysconfdir}/sysconfig/tftpd
%{_sbindir}/tftpd
%{_mandir}/man8/*
%attr(700,nobody,nobody) %dir %{_localstatedir}/lib/tftpboot
%{_initrddir}/tftpd 

%changelog
* Mon Feb 18 2013 Andrew Vedischev <andrey.vidischev@orange.com> - 5.2-7
- repacked for RHEL 6.X, or CentOS 6.X
- startup script added
- removed xinet from buildreq


Startup script

#!/bin/sh
#
# tftpd        Startup script for tftp
#
# chkconfig:   2345 50 60
# description: Starts, stops tftp server daemon
# 

### BEGIN INIT INFO
# Provides: tftpd
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: IPv4 Trivial File Transfer Protocol server
# Description: tftpd is a server for the Trivial File Transfer Protocol. \
#              The TFTP protocol is extensively used to support remote booting \
#              of diskless devices. The server is normally started by inetd, \
#              but can also run standalone.
#
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

exec="/usr/sbin/tftpd"
prog="tftpd"
pidfile="/var/run/tftpd"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog 

start() {
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6
    echo -n $"Starting $prog: "
    # if not running, start it up here, usually something like "daemon $exec"
    daemon --pidfile="$pidfile" $exec -l -P "$pidfile" $TFTPD_OPTIONS
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    # stop it here, often "killproc $prog"
    killproc -p "$pidfile" $exec
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
} 

force_reload() {
    restart
} 

rh_status() {
    # run checks to determine if the service is running or use generic status
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}


case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?


Links

Основы сборки и шаблоны для спеков и стартовых скриптов

Шаблоны стартовых скриптов

RPM Guide

Git репозиторий пакетов Fedora

Один из источников SRPM'ов