#!/bin/bash set -e # create group tcos if ! getent group tcos >/dev/null; then addgroup --quiet --system tcos || true fi # make sure that tcos.conf is not all readable chmod -f 644 /etc/tcos/tcos.conf chown -f root:tcos /etc/tcos/tcos.conf chmod -f 775 /var/lib/tcos/tftp/pxelinux.cfg chown -f -R root:tcos /var/lib/tcos/tftp/pxelinux.cfg chmod -f -R 664 /var/lib/tcos/tftp/pxelinux.cfg/* 2>/dev/null || true chown -f -R root:tcos /etc/tcos/secrets chmod -f 755 /etc/tcos/secrets chmod -f -R 640 /etc/tcos/secrets/* 2>/dev/null || true if [ -d /etc/tcos/templates ];then chown -f -R root:tcos /etc/tcos/templates chmod -f 775 /etc/tcos/templates chmod -f -R 640 /etc/tcos/templates/tcos* 2>/dev/null || true fi # set SUID in tcos-net-controller (iptables wrapper) if [ -e /usr/lib/tcos/tnc ];then chown -f root:tcos /usr/lib/tcos/tnc chmod -f 4750 /usr/lib/tcos/tnc fi # create file [ ! -e /etc/tcos/modules ] && touch /etc/tcos/modules # FIXME, now tftp is /srv/tftp TFTPBOOT_DEFAULT=/var/lib/tftpboot TFTPBOOT= function read_inetd() { # read tftpboot dir from inetd.conf if [ -f /etc/inetd.conf ]; then # get last word of tftp file tmp=$(grep ^tftp /etc/inetd.conf 2>/dev/null | awk '{print $NF}') if [ -d "${tmp}" ]; then TFTPBOOT=${tmp} fi fi } function read_dnsmasq() { # read tftp-root var from /etc/dnsmasq.conf if [ -f /etc/dnsmasq.conf ]; then tmp=$(grep ^tftp-root /etc/dnsmasq.conf 2>/dev/null | awk -F'=' '{print $2}') if [ -d "${tmp}" ]; then TFTPBOOT=${tmp} fi fi } function read_from_conf() { #$1 is conf file if [ -f "$1" ]; then for txt in $(grep OPTIONS "$1" ); do if [ $(echo $txt |grep -c "/" ) = 1 ]; then TFTPBOOT=$(echo $txt| sed s/"\""/""/g) fi done fi } # # First we try to read from dnsmasq, second inetd and third conf file # read_dnsmasq if [ -z "$TFTPBOOT" ]; then # read from inetd read_inetd fi if [ -z "$TFTPBOOT" ]; then # try with conf files read_from_conf "/etc/default/atftpd" fi if [ -z "${TFTPBOOT}" ]; then TFTPBOOT=$TFTPBOOT_DEFAULT echo " * Using $TFTPBOOT_DEFAULT dir as TFTP root dir" fi if [ ! -d ${TFTPBOOT} ]; then # create dir mkdir -p "${TFTPBOOT}" echo " * Created $TFTPBOOT dir as TFTP root dir" fi if [ ! -L ${TFTPBOOT}/tcos ]; then rm -rf ${TFTPBOOT}/tcos fi # make symlink if [ ! -e ${TFTPBOOT}/tcos ]; then ln -s /var/lib/tcos/tftp ${TFTPBOOT}/tcos fi [ ! -e /var/lib/tcos/tftp/conf ] && mkdir -p /var/lib/tcos/tftp/conf chown -f -R root:tcos /var/lib/tcos/tftp/conf chmod -f 775 /var/lib/tcos/tftp/conf chmod -f -R 664 /var/lib/tcos/tftp/conf/* 2>/dev/null || true gentcos -parse-pxelinuxcfg 2>/dev/null || true #DEBHELPER#