[Discuss] Scripting help

Steven Santos Steven at simplycircus.com
Mon Feb 17 10:33:18 EST 2014


So, my scripting fu isn't great.  This mostly works, but I need some
help with it.

I know what needs to be done to get CUPS and SANE working, but I don't
know how to make the changes (see the script below)

I am not sure of the best way to install a .deb package via a script
(help would be appreciated)

I would love to be able to run a script on the server to modify this
with the correct LDAP information, possibly eventually create a way to
download a filled in version from the Zentyal admin screen.



#!/bin/sh

######################################################################
######################################################################
#
# This script is designed for Ubuntu 12.10.  It may or may not work
with other versions.
# This script will set up a computer to be a client on a Zentyal
network, including the following services:
# - Log-in via ldap
# - Mount home directories from the server
# - Mount shared directories from the server
# - Tell CUPS to print via CUPS on the server
# - Tell SANE to pickup shared scanners on the server
# - Enable partner repos
# - Add additional repos
# - Install additional software
#
# This script makes the following assumptions:
# - You have a working Zentyal installation
# - You have users set up on the Zentyal server
# - You have opened up port 390 on the Zentyal server
# - You have set up and exported /home and /shared shares from the server
# - You have set up and shared out any printers via CUPS
# - You have set up and shared out any scanners via SANED
#
# This script sets up standard repositories and software for the network
#
# This script MUST be run as root
#
######################################################################
######################################################################


######################################################################
######################################################################
# This section sets the LDAP information.
# Edit the following to match your Zentyal server
# Make sure you do NOT have a space before or after the equal sign
######################################################################
ldapserver=192.168.0.1                   # IP address or hostname
basedn=dc=office,dc=lan                  # The domain Zentyal is on
rootdn=cn=zentyal,dc=office,dc=lan       # The root DN
passwort=rVhH5PIgaDYwZFNdAPi2            # The password
######################################################################
# If you are unsure of your basedn, from the Zentyal dash board:
->"Users and Groups" -> "LDAP settings" -> "LDAP information" -> #
Base DN
######################################################################
# The uri is the IP address of your Zentyal box. Zentyal uses  Port
390 to reach ldap (the port is added by the script later)
######################################################################
# If you are unsure of the rootnd and/or password, you can either:
# from the Zentyal dash board: ->"Users and Groups" -> "LDAP settings"
-> "LDAP information" -> LDAP USER
# OR from a terminal on the zentyal server, run the following commands:
# sudo grep ^binddn /etc/ldap.conf
# sudo grep ^bindpw /etc/ldap.conf
######################################################################
######################################################################


######################################################################
######################################################################
# Set the values for the 'ldap-auth-config' Installer
######################################################################
echo "Set the values for the 'ldap-auth-config' Installer"
# LDAP-Server
echo "ldap-auth-config ldap-auth-config/ldapns/ldap-server string
$ldapserver:390" | debconf-set-selections
# Distinguished Name (baseDN)
echo "ldap-auth-config ldap-auth-config/ldapns/base-dn string $basedn"
| debconf-set-selections
# LDAP version
echo "ldap-auth-config ldap-auth-config/ldapns/ldap_version select 3"
| debconf-set-selections
# Local Database Root
echo "ldap-auth-config ldap-auth-config/dbrootlogin boolean true" |
debconf-set-selections
# No database login requiered
echo "ldap-auth-config ldap-auth-config/dblogin boolean false" |
debconf-set-selections
# LDAP root-Account
echo "ldap-auth-config ldap-auth-config/rootbinddn string $rootdn" |
debconf-set-selections
# LDAP-root Passwd
echo "ldap-auth-config ldap-auth-config/bindpw password $passwort" |
debconf-set-selections
echo "ldap-auth-config ldap-auth-config/rootbindpw password $passwort"
| debconf-set-selections
######################################################################
######################################################################




######################################################################
######################################################################
# Install the packages for ldap
######################################################################

# Install ldap-auth-config and nscd
echo "Installing 'ldap-auth-config' and 'nscd'"
apt-get install -y ldap-auth-config nscd

# Setup nss
echo "Setting up nss"
auth-client-config -t nss -p lac_ldap

# Restart ldap and nss
echo "Restarting the'libnss-ldap' and 'nscd' daemons"
/etc/init.d/libnss-ldap restart
/etc/init.d/nscd restart
######################################################################
######################################################################



######################################################################
######################################################################
# Set up the NFS mounts for /home
######################################################################
# Install NFS-common
echo "Installing 'nfs-common'"
apt-get install -y nfs-common

# Establish the fstab entry...
fstabEintrag="$ldapserver:/home /home nfs rw 0 0"

# Test whether a corresponding entry in the /etc/fstab file has
already been created
if grep -Exq "$ldapserver:/home[[:space:]]+/home[[:space:]]+nfs[[:space:]]+rw[[:space:]]+0[[:space:]]+0[[:space:]]*"
/etc/fstab ||
#Oder, ob home schon Mountpunkt ist
grep -Exq ".+:/.+[[:space:]]+/home[[:space:]]+.*" /etc/fstab
then
echo "Mount point"
echo "$fstabEintrag"
echo "already exists."
else
echo "Adding $fstabEintrag to /etc/fstab"
cp /etc/fstab /etc/fstab.orig
echo $fstabEintrag >> /etc/fstab
fi


