Quantcast
Channel: run as me » JDK
Viewing all articles
Browse latest Browse all 17

Customizing LIbreOffice 4.x for Windows Deployment

$
0
0

After LibreOffice 3.5, there are a lot of additional customizations in the MSI installer[1].

What you Can Customize from the MSI

We run a mix of MS Office and LibreOffice for the TS/RDS servers, so the interop format is legacy Microsoft formats (doc, xls, etc) rather than ODF (which can work in MS products but is a bit of a cultural adjustment).

The following parameters sets the file associations and disables auto updating.

msiexec /qb /i LibreOffice_4.1.5_Win_x86.msi /l* LibO_install_log-%date:~-4,4%%date:~-10,2%%date:~-7,2%-%time:~-11,2%%time:~-8,2%%time:~-5,2%.txt ALLUSERS=1 ISCHECKFORPRODUCTUPDATES=0 SELECT_WORD=1 SELECT_EXCEL=1 SELECT_POWERPOINT=1 REGISTER_ALL_MSO_TYPES=1 HideEula=1 ADDLOCAL=ALL REMOVE=gm_o_Onlineupdate

You can find most of the common MSI table settings:

Setting Default Save As (not possible via MSI)

We also needed to stage the install so users (by default) would save files as the MS formats rather than ODF — not just the file associations.

Unfortunately, this is not possible through the MSI and there appear to be no properties while viewing the MSI tables in Orca that seem relevant.

Essentially, under LIBREOFFICEINSTALLDIR\share\registry you will find *.xcd files which contain many XML files for basic settings — including the default save as format for each program.

Each application hill have its own file in the directory to which we will change the element as follows:

<prop oor:name="ooSetupFactoryDefaultFilter"><value>PROGRAM NAME</value>

Here are some of the default values and the values we’ll be changing them to.

  • calc.xcd : calc8 -> MS Excel 97
  • impress.xcd : impress8 -> MS Powerpoint 97
  • writer.xcd : writer8 -> MS Word 97

You can actually do this change via an administrative install ahead of time rather than having to make modifications via a user script afterwards.

Automating via Powershell. – Stage-LibreOffice.ps1

The following script can be pointed at a libreoffice MSI. It will create an administrative install and make the modifications to the “registry” XML files and drop in an INSTALL-LIBRE.bat which has pre-set parameters. Make sure the INSTALL-LIBRE.bat template is in the same directory as the script.

param(
	[string]$msi,
	[string]$copyTo="",
	[string]$testDefaultSaveAsFix="",
	[switch]$skipSaveAsFix
)

$currentScriptPath = Split-Path ((Get-Variable MyInvocation -Scope 0).Value).MyCommand.Path
Push-Location $currentScriptPath

if (!$msi -and !$testDefaultSaveAsFix) {
	write-warning 'Specify a MSI file.'
	EXIT
}

function Replace-DefaultSaveAs {
param(
	[string]$name,
	[string]$currValue,
	[string]$newValue,
	[string]$regLocation,
	[string]$backupXmlPath
)

	$xmlFile = "$regLocation\$name.xcd"
	if (Test-Path $xmlFile) {
		write-host "Reading $xmlFile" -foregroundcolor magenta
		#$buffer = gc $xmlFile
		$encoding = New-Object System.Text.ASCIIEncoding # try to always declare your encoding with file.readalltext
		$buffer = [system.io.file]::ReadAllText((Resolve-Path $xmlFile).ProviderPath, $encoding)
		$currValueElement = "<prop oor:name=`"ooSetupFactoryDefaultFilter`"><value>$currValue</value>"
		$newValueElement = "<prop oor:name=`"ooSetupFactoryDefaultFilter`"><value>$newValue</value>"
		write-host "Replacing default save as element" -foregroundcolor gray

		if ($buffer.Contains($currValueElement)) {
			$newXml = $buffer.Replace($currValueElement,$newValueElement)

			$xmlFileName = $xmlFile.Name
			$backupXmlPathTs = "$backupXmlPath\xmlbackups-$(Get-Date -f 'yyyyMMddHHmmss')"
			md $backupXmlPathTs -force | out-null

			write-host "Backing up file $xmlFileName to $backupXmlPathTs" -foregroundcolor gray

			move-item -path $xmlFile -destination "$backupXmlPathTs\$xmlFileName"

			write-host "Saving $xmlFile" -foregroundcolor gray
			$newXml | sc -path $xmlFile
		} else {
			write-warning "Could not find $currValueElement in the file"
		}
	} else {
		write-warning "Could not find file - $xmlFile"
	}
}

