Duinsoft - Linux
Friday, 29 March 2024      | home | tools | contact

Functions

This page contains information about a number of non-trivial bash shell functions I use in my scripts. Providing this info here is both for my own benefit as well as for others'. A listing of the actual code of a function can be called up by clicking the function name in the title. Smaller functions the main functions depend on are usually included in the listing.

CheckReferencePackages
top

This function needs a string variable listing packages and files. For example:
	ReferencePackages='
	lightdm,/etc/lightdm/lightdm.conf
	lightdm-gtk-greeter,/etc/lightdm/lightdm-gtk-greeter.conf
	solydk-info:amd64,/etc/lsb-release
	solydk-info:amd64,/etc/solydxk/info
	solydk-info:i386,/etc/lsb-release
	solydk-info:i386,/etc/solydxk/info
	solydk-system-adjustments,/DEBIAN/postinst
	solydk-system-adjustments,/DEBIAN/prerm
	solydk-system-adjustments,/boot/grub/grubbg.png
	solydk-system-adjustments,/etc/solydxk/adjustments/15-solydk-sound.overwrite
	solydk-system-adjustments,/etc/solydxk/adjustments/20-solydk.overwrite
	solydk-system-adjustments,/etc/xdg/autostart/xhost-plus.desktop
	solydk-system-adjustments,/usr/bin/configure-theme
	'

The function first compares the version of the package with the current one in the cache. If this is newer, it will download the new version, unpack it and compare the file(s) listed. The fact a file has changed will be reported, and the differences are shown in the log file.

Process
top

The Process function takes a string (variable) with whitespace separated items in the basic format command=package[,...]. An example (not a realistic one, i.e. this combination of actions does not really make sense):

	ProcessActions='
	purge=^live-*
	remove=cups-pdf,softwaremanager
	:install=+[Wheezy:lightdm,libjpeg-turbo-progs],solyd[DE]-system-adjustments
	purge=+[!Wheezy:libhal1,hal-info]
	k)install=+[Wheezy:gufw],kuser
	kee)purge=kcm-ufw
	reinstall=solydxk-welcome,solyd[DE]-system-adjustments-[RELNEW],solydxk-system
	x)install=!r;gnome-packagekit
	hold=live-boot=5.0~a3-1,live-boot-initramfs-tools=5.0~a3-1
	replace-conf=bash;/etc/bash.bashrc;/etc/skel/.bashrc
	reconfigure=grub-pc
	reconfigure=grub-efi-amd64
	reconfigure=grub-efi-ia32
	'

The commands available are: install, reinstall, upgrade, remove, purge, hold, replace-conf and reconfigure. Only reconfigure is limited to one package name as argument. The others can have multiple arguments, separated by commas. An item must not contain whitespace.
The difference between reinstall and install is that the first uses apt-get install with the --reinstall switch. Upgrade is essentially the same as install.

Several qualifiers may be added. If the command starts with k), k8), k9), k10), k_), kee), x), x8), x9), x10), x_) or xee), it will only be executed in the specified environment (k=KDE, x=Xfce). The numbers specify the SolydXK release required and ee means Enthusiast's Edition only and _ main edition only. Following that, a colon at the start of a command makes the function add some dpkg force options, e.g. ignoring dependency problems.

A +[ sequence following the equals sign signals a variable dependent command, i.e. +[Control:names,of,packages]. The packages can be specified directly or in a variable. They will only be handled if the control variable exists (or not, with +[! instead of +[).
If a package name contains the literal [DE], the code (k or x) for the desktop environment will replace it. Similarly, [RELOLD] and [RELNEW] will be replaced with the old and new release numbers (for the main edition, currently 8 and 9 respectively - 9 and 10 for an EE).

If a package must be installed without the additional packages its control file recommends, the three characters !r; must precede its name.

To force replacing a package's configuration files (replace-conf command), add a (semi-colon separated) list of files to be replaced after the package name and a semi-colon.

Package names can have a trailing equals sign plus version number, e.g. for downgrading (with the install command) or forcibly holding a package at that version (this can include up or downgrading). In case of a hold, the required package must be/remain available in one of the repositories used and this must have a higher priority than all others.

If a package name has a trailing colon, the command will only handle the package for the foreign architecture. This option cannot be combined with specifying the version number.

While most commands are processed by apt-get, the reconfigure command is short for dpkg-reconfigure. Reconfiguring a package will only happen if the package in question is actually installed by the way, so listing all kinds of different grub packages, as is done in the example above, should be fine.