source: src-sh/pc-thinclient/pc-thinclient @ bbd17bc

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since bbd17bc was bbd17bc, checked in by pkgdemon <pkgdemonteam@…>, 14 months ago

Update pc-thinclient

Forgot to add needed lines for services to rc.conf.

  • Property mode set to 100644
File size: 15.4 KB
Line 
1#!/bin/sh
2#
3# Copyright 2012 Kris Moore / iXsystems
4# All rights reserved
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted providing that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26#
27#        Name: pc-thinclient
28# Description: Helper script to build / install the necessary bits to turn
29#              a PC-BSD system into a thin-client server
30#
31# Modified for external dhcp server support by Joe Maloney
32
33# Source our functions
34. /usr/local/share/pcbsd/scripts/functions.sh
35
36# Set some universal variables
37PROGDIR="/usr/local/share/pcbsd/pc-thinclient"
38DHCPPORT="isc-dhcp41-server"
39PXEWORLD="/usr/home/thinclient"
40WORLDPORTS="x11/xorg graphics/xv"
41export WORLDPORTS
42SYSVER="`uname -r | cut -d '-' -f 1-2`"
43
44# Start by sourcing /etc/profile
45# This grabs any HTTP_ / FTP_ PROXY variables
46. /etc/profile
47
48# Start configuring the base system
49check_configsystem() {
50        echo "Setting up system for PXE booting..."
51
52        # Setup the new pxeboot user with a default password
53        cat /etc/passwd | grep pxeboot >/dev/null 2>/dev/null
54        if [ "$?" != "0" ] ; then
55                echo "thinclient" | pw useradd -n "pxeboot" -h 0 -s /bin/tcsh -d ${PXEWORLD}/mnt/xorg-config -c "pxeboot"
56                chown -R pxeboot:pxeboot ${PXEWORLD}/mnt/xorg-config
57        fi
58
59        # Copy over the default dhcpd.conf file
60        cp ${PROGDIR}/resources/dhcpd/dhcpd.conf /usr/local/etc/dhcpd.conf
61
62        # Ask for the NIC we want to run on
63        while
64        z=1
65        do
66                echo "What NIC do you wish DHCPD to listen on? (I.E. re0)"
67                echo -e "nic) \c"
68                read NIC
69               
70                ifconfig $NIC >/dev/null 2>/dev/null
71                if [ $? -ne 0 -o -z "$NIC" ] ; then
72                        echo "Invalid nic entered, please try again!"
73                        sleep 1
74                else
75                        break
76                fi
77        done
78
79        # Save the rc.conf glue
80        cat /etc/rc.conf | grep "# pc-thinclient" >/dev/null 2>/dev/null
81        if [ "$?" != "0" ] ; then
82                echo "# pc-thinclient configuration
83dhcpd_enable=\"YES\"
84dhcpd_ifaces=\"${NIC}\"
85portmap_enable=\"YES\"
86nfs_server_enable=\"YES\"
87inetd_enable=\"YES\"
88ifconfig_${NIC}=\"192.168.2.2\"" >> /etc/rc.conf
89        fi
90
91        # Add firewall exception
92        if [ -e "/etc/pf.conf" ] ; then
93          cat /etc/pf.conf | grep "pass in on ${NIC} all" >/dev/null 2>/dev/null
94          if [ "$?" != "0" ] ; then
95                # Setup the firewall exclusion for this NIC
96                echo "pass in on ${NIC} all" >> /etc/pf.conf
97          fi
98        fi
99
100        # Add some entries for /etc/exports
101        cat /etc/exports 2>/dev/null | grep "$PXEWORLD" >/dev/null 2>/dev/null
102        if [ "$?" != "0" ] ; then
103                echo "$PXEWORLD -maproot=nobody -ro -network 192.168.2 -mask 255.255.255" >>/etc/exports
104        fi
105
106        # Setup tftp
107        cat /etc/inetd.conf | grep "$PXEWORLD" >/dev/null 2>/dev/null
108        if [ "$?" != "0" ] ; then
109                echo "tftp   dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -l -s ${PXEWORLD}" >> /etc/inetd.conf
110        fi
111
112        # Setup rcpbind entries
113        cat /etc/hosts.allow 2>/dev/null | grep "192.168.2.0" >/dev/null 2>/dev/null
114        if [ "$?" != "0" ] ; then
115                sed  -i '' 's|rpcbind : ALL : deny|rpcbind : 192.168.2.0/255.255.255.0 : allow\
116portmap : 192.168.2.0/255.255.255.0 : allow\
117rpcbind : ALL : deny|' /etc/hosts.allow
118        fi
119
120        # Add a bulk of IPs to /etc/hosts this fixes bugs with RPC timeouts
121        # when mounting NFS
122        grep -q 'thinclient100' /etc/hosts
123        if [ $? -ne 0 ] ; then
124                i="100"
125                while
126                z="1"
127                do
128                        if [ "${i}" = "200" ]; then break; fi
129                        echo "192.168.2.${i}  thinclient${i}" >>/etc/hosts
130                        i="`expr ${i} + 1`"
131                done
132        fi
133
134        # Make sure the NIC is set to the right IP before bringing up dhcpd
135        ifconfig $NIC 192.168.2.2
136
137        # Start the services
138        cmds="/etc/rc.d/nfsd /etc/rc.d/inetd /usr/local/etc/rc.d/isc-dhcpd"
139        for _sC in $cmds
140        do
141                echo -e "Starting ${_sC}...\c"
142                ${_sC} restart >/dev/null 2>/dev/null
143                if [ "$?" != "0" ] ; then
144                        echo -e "FAILED! Please run try running it manually."
145                else
146                        echo -e "OK"
147                fi
148        done
149}
150
151# Start configuring the base system without DHCP
152check_configsystem_ignore_dhcp() {
153        echo "Setting up system for PXE booting..."
154
155        # Setup the new pxeboot user with a default password
156        cat /etc/passwd | grep pxeboot >/dev/null 2>/dev/null
157        if [ "$?" != "0" ] ; then
158                echo "thinclient" | pw useradd -n "pxeboot" -h 0 -s /bin/tcsh -d ${PXEWORLD}/mnt/xorg-config -c "pxeboot"
159                chown -R pxeboot:pxeboot ${PXEWORLD}/mnt/xorg-config
160        fi
161
162        # Ask for the NIC we want to run on
163        while
164        z=1
165        do
166                echo "What NIC do you wish to listen on? (I.E. re0)"
167                echo -e "nic) \c"
168                read NIC
169
170                ifconfig $NIC >/dev/null 2>/dev/null
171                if [ $? -ne 0 -o -z "$NIC" ] ; then
172                        echo "Invalid nic entered, please try again!"
173                        sleep 1
174                else
175                        break
176                fi
177        done
178       
179        # Ask for the IP Address to be used on the NIC for PXE booting
180        while
181        z=1
182        do
183                echo "What IP address will pc-thinclient be listening on? (I.E. 192.168.2.2)"
184                echo -e "ipaddr) \c"
185                read ipaddr
186        break
187        done
188                # Ask for the network id of the local subnet
189        while
190        z=1
191        do
192                echo "What is the network id for your local subnet? (I.E. 192.168.2.0)"
193                echo -e "netid) \c"
194                read netid
195        break
196        done
197       
198                # Ask for the network mask of the local subnet
199        while
200        z=1
201        do
202                echo "What is the network mask for your local subnet? (I.E. 255.255.255.0)"
203                echo -e "netmaskid) \c"
204                read netmaskid
205        break
206        done
207
208        # Save the rc.conf glue
209        cat /etc/rc.conf | grep "# pc-thinclient" >/dev/null 2>/dev/null
210        if [ "$?" != "0" ] ; then
211                echo "# pc-thinclient configuration
212portmap_enable=\"YES\"
213nfs_server_enable=\"YES\"
214inetd_enable=\"YES\"
215
216        # Add firewall exception
217        if [ -e "/etc/pf.conf" ] ; then
218          cat /etc/pf.conf | grep "pass in on ${NIC} all" >/dev/null 2>/dev/null
219          if [ "$?" != "0" ] ; then
220                # Setup the firewall exclusion for this NIC
221                echo "pass in on ${NIC} all" >> /etc/pf.conf
222          fi
223        fi
224
225        # Add some entries for /etc/exports based on manual user input
226        echo "$PXEWORLD -maproot=nobody -ro -network $netid -mask $netmaskid" >> /etc/exports
227
228        # Setup tftp
229        cat /etc/inetd.conf | grep "$PXEWORLD" >/dev/null 2>/dev/null
230        if [ "$?" != "0" ] ; then
231                echo "tftp   dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -l -s ${PXEWORLD}" >> /etc/inetd.conf
232        fi
233       
234        # Setup rcpbind entries
235        sed -i -e "s|rpcbind : ALL : deny|rpcbind : $netid/$netmaskid : allow\\
236portmap : $netid/$netmaskid : allow\\
237rpcbind : ALL : deny|" /etc/hosts.allow
238
239        # Add a bulk of IPs to /etc/hosts this fixes bugs with RPC timeouts
240        # when mounting NFS
241        grep -q 'thinclient100' /etc/hosts
242        if [ $? -ne 0 ] ; then
243                i="100"
244                while
245                z="1"
246                do
247                        if [ "${i}" = "200" ]; then break; fi
248                        echo "192.168.2.${i}  thinclient${i}" >>/etc/hosts
249                        i="`expr ${i} + 1`"
250                done
251        fi
252
253        # Start the services
254        cmds="/etc/rc.d/nfsd /etc/rc.d/inetd"
255        for _sC in $cmds
256        do
257                echo -e "Starting ${_sC}...\c"
258                ${_sC} restart >/dev/null 2>/dev/null
259                if [ "$?" != "0" ] ; then
260                        echo -e "FAILED! Please run try running it manually."
261                else
262                        echo -e "OK"
263                fi
264        done
265}
266
267
268# Check if we need to install custom config
269check_installconfig() {
270        if [ -e "${PXEWORLD}/etc/scripts/tcslogin.sh" ] ; then return ; fi
271
272        # Lets copy over the /etc/scripts directory
273        rm -rf ${PXEWORLD}/etc/scripts >/dev/null 2>/dev/null
274        cp -r ${PROGDIR}/resources/scripts ${PXEWORLD}/etc/scripts
275
276        # Remove a few rc.d things we dont need on clients
277        rm ${PXEWORLD}/etc/rc.d/cron
278        rm ${PXEWORLD}/etc/rc.d/sendmail
279
280        # Lets copy over all the /etc/ files we need
281        cp ${PROGDIR}/resources/etc/fstab ${PXEWORLD}/etc/
282        cp ${PROGDIR}/resources/etc/gettytab ${PXEWORLD}/etc/
283        cp ${PROGDIR}/resources/etc/hosts ${PXEWORLD}/etc/
284        cp ${PROGDIR}/resources/etc/motd ${PXEWORLD}/etc/
285        cp ${PROGDIR}/resources/etc/rc.conf ${PXEWORLD}/etc/
286        cp ${PROGDIR}/resources/etc/ttys ${PXEWORLD}/etc/
287
288        # Copy over rc.d / boot / root files
289        cp ${PROGDIR}/resources/boot/beastie.4th ${PXEWORLD}/boot/
290        cp ${PROGDIR}/resources/root/dot.login ${PXEWORLD}/root/.login
291
292        # Create a few directories used on client
293        mkdir -p ${PXEWORLD}/mnt/xorg-config
294
295        # Create the diskless configuration
296        mkdir -p ${PXEWORLD}/conf/base
297        mkdir -p ${PXEWORLD}/conf/base/etc
298        mkdir -p ${PXEWORLD}/conf/base/var
299        mkdir -p ${PXEWORLD}/conf/base/root
300        echo "10m" > ${PXEWORLD}/conf/base/etc/md_size
301        echo "20m" > ${PXEWORLD}/conf/base/var/md_size
302        echo "30m" > ${PXEWORLD}/conf/base/root/md_size
303        chroot ${PXEWORLD} tar cvf conf/base/etc.cpio.gz --format cpio --gzip etc 2>/dev/null
304        chroot ${PXEWORLD} tar cvf conf/base/var.cpio.gz --exclude var/db/pkg --format cpio --gzip var 2>/dev/null
305        chroot ${PXEWORLD} tar cvf conf/base/root.cpio.gz --format cpio --gzip root 2>/dev/null
306       
307}
308
309# Check if we need to build the world environment
310check_worldports() {
311        if [ -e "${PXEWORLD}/usr/local/bin/xv" ] ; then return ; fi
312
313        if [ ! -d "${PXEWORLD}/usr/ports/x11/xorg" -a ! -d "/usr/ports/x11/xorg" ] ; then
314                exit_err "Missing /usr/ports/x11/xorg, please checkout ports tree to continue"
315        fi
316
317        if [ ! -d "${PXEWORLD}/usr/ports/x11/xorg" ] ; then
318                rm -rf "${PXEWORLD}/usr/ports"
319                echo "Copying /usr/ports -> ${PXEWORLD}/usr/ports"
320                cp -r /usr/ports ${PXEWORLD}/usr/ports
321        fi
322
323        # Building ports inside world
324        mount -t devfs devfs ${PXEWORLD}/dev
325        cp /etc/resolv.conf ${PXEWORLD}/etc/resolv.conf
326        echo "BATCH=yes" >> ${PXEWORLD}/etc/make.conf
327        echo '#!/bin/sh
328
329/etc/rc.d/ldconfig start
330chmod 777 /tmp
331MACHINE=i386 ; export MACHINE
332UNAME_p=i386 ; export UNAME_p
333UNAME_m=i386 ; export UNAME_m
334
335for p in $WORLDPORTS
336do
337        cd /usr/ports/$p
338        make install
339        if [ "$?" != "0" ] ; then
340                exit 1
341        fi
342done
343' > ${PXEWORLD}/.mkports.sh
344
345        chmod 755 ${PXEWORLD}/.mkports.sh
346        chroot ${PXEWORLD} /.mkports.sh
347        if [ "$?" != "0" ] ; then
348                exit_err "Failed building thinclient world ports!"
349        fi
350        rm ${PXEWORLD}/.mkports.sh
351        umount ${PXEWORLD}/dev
352
353}
354
355# Check if we need to build the world environment
356check_world() {
357  if [ -e "${PXEWORLD}/COPYRIGHT" ] ; then return ; fi
358       
359  mkdir -p "${PXEWORLD}"
360  cd "${PXEWORLD}"
361
362  # Default pcbsd.conf file
363  PCBSD_ETCCONF="/usr/local/etc/pcbsd.conf"
364
365  # Set the mirror URL
366  get_mirror
367  MIRRORURL="$VAL"
368
369  # Set the system arch type
370  if [ "$SYSTYPE" = "desktop" ] ; then
371    # If building remote X server, we don't need to run amd64
372    ARCH="i386"
373  else
374    ARCH="`uname -m`"
375  fi
376
377  local dFiles="base.txz doc.txz kernel.txz games.txz"
378  if [ "$ARCH" = "amd64" ] ; then
379     dFiles="$dFiles lib32.txz"
380  fi
381
382  # To fetch the jail environment
383  echo "Fetching FreeBSD environment. This may take a while..."
384  for i in $dFiles
385  do
386    echo "Downloading ${MIRRORURL}/${SYSVER}/${ARCH}/dist/${i} ..."
387   
388    get_file_from_mirrors "/${SYSVER}/${ARCH}/dist/${i}" "$i"
389    [ $? -ne 0 ] && exit_err "Error while downloading the freebsd world."
390  done
391
392  # Save the archive as our example world environment
393  mkdir -p ${PXEWORLD}/installarchive/
394
395  echo "Extracting FreeBSD environment... This may take a while..."
396  # Extract dist files
397  for i in $dFiles
398  do
399    tar xvpf ${i} 2>/dev/null
400    if [ $? -ne 0 ] ; then exit_err "Failed extracting FreeBSD environment"; fi
401
402    # Save the archive file
403    mv ${i} ${PXEWORLD}/installarchive/
404  done
405
406}
407
408# Function to check if dhcpd is installed
409check_dhcpd() {
410        which dhcpd >/dev/null 2>/dev/null
411        if [ "$?" = "0" ] ; then return; fi
412
413        echo "Installing $DHCPPORT"
414        pkg install -y ${DHCPPORT}
415        if [ "$?" != "0" ] ; then exit_err "Failed installing ${DHCPPORT}"; fi
416}
417
418# Function to display what information to add to external DHCP server
419ignore_dhcpd() {
420        echo "Add the following information to your external DHCP Server"
421        echo "Will display here when this works"
422}
423
424# Function which checks and sets up the thinclient as an install server
425check_installdirs() {
426        if [ -e "${PXEWORLD}/installscripts/pc-sysinstall.example" ]; then
427           return
428        fi
429        touch ${PXEWORLD}/etc/installserver
430        mkdir ${PXEWORLD}/installscripts
431        cp ${PROGDIR}/resources/scripts/pc-sysinstall.example ${PXEWORLD}/installscripts/pc-sysinstall.example
432        echo "zfs_load=\"YES\"" > ${PXEWORLD}/boot/loader.conf
433        echo "geom_mirror_load=\"YES\"" >> ${PXEWORLD}/boot/loader.conf
434        echo "geom_eli_load=\"YES\"" >> ${PXEWORLD}/boot/loader.conf
435}
436
437do_removal() {
438        if [ -d "${PXEWORLD}" ] ; then
439                echo "Removing ${PXEWORLD}"
440                rm -rf ${PXEWORLD} 2>/dev/null
441                chflags -R noschg ${PXEWORLD} 2>/dev/null
442                rm -rf ${PXEWORLD} 2>/dev/null
443        fi
444}
445
446# Make sure we are root
447if [ `id -u` != "0" ] ; then exit_err "Must be run as root!"; fi
448
449# Check if we are removing the existing thinclient
450if [ "$1" = "-remove" -o "$1" = "remove" ] ;  then
451  do_removal
452  exit 0
453fi
454
455echo "$0 will install the components to convert this system into a thin-client server."
456echo -e "Continue? (Y/N) \c"
457read tmp
458if [ "$tmp" != "Y" -a "$tmp" != "y" ] ; then
459        exit 0
460fi
461
462echo "Do you wish to install the dhcpd server port or use an external server?"
463echo "If you wish to use an external server please make sure it supports adding"
464echo "next server and bootfile name options."
465echo -e "(d/e) \c"
466read tmp
467if [ "$tmp" = "D" -o "$tmp" = "d" ] ; then
468   DHCPTYPE="internal"
469else
470   DHCPTYPE="external"
471fi
472
473echo "Do you wish to make this a remote X desktop server or install server?"
474echo -e "(r/i) \c"
475read tmp
476if [ "$tmp" = "I" -o "$tmp" = "i" ] ; then
477   SYSTYPE="install"
478else
479   SYSTYPE="desktop"
480fi
481
482
483if [ "$DHCPTYPE" = "internal" ] ; then
484  # Start by installing dhcpd
485  check_dhcpd
486else
487  # Install without dhcpd
488  ignore_dhcpd
489
490# Start by setting up a new buildworld
491check_world
492
493if [ "$SYSTYPE" = "desktop" ] ; then
494  # Build the ports inside the world environment
495  check_worldports
496else
497  # Setup the installation directories
498  check_installdirs
499fi
500
501# Install the thinclient configuration files
502check_installconfig
503
504if [ "$DHCPTYPE" = "internal" ] ; then
505  # Tweak the base system to enable the thinclient
506  check_configsystem
507else
508  # Tweak the base system to enable the thinclient without dhcpd
509  check_configsystem_ignore_dhcp
510fi
511
512if [ "$SYSTYPE" = "desktop" ] ; then
513  echo ""
514  echo "You will now need to enable remote desktop."
515  echo "This can be done via the PC-BSD Control Panel -> GDM Configuration"
516  echo "or by manually editing /usr/local/etc/gdm/custom.conf"
517else
518  echo ""
519  echo "To perform system installations, place your custom pc-sysinstall scripts in:"
520  echo "/usr/home/thinclient/installscripts"
521  echo ""
522  echo "An example script is provided in the above directory"
523  echo ""
524  echo "For unattended installations, save your pc-sysinstall script as:"
525  echo "/usr/home/thinclient/installscripts/unattended.cfg"
526fi
527
528if [ "$DHCPTYPE" = "internal" ] ; then
529  echo ""
530  echo "Your system is now setup to do PXE booting!"
531  exit 0
532else
533  echo "You will need to modify the following options in your dhcp server:"
534  echo ""
535  echo "filename "boot/pxeboot"
536  echo "next-server $ipaddr"
537  echo "option root-path "/usr/home/thinclient"
538  echo ""
539  echo "Then you can begin to use PXE Boot."
540  exit 0
541fi
542fi
Note: See TracBrowser for help on using the repository browser.