Post DAB Error

apmuthu

Well-Known Member
Feb 26, 2009
807
8
58
Chennai - India & Singapore
github.com
On only one (#! /bin/sh) script (using the hostname as "wiki") - the Post DAB setup script (the one executed on first boot of the VM) at:
Code:
HOSTNAME=`head -n 1 /etc/hostname|awk '{ print $1; }'`

if [ "X${HOSTNAME}" = "Xlocalhost" ] ; then
    exit 0;
fi
I get the following error:
Code:
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..
[: 19: Xwiki: unexpected operator
Starting Postfix Mail Transport Agent: postfix.

The exit 0; is preceded with a tab as in all the other scripts.
 
I have used the same setup script to run on first boot and we get the same error - compiled in ProxMox v1.3 and in ProxMox v1.7 using DAB.

What is the command to repor the DAB version?

The v1.3 machine has:
Code:
# pveversion -v
pve-manager: 1.3-1 (pve-manager/1.3/4023)
qemu-server: 1.0-14
pve-kernel: 2.6.24-11
pve-kvm: 86-3
pve-firmware: 1
vncterm: 0.9-2
vzctl: 3.0.23-1pve3
vzdump: 1.1-2
vzprocps: 2.0.11-1dso2
vzquota: 3.0.11-1

The v1.7 machine has
Code:
# pveversion -v
pve-manager: 1.7-11 (pve-manager/1.7/5470)
running kernel: 2.6.32-4-pve
proxmox-ve-2.6.32: 1.7-30
pve-kernel-2.6.32-4-pve: 2.6.32-30
qemu-server: 1.1-28
pve-firmware: 1.0-10
libpve-storage-perl: 1.0-16
vncterm: 0.9-2
vzctl: 3.0.24-1pve4
vzdump: 1.2-10
vzprocps: 2.0.11-1dso2
vzquota: 3.0.11-1
pve-qemu-kvm: 0.13.0-3
ksm-control-daemon: 1.0-4
 
As Proxmox VE v1.7 is still based on Lenny,

# ls /bin/sh -al
Code:
lrwxrwxrwx 1 root root 4 Aug 19  2009 /bin/sh -> bash

But the Virtual machine instance is based on a Squeeze template and the setup script is executed on first boot of the Virtual machine inside it,

# ls /bin/sh -al
Code:
lrwxrwxrwx 1 root root 4 Feb 26 23:09 /bin/sh -> dash

The folowing operators yield errors:
Code:
=
==
-eq
The last one above expects a number
 
The relevant snippet from /etc/runlevel.conf is:
Code:
18 - S  /etc/init.d/ifupdown-clean
19 - 2,3,4,5  /etc/init.d/mysql
20 - 0,6  /etc/init.d/sendsigs
20 - 2  /etc/init.d/mysql_randompw
20 0,1,6 2,3,4,5  /etc/init.d/postfix
21 - 2  /etc/init.d/mediawiki_setup
21 0,1,6 -  /etc/init.d/mysql
25 0,6 -  /etc/init.d/hwclock.sh
30 - 0,6  /etc/init.d/rsyslog
30 - 0,6  /etc/init.d/urandom

Thought that dash may be broken since last 1 or 2 days.
But tried with bash as well with same error.

Manually running the snippet in question works correctly in dash.
 
Last edited:
Re: Post DAB Error - bashism?

Just did the following inside a squeeze virtual machine for a script with a shebang of -
!# /bin/sh that points to dash:
Code:
# apt-get install devscripts
# checkbashisms  /etc/init.d/mediawiki_setup
possible bashism in /etc/init.d/mediawiki_setup line 19 ($HOST(TYPE|NAME)):
if [ "X${HOSTNAME}" = "Xlocalhost" ] ; then
Any idea what may be wrong with the statement:
Code:
if [ "X${HOSTNAME}" = "Xlocalhost" ] ; then

The contents of the script in question have been reduced to just:
#cat /etc/init.d/mediawiki_setup
Code:
#! /bin/sh
set -e
HOSTNAME=`head -n 1 /etc/hostname|awk '{ print $1; }'`
if [ "X${HOSTNAME}" = "Xlocalhost" ] ; then
 exit 0;
fi
rm -f /etc/init.d/mediawiki_setup
update-rc.d -f mediawiki_setup remove
Ref: http://princessleia.com/plug/2008-JP_bash_vs_dash.pdf Slide 21
 
Last edited:
{SOLVED] Re: Post DAB Error - bashism?

It appears that for full POSIX compliance the Debian version of dash has been updated in the last 2 days so that reserved keywords should not be used or used to start variable names inside the script. The variable HOSTNAME is henceforth disallowed in Debian Squeeze as it overlaps the system variable: ($HOST(TYPE|NAME)).

The following now works:
Code:
#! /bin/sh
set -e
HNAME=`head -n 1 /etc/hostname|awk '{ print $1; }'`
if [ "X${HNAME}" = "Xlocalhost" ] ; then
 exit 0;
fi
rm -f /etc/init.d/mediawiki_setup
update-rc.d -f mediawiki_setup remove

and no bashism reported.

Hence all DAB scripts now need to have their Squeeze based template's setup files altered suitably. The Makefile is exempted for now as it is executed by DAB within Proxmox VE's Lenny.

Complete if syntax in POSIX compliant dash applicatble especially to Debian Squeeze where dash is the default sh is at:
http://www.metalshell.com/source_code/70/If_Statement.html
 
Last edited:
Re: {SOLVED] Re: Post DAB Error - bashism?

It appears that for full POSIX compliance the Debian version of dash has been updated in the last 2 days so that reserved keywords should not be used or used to start variable names inside the script. The variable HOSTNAME is henceforth disallowed in Debian Squeeze as it overlaps the system variable: ($HOST(TYPE|NAME)).

Wow - I guess that change will break many scripts. Many thanks for finding that bug (will fix it in all dab scripts we ship).

- Dietmar
 
It appears that DAB also needs to be updated to prevent such errors from seeping thru. The new template built with the fix here still throws up the same error on first boot of the appliance. The setup script if manually executed shows no error. Something to do with the way a handover from Lenny bash to squeeze dash occurs during (first) entry into the container.

Thanks for the dab commands - maybe make it to the man dab.

# dpkg -l dab
Code:
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
ii  dab            1.1-9          Debian OpenVZ Appliance Builder

# dpkg-query -p dab
Code:
Package: dab
Priority: optional
Section: admin
Maintainer: Proxmox Support Team <support@proxmox.com>
Architecture: all
Version: 1.1-9
Depends: perl (>= 5.6.0-16), wget, make, binutils, vzctl
Size: 27518
Description: Debian OpenVZ Appliance Builder
 This package contains scripts to automate the creation of openvz
 appliances.
 
Last edited:
dab_1.1-9_all.deb

\usr\lib\dab\scripts\mysql_randompw
Code:
 Line 15: HOSTNAME=`head -n 1 /etc/hostname|awk '{ print $1; }'`
 Line 17: if [ "X${HOSTNAME}" == "Xlocalhost" ] ; then
\usr\lib\dab\scripts\ssh_gen_host_keys
Code:
 Line 15: HOSTNAME=`head -n 1 /etc/hostname|awk '{ print $1; }'`
 Line 17: if [ "X${HOSTNAME}" = "Xlocalhost" ] ; then
\usr\lib\dab\scripts\init.pl
Code:
 Line 56: system ("hostname localhost") == 0 ||
 Line 57:     die "unable to set hostname\n";
The last one above is okay. The first one has a double equals sign (==) bashism that needs to be corrected as well.
 
Last edited:
Another error I had at the fag end of my script (ego trip) was:
Code:
echo Authored by Ap.Muthu <apmuthu@usa.net> courtesy GNUAcademy.org
This resulted in an abrupt end to the script with the error:
Code:
/etc/init.d/mediawiki_setup: 335: cannot open apmuthu@usa.net: No such file
It had to be corrected as:
Code:
echo Authored by Ap.Muthu \<apmuthu@usa.net\> courtesy GNUAcademy.org
and then all was well.
 
It has been common practice to use the variable PASSWD to store a randomly generated MySQL application user password or other password in the post install setup shell scripts till now. This must be eschewed in light of strict POSIX compatibility that dash demands as it is a reserved key word irrespective of it's case.

In my DAB build scripts for Squeeze, I have been using the variable UPASSWD and it would be nice to make it standard so that all post install setup scripts can be standardized with stanzas for ease of building new ones and maintaining old ones.

Thanks Dietmar for the quick update to DAB.
 
Thanks - that was fast.

Unable to update dab using apt-get update / dist-upgrade
Had to uninstall dab using
Code:
apt-get remove dab
and then:
Code:
wget [URL]ftp://download.proxmox.com/debian/dists/lenny/pvetest/binary-amd64/dab_1.1-12_all.deb[/URL]
dpkg -i dab_1.1-12_all.deb
and now

Code:
# dpkg -l dab

gives no output and

# dpkg-query -p dab
Code:
Package: dab
Priority: optional
Section: admin
Maintainer: Proxmox Support Team <[EMAIL="support@proxmox.com"]support@proxmox.com[/EMAIL]>
Architecture: all
Version: 1.1-12
Depends: perl (>= 5.6.0-16), wget, make, binutils, vzctl
Size: 27660
Description: Debian OpenVZ Appliance Builder
 This package contains scripts to automate the creation of openvz
 appliances.
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!