Initial commit
This commit is contained in:
120
customcd/files/etc/init.d/dhcpd
Normal file
120
customcd/files/etc/init.d/dhcpd
Normal file
@@ -0,0 +1,120 @@
|
||||
#!/sbin/openrc-run
|
||||
# Copyright 1999-2015 Gentoo Foundation
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
extra_commands="configtest"
|
||||
|
||||
: ${DHCPD_CONF:=/etc/dhcp/${SVCNAME}.conf}
|
||||
|
||||
depend() {
|
||||
#need net
|
||||
provide net
|
||||
use logger dns
|
||||
}
|
||||
|
||||
get_var() {
|
||||
local var="$(sed -n 's/^[[:blank:]]\?'"$1"' "*\([^#";]\+\).*/\1/p' "${chroot}${DHCPD_CONF}")"
|
||||
echo ${var:-$2}
|
||||
}
|
||||
|
||||
setup_opts() {
|
||||
DHCPD_CHROOT=${DHCPD_CHROOT%/}
|
||||
|
||||
# Work out our cffile if it's in our DHCPD_OPTS
|
||||
case " ${DHCPD_OPTS} " in
|
||||
*" -cf "*)
|
||||
DHCPD_CONF=" ${DHCPD_OPTS} "
|
||||
DHCPD_CONF="${DHCPD_CONF##* -cf }"
|
||||
DHCPD_CONF="${DHCPD_CONF%% *}"
|
||||
;;
|
||||
*) DHCPD_OPTS="${DHCPD_OPTS} -cf ${DHCPD_CONF}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
checkconfig() {
|
||||
set -- ${DHCPD_OPTS} -chroot "${DHCPD_CHROOT:-/}" -t
|
||||
|
||||
dhcpd "$@" 1>/dev/null 2>&1
|
||||
local ret=$?
|
||||
if [ ${ret} -ne 0 ] ; then
|
||||
eerror "${SVCNAME} has detected a syntax error in your configuration files:"
|
||||
dhcpd "$@"
|
||||
fi
|
||||
|
||||
return ${ret}
|
||||
}
|
||||
|
||||
configtest() {
|
||||
setup_opts
|
||||
|
||||
ebegin "Checking ${SVCNAME} configuration"
|
||||
checkconfig
|
||||
eend $?
|
||||
}
|
||||
|
||||
start() {
|
||||
setup_opts
|
||||
local chroot="${DHCPD_CHROOT}"
|
||||
|
||||
if [ -n "${chroot}" ] ; then
|
||||
# the config test want's these to exist
|
||||
mkdir -p \
|
||||
"${chroot}"/var/run/dhcp \
|
||||
"${chroot}"/var/lib/dhcp \
|
||||
"${chroot}"/etc/dhcp
|
||||
fi
|
||||
|
||||
# see comment in get_var() above
|
||||
if [ ! -f "${chroot}${DHCPD_CONF}" ] ; then
|
||||
eerror "${chroot}${DHCPD_CONF} does not exist"
|
||||
return 1
|
||||
fi
|
||||
|
||||
checkconfig || return 1
|
||||
|
||||
checkpath -d -o dhcp:dhcp "${chroot}"/var/run/dhcp "${chroot}"/var/lib/dhcp
|
||||
|
||||
local leasefile="$(get_var lease-file-name /var/lib/dhcp/${SVCNAME}.leases)"
|
||||
checkpath -f -o dhcp:dhcp "${chroot}${leasefile}"
|
||||
|
||||
# Setup LD_PRELOAD so name resolution works in our chroot.
|
||||
if [ -n "${chroot}" ] ; then
|
||||
checkpath -d -o root:root -m 755 "${chroot}"/dev "${chroot}"/etc "${chroot}"/proc
|
||||
cp -pP /etc/localtime /etc/resolv.conf "${chroot}"/etc/
|
||||
export LD_PRELOAD="${LD_PRELOAD} libresolv.so libnss_dns.so"
|
||||
if ! mountinfo -q "${chroot}/proc" ; then
|
||||
mount --bind /proc "${chroot}/proc"
|
||||
fi
|
||||
fi
|
||||
|
||||
local pidfile="$(get_var pid-file-name /var/run/dhcp/${SVCNAME}.pid)"
|
||||
|
||||
ebegin "Starting ${chroot:+chrooted }${SVCNAME}"
|
||||
start-stop-daemon --start --exec /usr/sbin/dhcpd \
|
||||
--pidfile "${chroot}/${pidfile}" \
|
||||
-- ${DHCPD_OPTS} -q -pf "${pidfile}" -lf "${leasefile}" \
|
||||
-user dhcp -group dhcp \
|
||||
-chroot "${chroot:-/}" ${DHCPD_IFACE}
|
||||
eend $? \
|
||||
&& save_options dhcpd_chroot "${chroot}" \
|
||||
&& save_options pidfile "${pidfile}"
|
||||
}
|
||||
|
||||
stop() {
|
||||
local chroot="$(get_options dhcpd_chroot)"
|
||||
[ -z "${chroot}" ] && chroot="$(get_options chroot)"
|
||||
|
||||
ebegin "Stopping ${chroot:+chrooted }${SVCNAME}"
|
||||
start-stop-daemon --stop --exec /usr/sbin/dhcpd \
|
||||
--pidfile "${chroot}/$(get_options pidfile)"
|
||||
res=$?
|
||||
|
||||
if [ ${res} -eq 0 ] && [ -n "${chroot}" ] ; then
|
||||
if mountinfo -q "${chroot}/proc" ; then
|
||||
umount "${chroot}/proc"
|
||||
fi
|
||||
fi
|
||||
|
||||
eend ${res}
|
||||
}
|
||||
44
customcd/files/etc/init.d/dostartx
Normal file
44
customcd/files/etc/init.d/dostartx
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/sbin/runscript
|
||||
|
||||
DAEMON="/usr/bin/xinit"
|
||||
ARGS="/etc/X11/xinit/xinitrc"
|
||||
PIDFILE="/var/run/dostartx.pid"
|
||||
LOGFILE="/var/log/dostartx.log"
|
||||
CWD="/root"
|
||||
|
||||
totalmem=`free|grep Mem:|awk '{print $2}'`
|
||||
if [ "$totalmem" -lt 500000 ]; then
|
||||
if grep -q "autoruns=3" /proc/cmdline ; then
|
||||
dotextonly=1
|
||||
fi
|
||||
fi
|
||||
|
||||
depend() {
|
||||
after sysresccd
|
||||
}
|
||||
|
||||
start() {
|
||||
if grep -q "dostartx" /proc/cmdline
|
||||
then
|
||||
if [ "$dotextonly" ]
|
||||
then
|
||||
ebegin "Not enough memory to start the graphical environment"
|
||||
eend 0
|
||||
else
|
||||
ebegin "Starting the graphical environment"
|
||||
start-stop-daemon --start --quiet --user root --env SHELL="/bin/bash" --env PATH="$PATH:/root/rescuebru" \
|
||||
--pidfile $PIDFILE --exec $DAEMON --background --chdir $CWD \
|
||||
--stdout $LOGFILE --make-pidfile -- $ARGS
|
||||
eend $?
|
||||
fi
|
||||
else
|
||||
eend 0
|
||||
fi
|
||||
}
|
||||
|
||||
stop() {
|
||||
ebegin "Stopping the graphical environment"
|
||||
start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON
|
||||
eend $?
|
||||
}
|
||||
|
||||
187
customcd/files/etc/init.d/pxebootsrv
Normal file
187
customcd/files/etc/init.d/pxebootsrv
Normal file
@@ -0,0 +1,187 @@
|
||||
#!/sbin/runscript
|
||||
# Distributed under the terms of the GNU General Public License, v2 or later
|
||||
|
||||
bootdir='/livemnt/boot'
|
||||
|
||||
depend()
|
||||
{
|
||||
need net
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
ebegin "Starting the pxe-boot-server"
|
||||
|
||||
# ---- check the cdrom files exist
|
||||
if ! ls -l ${bootdir}/sysrcd.dat ${bootdir}/???linux/???linux.cfg >/dev/null 2>&1
|
||||
then
|
||||
eerror "Files are missing, please check you are running a valid SystemRescueCd"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# ---- check the config file exists
|
||||
if [ ! -f /etc/conf.d/pxebootsrv ]
|
||||
then
|
||||
eerror "The pxebootsrv configuration file \"/etc/conf.d/pxebootsrv\" does not exists. Cannot continue."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# ---- check the major options are set to 'yes' or 'no'
|
||||
if [ $PXEBOOTSRV_DODHCPD != "yes" ] && [ $PXEBOOTSRV_DODHCPD != "no" ]
|
||||
then
|
||||
eerror "Invalid value for PXEBOOTSRV_DODHCPD. Must be \"yes\" or \"no\" (lowercase)."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ $PXEBOOTSRV_DOTFTPD != "yes" ] && [ $PXEBOOTSRV_DOTFTPD != "no" ]
|
||||
then
|
||||
eerror "Invalid value for PXEBOOTSRV_DOTFTPD. Must be \"yes\" or \"no\" (lowercase)."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ $PXEBOOTSRV_DOHTTPD != "yes" ] && [ $PXEBOOTSRV_DOHTTPD != "no" ]
|
||||
then
|
||||
eerror "Invalid value for PXEBOOTSRV_DOHTTPD. Must be \"yes\" or \"no\" (lowercase)."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ $PXEBOOTSRV_DONFSD != "yes" ] && [ $PXEBOOTSRV_DONFSD != "no" ]
|
||||
then
|
||||
eerror "Invalid value for PXEBOOTSRV_DONFSD. Must be \"yes\" or \"no\" (lowercase)."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ $PXEBOOTSRV_DODHCPD == "yes" ]
|
||||
then
|
||||
# ---- prepare /etc/dhcp/dhcpd.conf from /etc/conf.d/pxebootsrv
|
||||
[ -f /etc/dhcp/dhcpd.conf ] && cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.bak
|
||||
cp /etc/dhcp/dhcpd.orig /etc/dhcp/dhcpd.conf
|
||||
|
||||
if [ -z "$PXEBOOTSRV_SUBNET" -o -z "$PXEBOOTSRV_NETMASK" ]
|
||||
then
|
||||
eerror "Invalid values for PXEBOOTSRV_SUBNET or PXEBOOTSRV_NETMASK"
|
||||
return 1
|
||||
else
|
||||
sed -i -e "s/subnet 192.168.1.0 netmask 255.255.255.0/subnet $PXEBOOTSRV_SUBNET netmask $PXEBOOTSRV_NETMASK/" /etc/dhcp/dhcpd.conf
|
||||
sed -i -e "s/option subnet-mask 255.255.255.0;/option subnet-mask $PXEBOOTSRV_NETMASK;/" /etc/dhcp/dhcpd.conf
|
||||
fi
|
||||
|
||||
if [ -z "$PXEBOOTSRV_DEFROUTE" ]
|
||||
then
|
||||
eerror "The config variable PXEBOOTSRV_DEFROUTE is missing"
|
||||
return 1
|
||||
else
|
||||
sed -i -e "s/option routers 192.168.1.254;/option routers $PXEBOOTSRV_DEFROUTE;/" /etc/dhcp/dhcpd.conf
|
||||
fi
|
||||
|
||||
if [ -z "$PXEBOOTSRV_DHCPRANGE" ]
|
||||
then
|
||||
eerror "The config variable PXEBOOTSRV_DHCPRANGE is missing"
|
||||
return 1
|
||||
else
|
||||
sed -i -e "s/range dynamic-bootp 192.168.1.100 192.168.1.150;/range dynamic-bootp $PXEBOOTSRV_DHCPRANGE;/" /etc/dhcp/dhcpd.conf
|
||||
fi
|
||||
|
||||
if [ -z "$PXEBOOTSRV_TFTPSERVER" ]
|
||||
then
|
||||
eerror "The config variable PXEBOOTSRV_TFTPSERVER is missing"
|
||||
return 1
|
||||
else
|
||||
sed -i -e "s/next-server 192.168.1.5;/next-server $PXEBOOTSRV_TFTPSERVER;/" /etc/dhcp/dhcpd.conf
|
||||
fi
|
||||
|
||||
if [ -n "$PXEBOOTSRV_DNS" ]
|
||||
then
|
||||
sed -i -e "s/option domain-name-servers 192.168.1.254;/option domain-name-servers $PXEBOOTSRV_DNS;/" /etc/dhcp/dhcpd.conf
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $PXEBOOTSRV_DOTFTPD == "yes" ]
|
||||
then
|
||||
# ---- prepare pxelinux config file
|
||||
[ ! -d /tftpboot/pxelinux.cfg ] && mkdir -p /tftpboot/pxelinux.cfg
|
||||
[ ! -f /tftpboot/pxelinux.0 ] && cp /usr/share/syslinux/pxelinux.0 /tftpboot/
|
||||
[ -f /tftpboot/pxelinux.cfg/default.bak ] && rm -f /tftpboot/pxelinux.cfg/default.bak
|
||||
[ -f /tftpboot/pxelinux.cfg/default ] && mv /tftpboot/pxelinux.cfg/default /tftpboot/pxelinux.cfg/default.bak
|
||||
cp --remove-destination ${bootdir}/???linux/{*msg,*c32,*.0,memdisk,netboot} /tftpboot/
|
||||
cp --remove-destination ${bootdir}/???linux/???linux.cfg /tftpboot/pxelinux.cfg/default
|
||||
if [ -n "$PXEBOOTSRV_TIMEOUT" ]
|
||||
then
|
||||
sed -i -e "s!^TIMEOUT .*!TIMEOUT $PXEBOOTSRV_TIMEOUT!i" /tftpboot/pxelinux.cfg/default
|
||||
fi
|
||||
sed -i -e "s!scandelay=1!scandelay=5 netboot=$PXEBOOTSRV_HTTPSERVER ${PXEBOOTSRV_EXTRA}!g" /tftpboot/pxelinux.cfg/default
|
||||
fi
|
||||
|
||||
# ---- start the NFS server
|
||||
if [ $PXEBOOTSRV_DONFSD == "yes" ]
|
||||
then
|
||||
# ---- nfs export /tftpboot
|
||||
touch /etc/exports
|
||||
sed -i -e 's!^/tftpboot!#/tftpboot!g' /etc/exports
|
||||
echo "/tftpboot *(fsid=0,ro,no_subtree_check,all_squash,insecure,anonuid=1000,anongid=1000)" >> /etc/exports
|
||||
fi
|
||||
|
||||
# ---- stop network manager to avoid conflicts
|
||||
/etc/init.d/NetworkManager stop
|
||||
|
||||
# ---- bring up network interface
|
||||
ifconfig $PXEBOOTSRV_IF $PXEBOOTSRV_LOCALIP/24
|
||||
|
||||
# ---- start the DHCPD service
|
||||
if [ $PXEBOOTSRV_DODHCPD == "yes" ]
|
||||
then
|
||||
/etc/init.d/dhcpd restart
|
||||
if [ "$?" != "0" ]
|
||||
then
|
||||
eerror "Cannot start /etc/init.d/dhcpd, check /var/log/messages"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# ---- start the THTTPD service
|
||||
if [ $PXEBOOTSRV_DOHTTPD == "yes" ]
|
||||
then
|
||||
/etc/init.d/thttpd restart
|
||||
if [ "$?" != "0" ]
|
||||
then
|
||||
eerror "Cannot start /etc/init.d/thttpd"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# ---- start the TFTPD service
|
||||
if [ $PXEBOOTSRV_DOTFTPD == "yes" ]
|
||||
then
|
||||
/etc/init.d/in.tftpd restart
|
||||
if [ "$?" != "0" ]
|
||||
then
|
||||
eerror "Cannot start /etc/init.d/in.tftpd"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# ---- start the NFS server
|
||||
if [ $PXEBOOTSRV_DONFSD == "yes" ]
|
||||
then
|
||||
/etc/init.d/nfs restart
|
||||
if [ "$?" != "0" ]
|
||||
then
|
||||
eerror "Cannot start /etc/init.d/nfs"
|
||||
return 1
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
ebegin "Stopping the pxe-boot-server"
|
||||
|
||||
/etc/init.d/thttpd stop
|
||||
/etc/init.d/in.tftpd stop
|
||||
/etc/init.d/dhcpd stop
|
||||
|
||||
return 0
|
||||
}
|
||||
128
customcd/files/etc/init.d/sysresccd
Normal file
128
customcd/files/etc/init.d/sysresccd
Normal file
@@ -0,0 +1,128 @@
|
||||
#!/sbin/runscript
|
||||
|
||||
source /sbin/livecd-functions.sh
|
||||
|
||||
depend()
|
||||
{
|
||||
before xdm autorun tigervnc
|
||||
after pwgen sshd portmap hald
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
ebegin "Performing the SystemRescueCd specific initializations"
|
||||
|
||||
CMDLINE="$(cat /proc/cmdline)"
|
||||
|
||||
# ---- create file /var/log/lastlog so that ssh does not complain in the logs ----
|
||||
touch /var/log/lastlog
|
||||
|
||||
# ---- create various directories ----
|
||||
mkdir -p /var/log/samba
|
||||
mkdir -p /var/cache/revdep-rebuild
|
||||
mkdir -p /var/run/dhcp
|
||||
chown dhcp:dhcp /var/run/dhcp
|
||||
|
||||
# ---- disable screensaver in the console
|
||||
setterm -blank 0 -powersave off
|
||||
|
||||
# ---- auto-detect software raid ----
|
||||
[ -n "$(which mdadm)" ] && mdadm --auto-detect 2>&1
|
||||
|
||||
# ---- change the root password if requested in cmdline ----
|
||||
for curopt in ${CMDLINE}
|
||||
do
|
||||
if echo "${curopt}" | grep -q -E '^rootpass=[^ ]{1,32}$'
|
||||
then
|
||||
newpass="$(echo ${curopt} | sed -r -e 's!^rootpass=([^ ]{1,32})$!\1!g')"
|
||||
( echo root:${newpass} ) | chpasswd 1>/dev/null 2>&1
|
||||
fi
|
||||
done
|
||||
|
||||
# ---- options to start/stop services ----
|
||||
for curopt in ${CMDLINE}
|
||||
do
|
||||
if echo "${curopt}" | grep -q -E '^initscript=[a-zA-Z0-9]{1,32}:[a-z]{1,32}$'
|
||||
then
|
||||
touch /var/log/initscript.log
|
||||
service="$(echo ${curopt} | sed -r -e 's!^initscript=([a-zA-Z0-9]{1,32}):([a-z]{1,32})$!\1!g')"
|
||||
action="$(echo ${curopt} | sed -r -e 's!^initscript=([a-zA-Z0-9]{1,32}):([a-z]{1,32})$!\2!g')"
|
||||
echo "initscript: found option ${curopt} (service=${service} and action=${action}" >| /var/log/initscript.log
|
||||
if [ -x "/etc/init.d/${service}" ]
|
||||
then
|
||||
cmd="/etc/init.d/${service} ${action}"
|
||||
${cmd} > /var/log/initscript-${service}.log 2>&1
|
||||
res=$?
|
||||
echo "initscript: ${cmd} --> ${res}" | tee -a /var/log/initscript.log
|
||||
else
|
||||
echo "initscript: /etc/init.d/${service} not found" | tee -a /var/log/initscript.log
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# ---- options to configure and start the vncserver ----
|
||||
# eg: "rescuecd vncserver=2:mYpAsWd" will create two vnc displays (display=1 on port 5900 and display=2 on port 5901)
|
||||
# and the two displays will use the same password and the root user account (password=mYpAsWd)
|
||||
# this option should be used only once, but in case of multiple usages the last vncserver option overwrite the previous ones
|
||||
vnclog='/var/log/vncserver.log'
|
||||
for curopt in ${CMDLINE}
|
||||
do
|
||||
case "${curopt}" in
|
||||
vncserver\=*)
|
||||
echo '' >| ${vnclog}
|
||||
vncopt="$(echo ${curopt} | cut -d= -f2)"
|
||||
echo "vncserver: found option vncserver=${vncopt}" | tee -a ${vnclog}
|
||||
if echo "${vncopt}" | grep -q -E '^[1-9]:[^ ]{6,12}$'
|
||||
then
|
||||
[ -f /root/.vnc/passwd ] && rm -f /root/.vnc/passwd
|
||||
[ ! -d /root/.vnc ] && mkdir -p /root/.vnc
|
||||
sed -i -e 's!^DISPLAYS=.*!!g' /etc/conf.d/tigervnc
|
||||
displaycnt="$(echo ${curopt} | sed -r -e 's!^vncserver=([1-9]):([^ ]{6,12})$!\1!g')"
|
||||
password="$(echo ${curopt} | sed -r -e 's!^vncserver=([1-9]):([^ ]{6,12})$!\2!g')"
|
||||
echo "vncserver: ${displaycnt} displays will be created" | tee -a ${vnclog}
|
||||
echo "vncserver: creating password file in /root/.vnc/passwd:" >>${vnclog}
|
||||
echo -e "${password}\n${password}\n" | vncpasswd /root/.vnc/passwd >>${vnclog} 2>&1
|
||||
|
||||
chmod 600 /root/.vnc/passwd
|
||||
echo "exec /usr/bin/startxfce4 >/dev/null 2>&1" >| /root/.vnc/xstartup
|
||||
chmod 700 /root/.vnc/xstartup
|
||||
displayopt=''
|
||||
for ((i=1; i <= displaycnt; i++))
|
||||
do
|
||||
echo "vncserver: preparing display number $i" | tee -a ${vnclog}
|
||||
displayopt="${displayopt} root:$i"
|
||||
displayopt="$(echo ${displayopt} | sed -e 's!^ !!g' | sed -e 's! $!!g')"
|
||||
done
|
||||
echo "DISPLAYS=\"${displayopt}\"" >> /etc/conf.d/tigervnc
|
||||
else
|
||||
echo "vncserver: invalid syntax (expected \"vncserver=x:mYpAsWd\")"
|
||||
echo " where x is the number of displays (1 or 2 in general)"
|
||||
echo " mYpAsWd is a password (between 6 and 12 characters)"
|
||||
sleep 2
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ---- clean /etc/mtab ----
|
||||
if grep -q -F 'tmpfs /newroot' /etc/mtab
|
||||
then
|
||||
rm -f /etc/mtab.bak
|
||||
cp /etc/mtab /etc/mtab.bak
|
||||
sed -i -e "/ \/newroot/d" /etc/mtab
|
||||
fi
|
||||
|
||||
# ---- create a kernel options file ----
|
||||
if [ -f /proc/config.gz ]
|
||||
then
|
||||
cat /proc/config.gz | gzip -d > /root/kernel-$(uname -r).conf
|
||||
fi
|
||||
|
||||
# ---- fix inittab for serial consoles
|
||||
livecd_fix_inittab
|
||||
/sbin/telinit q &>/dev/null
|
||||
|
||||
# ---- mount tmpfs (important for backing store)
|
||||
mount -t tmpfs tmpfs /tmp
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user