[Server-devel] Server-devel Digest, Vol 75, Issue 25

Tony Anderson tony at olenepal.org
Fri Aug 2 06:02:14 EDT 2013


On 08/01/2013 06:33 PM, Sameer Verma wrote:
> On Mon, Jul 29, 2013 at 11:33 PM, Tony Anderson<tony at olenepal.org>  wrote:
>> >Hi,
>> >
>> >As I have unsuccessfully tried to explain many times. OLE Nepal, with help
>> >from Daniel Drake, an effective and proven means to add selected
>> >capabilities
>> >to the base server. Since this capability takes advantage of the running
>> >base
>> >server, all of its normal system administration capabilities are available
>> >(ssh,
>> >yum, etc.).
>> >
> This is true, but not documented well and not known. For instance, we
> use munin and openvpn on the XS 0.7 in Jamaica, and those are
> "add-ons". It would be good to document this and discuss approaches
> for installing complementary services.

The process is straightforward.

At install time, the script xs-custom is executed.

#!/bin/bash
cp 20-xc-generic /etc/usbmount/mount.d
cp path.py /usr/lib/python2.6/site-packages
python fixssh.py
adduser -padmin admin
xs-setup domain
poweroff

It installs a modified version of Daniel Drake's script 20-xc-generic 
which will be executed when a removable drive is mounted.
It puts path.py (a utility I use in many python cgi-scripts).
It executes a script fixssh.py which enables password authentication.
Finally, it adds user admin with password admin.
The xs-setup script is executed to complete the process.
The poweroff is a clear signal when the script is finished and forces a 
reboot.

The 20-xc-generic script is attached. It checks the removable device for 
a root folder
XC. If this exists, it checks for a script in that folder 'xc-install'. 
If so, it is executed. This allows a usb drive or hard drive to be used 
for this install or for other purposes by renaming the XC folder (e.g. 
xc) so that it is ignored.

The fixsh.py scripts enables password authentication:

#!/usr/bin/python

test = 'PasswordAuthentication'

fin=open('/etc/ssh/sshd_config.in','r')
txt = fin.read()
fin.close()
lines = txt.split('\n')
txtout = ''
fout = open('/etc/ssh/sshd_config.in','w')
for line in lines:
     if test in line and not '#' in line:
         print >> fout, test + ' yes'
     else:
         print >> fout, line
fout.close()


This is another reason for poweroff and reboot so that 
/etc/ssh/sshd_config is also
updated.

This enables login from an XO or other PC via ssh admin at schoolserver for
system administration.

The xc-install script in XC looks like this:

#!/bin/bash
# Author: Daniel Drake <dsd at laptop.org>
# XS auto-usbmount import script for code parts of the e-library
#modified for Rwanda configuration <tony_anderson at usa.net>

set -e

VERBOSE=No

# Log a string via the syslog facility.
log()
{
         if test $1 != debug || expr "$VERBOSE" : "[yY]" > /dev/null; then
                 logger -p user.$1 -t "xc-code[$$]" -- "$2"
                 echo "$(date "+%F %T") xc-code: $2"
         fi
}

error_beep()
{
         echo -en '\033[10;1000]\033[11;100]\007' > /dev/console
         sleep 0.2
         echo -en '\033[10;1000]\033[11;100]\007' > /dev/console
         sleep 0.2
         echo -en '\033[10]\033[11]' > /dev/console
         return 0
}

UM_MOUNTPOINT="/media/usb0"

cd "$UM_MOUNTPOINT"/XC
if [ -f xc-wiki/xc-wiki4schools-install ]; then
         log notice "Installing Wiki4Schools"
         cd xc-wiki
         if bash xc-wiki4schools-install; then
             log notice "wiki4schools installed successfully"
         else
             log notice "wiki4schools install failed with code $?"
             error beep
         fi
else
         log notice 'xc-wiki not found'

It normally has several of these install sections. The install section 
looks for a
folder: xc-wiki and in that folder for an install script: 
xc-wiki4schools-install.
The contents of the folder are:

wiki.conf
xc-wiki4schools-install
xc-wiki4schools.tar.gz
xc-wiki4schools.tar.gz.sha1

The xc-wiki4schools-install is:

#!/bin/bash

wktar=xc-wiki4schools.tar.gz

log() {
     logger -p user.notice -t nexc-wiktionary-inst -s -- "$1"
}

cp wiki.conf /etc/httpd/conf.d

rm -rf /library/wiki
mkdir -p /library/wiki

cp $wktar /library/wiki
cd /library/wiki

if ! tar -xzf $wktar; then
         log "could not extract $wktar"
         exit 1
fi

rm -rf /library/wiki/$wktar

chown -R apache:apache /library/wiki
chmod -R 755 /library/wiki

This script installs wiki.conf in /etc/httpd/conf.d, makes a folder 
/library/wiki,
copies the tarball to this folder and extracts it there. The tarball is 
removed and
permissions set. Note that the script removes previous content so that 
it can
be rerun.

The wiki.conf file is:

Alias /wiki4schools/ /library/wiki/
<Directory /library/wiki>
Order deny,allow
Allow from all
</Directory>

This makes the wiki accessible via: http://schoolserver/wiki4schools/.


For simplicity, each folder in XC has this style. For example, xc-moodle 
installs
the Moodle courses and so on. If xc-moodle is renamed to xcc-moodle, it 
gets
ignored by xc-install. This way a deployment can select which packages 
or bundles to install.

As you can see bash scripting or python scripting works fine. The only 
really tricky
part is to make sure the bundles are self-contained as many school 
servers have no internet access.

Tony
>

-------------- next part --------------
#!/bin/bash
# Author: Daniel Drake <dsd at laptop.org>
# XS auto-usbmount import script for code parts of the e-library
#modified for Rwanda configuration <tony_anderson at usa.net>
# execute XC-install if found
set -e

VERBOSE=no

# Log a string via the syslog facility.
log()
{
	if test $1 != debug || expr "$VERBOSE" : "[yY]" > /dev/null; then
		logger -p user.$1 -t "rwxc-code[$$]" -- "$2"
		echo "$(date "+%F %T") rwxc-code: $2"
	fi
}

error_beep()
{
	echo -en '\033[10;1000]\033[11;100]\007' > /dev/console
	sleep 0.2
	echo -en '\033[10;1000]\033[11;100]\007' > /dev/console
	sleep 0.2
	echo -en '\033[10]\033[11]' > /dev/console
	return 0
}

if [ -f "$UM_MOUNTPOINT"/XC/xc-install ]; then
        exec >> $UM_MOUNTPOINT/xc-usbmount.txt 2>&1
fi

if [ -f "$UM_MOUNTPOINT"/xc.*.tar.bz2 ]; then
        exec >> $UM_MOUNTPOINT/xc-usbmount.txt 2>&1
fi

if [ -f "$UM_MOUNTPOINT"/xc.*.tar.bz2 ]; then
        log notice "Updating School Server"
        rm -rf /library/update
        mkdir /library/update
        cp "$UM_MOUNTPOINT"/xc.*tar.bz2 /library/update
        cd /library/update
        tar -xvf xc.*.tar.bz2
        if bash xc-update; then
            log notice "School server updated successfully"
        else
            log notice "School server update failed with code $?"
            error_beep
        fi
fi

if [ -f "$UM_MOUNTPOINT"/XC/xc-install ]; then
	log notice "Installing XC"
	cd $UM_MOUNTPOINT/XC
	if bash xc-install; then
		log notice "XC installed successfully"
	else
		log notice "XC install failed with code $?"
		error_beep
	fi
fi


More information about the Server-devel mailing list