source: src-sh/pc-thinclient/pc-thinclient @ 4c82fbc

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

Update pc-thinclient

Add code which will ask user to input network mask for local subnet.

  • Property mode set to 100644
File size: 15.1 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 network id of the local subnet
180        while
181        z=1
182        do
183                echo "What is the network id for your local subnet? (I.E. 192.168.2.0)"
184                echo -e "netid) \c"
185                read netid
186
187        done
188       
189                # Ask for the network mask of the local subnet
190        while
191        z=1
192        do
193                echo "What is the network mask for your local subnet? (I.E. 255.255.255.0)"
194                echo -e "netmaskid) \c"
195                read netmaskid
196        break
197        done
198
199
200portmap_enable=\"YES\"
201nfs_server_enable=\"YES\"
202inetd_enable=\"YES\"
203
204        # Add firewall exception
205        if [ -e "/etc/pf.conf" ] ; then
206          cat /etc/pf.conf | grep "pass in on ${NIC} all" >/dev/null 2>/dev/null
207          if [ "$?" != "0" ] ; then
208                # Setup the firewall exclusion for this NIC
209                echo "pass in on ${NIC} all" >> /etc/pf.conf
210          fi
211        fi
212
213        # Add some entries for /etc/exports
214        cat /etc/exports 2>/dev/null | grep "$PXEWORLD" >/dev/null 2>/dev/null
215        if [ "$?" != "0" ] ; then
216                echo "$PXEWORLD -maproot=nobody -ro -network 192.168.2 -mask 255.255.255" >>/etc/exports
217        fi
218
219        # Setup tftp
220        cat /etc/inetd.conf | grep "$PXEWORLD" >/dev/null 2>/dev/null
221        if [ "$?" != "0" ] ; then
222                echo "tftp   dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -l -s ${PXEWORLD}" >> /etc/inetd.conf
223        fi
224       
225        # Setup rcpbind entries
226        cat /etc/hosts.allow 2>/dev/null | grep "192.168.2.0" >/dev/null 2>/dev/null
227        if [ "$?" != "0" ] ; then
228                sed  -i '' 's|rpcbind : ALL : deny|rpcbind : 192.168.2.0/255.255.255.0 : allow\
229portmap : 192.168.2.0/255.255.255.0 : allow\
230rpcbind : ALL : deny|' /etc/hosts.allow
231        fi
232
233        # Add a bulk of IPs to /etc/hosts this fixes bugs with RPC timeouts
234        # when mounting NFS
235        grep -q 'thinclient100' /etc/hosts
236        if [ $? -ne 0 ] ; then
237                i="100"
238                while
239                z="1"
240                do
241                        if [ "${i}" = "200" ]; then break; fi
242                        echo "192.168.2.${i}  thinclient${i}" >>/etc/hosts
243                        i="`expr ${i} + 1`"
244                done
245        fi
246
247        # Start the services
248        cmds="/etc/rc.d/nfsd /etc/rc.d/inetd"
249        for _sC in $cmds
250        do
251                echo -e "Starting ${_sC}...\c"
252                ${_sC} restart >/dev/null 2>/dev/null
253                if [ "$?" != "0" ] ; then
254                        echo -e "FAILED! Please run try running it manually."
255                else
256                        echo -e "OK"
257                fi
258        done
259}
260
261
262# Check if we need to install custom config
263check_installconfig() {
264        if [ -e "${PXEWORLD}/etc/scripts/tcslogin.sh" ] ; then return ; fi
265
266        # Lets copy over the /etc/scripts directory
267        rm -rf ${PXEWORLD}/etc/scripts >/dev/null 2>/dev/null
268        cp -r ${PROGDIR}/resources/scripts ${PXEWORLD}/etc/scripts
269
270        # Remove a few rc.d things we dont need on clients
271        rm ${PXEWORLD}/etc/rc.d/cron
272        rm ${PXEWORLD}/etc/rc.d/sendmail
273
274        # Lets copy over all the /etc/ files we need
275        cp ${PROGDIR}/resources/etc/fstab ${PXEWORLD}/etc/
276        cp ${PROGDIR}/resources/etc/gettytab ${PXEWORLD}/etc/
277        cp ${PROGDIR}/resources/etc/hosts ${PXEWORLD}/etc/
278        cp ${PROGDIR}/resources/etc/motd ${PXEWORLD}/etc/
279        cp ${PROGDIR}/resources/etc/rc.conf ${PXEWORLD}/etc/
280        cp ${PROGDIR}/resources/etc/ttys ${PXEWORLD}/etc/
281
282        # Copy over rc.d / boot / root files
283        cp ${PROGDIR}/resources/boot/beastie.4th ${PXEWORLD}/boot/
284        cp ${PROGDIR}/resources/root/dot.login ${PXEWORLD}/root/.login
285
286        # Create a few directories used on client
287        mkdir -p ${PXEWORLD}/mnt/xorg-config
288
289        # Create the diskless configuration
290        mkdir -p ${PXEWORLD}/conf/base
291        mkdir -p ${PXEWORLD}/conf/base/etc
292        mkdir -p ${PXEWORLD}/conf/base/var
293        mkdir -p ${PXEWORLD}/conf/base/root
294        echo "10m" > ${PXEWORLD}/conf/base/etc/md_size
295        echo "20m" > ${PXEWORLD}/conf/base/var/md_size
296        echo "30m" > ${PXEWORLD}/conf/base/root/md_size
297        chroot ${PXEWORLD} tar cvf conf/base/etc.cpio.gz --format cpio --gzip etc 2>/dev/null
298        chroot ${PXEWORLD} tar cvf conf/base/var.cpio.gz --exclude var/db/pkg --format cpio --gzip var 2>/dev/null
299        chroot ${PXEWORLD} tar cvf conf/base/root.cpio.gz --format cpio --gzip root 2>/dev/null
300       
301}
302
303# Check if we need to build the world environment
304check_worldports() {
305        if [ -e "${PXEWORLD}/usr/local/bin/xv" ] ; then return ; fi
306
307        if [ ! -d "${PXEWORLD}/usr/ports/x11/xorg" -a ! -d "/usr/ports/x11/xorg" ] ; then
308                exit_err "Missing /usr/ports/x11/xorg, please checkout ports tree to continue"
309        fi
310
311        if [ ! -d "${PXEWORLD}/usr/ports/x11/xorg" ] ; then
312                rm -rf "${PXEWORLD}/usr/ports"
313                echo "Copying /usr/ports -> ${PXEWORLD}/usr/ports"
314                cp -r /usr/ports ${PXEWORLD}/usr/ports
315        fi
316
317        # Building ports inside world
318        mount -t devfs devfs ${PXEWORLD}/dev
319        cp /etc/resolv.conf ${PXEWORLD}/etc/resolv.conf
320        echo "BATCH=yes" >> ${PXEWORLD}/etc/make.conf
321        echo '#!/bin/sh
322
323/etc/rc.d/ldconfig start
324chmod 777 /tmp
325MACHINE=i386 ; export MACHINE
326UNAME_p=i386 ; export UNAME_p
327UNAME_m=i386 ; export UNAME_m
328
329for p in $WORLDPORTS
330do
331        cd /usr/ports/$p
332        make install
333        if [ "$?" != "0" ] ; then
334                exit 1
335        fi
336done
337' > ${PXEWORLD}/.mkports.sh
338
339        chmod 755 ${PXEWORLD}/.mkports.sh
340        chroot ${PXEWORLD} /.mkports.sh
341        if [ "$?" != "0" ] ; then
342                exit_err "Failed building thinclient world ports!"
343        fi
344        rm ${PXEWORLD}/.mkports.sh
345        umount ${PXEWORLD}/dev
346
347}
348
349# Check if we need to build the world environment
350check_world() {
351  if [ -e "${PXEWORLD}/COPYRIGHT" ] ; then return ; fi
352       
353  mkdir -p "${PXEWORLD}"
354  cd "${PXEWORLD}"
355
356  # Default pcbsd.conf file
357  PCBSD_ETCCONF="/usr/local/etc/pcbsd.conf"
358
359  # Set the mirror URL
360  get_mirror
361  MIRRORURL="$VAL"
362
363  # Set the system arch type
364  if [ "$SYSTYPE" = "desktop" ] ; then
365    # If building remote X server, we don't need to run amd64
366    ARCH="i386"
367  else
368    ARCH="`uname -m`"
369  fi
370
371  local dFiles="base.txz doc.txz kernel.txz games.txz"
372  if [ "$ARCH" = "amd64" ] ; then
373     dFiles="$dFiles lib32.txz"
374  fi
375
376  # To fetch the jail environment
377  echo "Fetching FreeBSD environment. This may take a while..."
378  for i in $dFiles
379  do
380    echo "Downloading ${MIRRORURL}/${SYSVER}/${ARCH}/dist/${i} ..."
381   
382    get_file_from_mirrors "/${SYSVER}/${ARCH}/dist/${i}" "$i"
383    [ $? -ne 0 ] && exit_err "Error while downloading the freebsd world."
384  done
385
386  # Save the archive as our example world environment
387  mkdir -p ${PXEWORLD}/installarchive/
388
389  echo "Extracting FreeBSD environment... This may take a while..."
390  # Extract dist files
391  for i in $dFiles
392  do
393    tar xvpf ${i} 2>/dev/null
394    if [ $? -ne 0 ] ; then exit_err "Failed extracting FreeBSD environment"; fi
395
396    # Save the archive file
397    mv ${i} ${PXEWORLD}/installarchive/
398  done
399
400}
401
402# Function to check if dhcpd is installed
403check_dhcpd() {
404        which dhcpd >/dev/null 2>/dev/null
405        if [ "$?" = "0" ] ; then return; fi
406
407        echo "Installing $DHCPPORT"
408        pkg install -y ${DHCPPORT}
409        if [ "$?" != "0" ] ; then exit_err "Failed installing ${DHCPPORT}"; fi
410}
411
412# Function to display what information to add to external DHCP server
413ignore_dhcpd() {
414        echo "Add the following information to your external DHCP Server"
415        echo "Will display here when this works"
416}
417
418# Function which checks and sets up the thinclient as an install server
419check_installdirs() {
420        if [ -e "${PXEWORLD}/installscripts/pc-sysinstall.example" ]; then
421           return
422        fi
423        touch ${PXEWORLD}/etc/installserver
424        mkdir ${PXEWORLD}/installscripts
425        cp ${PROGDIR}/resources/scripts/pc-sysinstall.example ${PXEWORLD}/installscripts/pc-sysinstall.example
426        echo "zfs_load=\"YES\"" > ${PXEWORLD}/boot/loader.conf
427        echo "geom_mirror_load=\"YES\"" >> ${PXEWORLD}/boot/loader.conf
428        echo "geom_eli_load=\"YES\"" >> ${PXEWORLD}/boot/loader.conf
429}
430
431do_removal() {
432        if [ -d "${PXEWORLD}" ] ; then
433                echo "Removing ${PXEWORLD}"
434                rm -rf ${PXEWORLD} 2>/dev/null
435                chflags -R noschg ${PXEWORLD} 2>/dev/null
436                rm -rf ${PXEWORLD} 2>/dev/null
437        fi
438}
439
440# Make sure we are root
441if [ `id -u` != "0" ] ; then exit_err "Must be run as root!"; fi
442
443# Check if we are removing the existing thinclient
444if [ "$1" = "-remove" -o "$1" = "remove" ] ;  then
445  do_removal
446  exit 0
447fi
448
449echo "$0 will install the components to convert this system into a thin-client server."
450echo -e "Continue? (Y/N) \c"
451read tmp
452if [ "$tmp" != "Y" -a "$tmp" != "y" ] ; then
453        exit 0
454fi
455
456echo "Do you wish to install the dhcpd server port or use an external server?"
457echo "If you wish to use an external server please make sure it supports adding" 
458echo "next server and bootfile name options."
459echo -e "(d/e) \c"
460read tmp
461if [ "$tmp" = "D" -o "$tmp" = "d" ] ; then
462   DHCPTYPE="internal"
463else
464   DHCPTYPE="external"
465fi
466
467echo "Do you wish to make this a remote X desktop server or install server?"
468echo -e "(r/i) \c"
469read tmp
470if [ "$tmp" = "I" -o "$tmp" = "i" ] ; then
471   SYSTYPE="install"
472else
473   SYSTYPE="desktop"
474fi
475
476
477if [ "$DHCPTYPE" = "internal" ] ; then
478  # Start by installing dhcpd
479  check_dhcpd
480else
481  # Install without dhcpd
482  ignore_dhcpd
483
484# Start by setting up a new buildworld
485check_world
486
487if [ "$SYSTYPE" = "desktop" ] ; then
488  # Build the ports inside the world environment
489  check_worldports
490else
491  # Setup the installation directories
492  check_installdirs
493fi
494
495# Install the thinclient configuration files
496check_installconfig
497
498if [ "$DHCPTYPE" = "internal" ] ; then
499  # Tweak the base system to enable the thinclient
500  check_configsystem
501else
502  # Tweak the base system to enable the thinclient without dhcpd
503  check_configsystem_ignore_dhcp
504fi
505
506if [ "$SYSTYPE" = "desktop" ] ; then
507  echo ""
508  echo "You will now need to enable remote desktop."
509  echo "This can be done via the PC-BSD Control Panel -> GDM Configuration"
510  echo "or by manually editing /usr/local/etc/gdm/custom.conf"
511else
512  echo ""
513  echo "To perform system installations, place your custom pc-sysinstall scripts in:"
514  echo "/usr/home/thinclient/installscripts"
515  echo ""
516  echo "An example script is provided in the above directory"
517  echo ""
518  echo "For unattended installations, save your pc-sysinstall script as:"
519  echo "/usr/home/thinclient/installscripts/unattended.cfg"
520fi
521
522if [ "$DHCPTYPE" = "internal" ] ; then
523  echo " "
524  echo "Your system is now setup to do PXE booting!"
525  exit 0
526else
527  echo "You will need to modify your dhcp server before you can begin using PXE boot"
528  exit 0
529fi
530fi
Note: See TracBrowser for help on using the repository browser.