#Test whether the NFS server exports the home directories

if showmount -e $ldapserver | grep -Ex "/home[[:space:]]+.*"
then
echo "Mounting home"
mount -a
else
echo "The host $ldapserver did not export the /home directory"
echo "You need to install 'nfs-kernel-server' and put an entry"
echo "for /home in /etc/exports"
fi;
######################################################################
######################################################################



######################################################################
# Add other shares under /shared
######################################################################
mkdir /shared                    # Make the shared directory
# Establish the fstab entry...
fstabshared="$ldapserver:/shared /shared nfs rw 0 0"

# Test whether a corresponding entry in the /etc/fstab file has
already been created
if grep -Exq "$ldapserver:/shared[[:space:]]+/shared[[:space:]]+nfs[[:space:]]+rw[[:space:]]+0[[:space:]]+0[[:space:]]*"
/etc/fstab ||
#Oder, ob home schon Mountpunkt ist
grep -Exq ".+:/.+[[:space:]]+/home[[:space:]]+.*" /etc/fstab
then
echo "Mount point"
echo "$fstabshared"
echo "already exists."
else
echo "Adding $fstabshared to /etc/fstab"
cp /etc/fstab /etc/fstab.orig1
echo $fstabshared >> /etc/fstab
fi
#Test whether the NFS server exports the shared directories

if showmount -e $ldapserver | grep -Ex "/shared[[:space:]]+.*"
then
echo "Mounting /shared"
mount -a
else
echo "The host $ldapserver did not export the /shared directory"
echo "You need to install 'nfs-kernel-server' and put an entry"
echo "for /shared in /etc/exports"
fi;
######################################################################
######################################################################


######################################################################
######################################################################
# Set up LightDM to use ldap
######################################################################
echo "Fixing the log-in screen"
echo ""
cp /etc/lightdm/lightdm.conf /etc/lightdm/lightdm.conf.orig
if grep -Exq "greeter-hide-users=.*" /etc/lightdm/lightdm.conf
then
sed -i '/greeter-hide-users=.*/d' /etc/lightdm/lightdm.conf
fi
echo "greeter-hide-users=true" >= /etc/lightdm/lightdm.conf
######################################################################
######################################################################


######################################################################
######################################################################
# Set up CUPS
######################################################################
# CUPS defaults to not showing printers shared by other systems. In
order to show the printers from the server, we need to modify
/etc/cups/cupsd.conf and create /etc/cups/client.conf
# This script needs to create /etc/cups/client.conf and add the line
# ServerName $ldapserver
#
# In /etc/cups/cupsd.conf this script needs to change the line
# Browsing Off
# to
# Browsing On
######################################################################
######################################################################


######################################################################
######################################################################
# Set up SANE
######################################################################
# We want the workstations to pick up any scanners shared out via
saned on the server.  To do that, we need to make changes in
/etc/sane.d/net.conf
# First, we need to find the line that reads "## saned hosts" and
append the line "$ldapserver" after that line
# Second, we need to find the line that reads "# connect_timeout = 60"
and replace it with "connect_timeout = 60"
#
######################################################################



######################################################################
######################################################################
echo  "Configuration completed. Try"
echo  "su <user on the ldap server>"
echo  "to log in with a user of the LDAP server."
######################################################################
######################################################################



######################################################################
######################################################################
# Set up additional software repositories for our standard workstation
######################################################################
# This will set up additional repositories for the workstations and
install the packages to those workstations

# Enable partner repositories
echo "Enabling Partner Repositories" &&
sed -i "/^# deb .*partner/ s/^# //" /etc/apt/sources.list

# Add the videolan repo
echo "Enabling VideoLAN repository"
add-apt-repository -y ppa:videolan/stable-daily

# Add the rhythmbox repo
echo "Enabling Rhythmbox repository"
add-apt-repository -y ppa:webupd8team/rhythmbox

# Add the gimp repo
echo "Enabling GNU Image Manipulation Program (GIMP) repository"
add-apt-repository -y ppa:otto-kesselgulasch/gimp

# Chrome
echo "Enabling Google Chrome repository"
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub |
sudo apt-key add -
sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main"
>> /etc/apt/sources.list.d/google-chrome.list'

######################################################################
######################################################################



######################################################################
######################################################################
# Download and install our standard workstation packages...
######################################################################
# This will set up additional repositories for the workstations and
install the packages to those workstations

echo "Updating package lists..."
apt-get -qq update
echo "Upgrading existing packages to the latest versions..."
apt-get upgrade


# Make Human
# No repo for this, need to download and install dep package
# http://download.tuxfamily.org/makehuman/releases/makehuman_1.0.alpha.8.rc1/makehuman_1.0.alpha.8.rc1_all.deb

apt-get install google-chrome-stable vlc gimp gimp-data
gimp-plugin-registry gimp-data-extras

echo "Cleaning Up"
apt-get -f install
apt-get autoremove
apt-get -y autoclean
apt-get -y clean


More information about the Discuss mailing list