# http://listarchives.libreoffice.org/global/users/msg12888.html
if (!$testDefaultSaveAsFix) {
	if (!(Test-Path $msi)) {
		write-warning "Could not find file $msi"
		exit
	}

	$msiFullPath = (gi $msi).FullName
	$msiFileName = (gi $msi).Name

	$extractLocation = "$currentScriptPath\$msiFileName-$(Get-Date -f 'yyyyMMddHHmmss')"
	md $extractLocation -force | out-null
	write-host "Extracting MSI to $extractLocation" -foregroundcolor green
	cmd /c "msiexec /a $msiFullPath /qb TARGETDIR=$extractLocation"
	if (!$? -or ($LASTEXITCODE -ne 0)) {
		write-warning "ISSUE WITH MSIEXEC - Last Exit Code = $LASTEXITCODE"
		exit
	} else {
		write-host "Extractiong went OK?" -foregroundcolor green
	}

	$registryLocation = "$extractLocation\share\registry"
	write-host "Attempting to change XML configs to set default save as format..." -foregroundcolor green
} else {
	if (Test-Path $testDefaultSaveAsFix) {
		$extractLocation = $testDefaultSaveAsFix
		$registryLocation = "$testDefaultSaveAsFix\share\registry"
	} else {
		write-warning "$testDefaultSaveAsFix is not a valid path."
		exit
	}
}

if (!$skipSaveAsFix) {
	#writer
	Replace-DefaultSaveAs -name 'writer' -currValue 'writer8' -newValue 'MS Word 97' -regLocation $registryLocation -backupXmlPath $extractLocation

	#calc
	Replace-DefaultSaveAs -name 'calc' -currValue 'calc8' -newValue 'MS Excel 97' -regLocation $registryLocation -backupXmlPath $extractLocation

	#impress
	Replace-DefaultSaveAs -name 'impress' -currValue 'impress8' -newValue 'MS PowerPoint 97' -regLocation $registryLocation -backupXmlPath $extractLocation

	if ($testDefaultSaveAsFix) {
		exit
	}
} else {
	write-host "skipping save as changes." -foregroundcolor green
}

#drop in bat file
$batFileTemplate = "INSTALL-LIBRE.bat"
write-host "Creating $batFileTemplate with proper install parameters" -foregroundcolor green
$batFileBuffer = gc ".\$batFileTemplate"
$newBatFile = $batFileBuffer.Replace("LIBREMSIFILE",$msiFileName)
$newBatFile | sc -path "$extractLocation\$batFileTemplate"

#copy files
if ($copyTo) {
	if (Test-Path $copyTo) {
		$srcFolderName = (gi $extractLocation).Name
		$dest = "$copyTo\$srcFolderName" 
		md $dest -force | out-null
		robocopy $extractLocation $dest /e /mt /w:2 /r:2 /xj
	} else {
		write-warning "$copyTo is not a valid location."
	}
}

an example INSTALL-LIBRE.bat

rem comments comments comments
Pushd "%~dp0"
msiexec /qb /i LIBREMSIFILE /l* LibO_install_log-%date:~-4,4%%date:~-10,2%%date:~-7,2%-%time:~-11,2%%time:~-8,2%%time:~-5,2%.txt ALLUSERS=1 ISCHECKFORPRODUCTUPDATES=0 SELECT_WORD=1 SELECT_EXCEL=1 SELECT_POWERPOINT=1 REGISTER_ALL_MSO_TYPES=1 HideEula=1 ADDLOCAL=ALL REMOVE=gm_o_Onlineupdate

Viewing all articles
Browse latest Browse all 17

Trending Articles