# Generated from system-config-keyboard's model list
# consolelayout		xlayout	xmodel		xvariant	xoptions
sg			ch	pc105		de_nodeadkeys	terminate:ctrl_alt_bksp
nl			nl	pc105		-		terminate:ctrl_alt_bksp
mk-utf			mk,us	pc105		-		terminate:ctrl_alt_bksp,grp:shifts_toggle,grp_led:scroll
trq			tr	pc105		-		terminate:ctrl_alt_bksp
uk			gb	pc105		-		terminate:ctrl_alt_bksp
is-latin1		is	pc105		-		terminate:ctrl_alt_bksp
de			de	pc105		-		terminate:ctrl_alt_bksp
la-latin1		latam	pc105		-		terminate:ctrl_alt_bksp
us			us	pc105+inet	-		terminate:ctrl_alt_bksp
ko			kr	pc105		-		terminate:ctrl_alt_bksp
ro-std			ro	pc105		std		terminate:ctrl_alt_bksp
de-latin1		de	pc105		-		terminate:ctrl_alt_bksp
slovene			si	pc105		-		terminate:ctrl_alt_bksp
hu101			hu	pc105		qwerty		terminate:ctrl_alt_bksp
jp106			jp	jp106		-		terminate:ctrl_alt_bksp
croat			hr	pc105		-		terminate:ctrl_alt_bksp
it2			it	pc105		-		terminate:ctrl_alt_bksp
hu			hu	pc105		-		terminate:ctrl_alt_bksp
sr-latin		rs	pc105		latin		terminate:ctrl_alt_bksp
fi			fi	pc105		-		terminate:ctrl_alt_bksp
fr_CH			ch	pc105		fr		terminate:ctrl_alt_bksp
dk-latin1		dk	pc105		-		terminate:ctrl_alt_bksp
fr			fr	pc105		-		terminate:ctrl_alt_bksp
it			it	pc105		-		terminate:ctrl_alt_bksp
ua-utf			ua,us	pc105		-		terminate:ctrl_alt_bksp,grp:shifts_toggle,grp_led:scroll
fr-latin1		fr	pc105		-		terminate:ctrl_alt_bksp
sg-latin1		ch	pc105		de_nodeadkeys	terminate:ctrl_alt_bksp
be-latin1		be	pc105		-		terminate:ctrl_alt_bksp
dk			dk	pc105		-		terminate:ctrl_alt_bksp
fr-pc			fr	pc105		-		terminate:ctrl_alt_bksp
bg_pho-utf8		bg,us	pc105		,phonetic	terminate:ctrl_alt_bksp,grp:shifts_toggle,grp_led:scroll
it-ibm			it	pc105		-		terminate:ctrl_alt_bksp
cz-us-qwertz		cz,us	pc105		-		terminate:ctrl_alt_bksp,grp:shifts_toggle,grp_led:scroll
br-abnt2		br	abnt2		-		terminate:ctrl_alt_bksp
ro			ro	pc105		-		terminate:ctrl_alt_bksp
us-acentos		us	pc105		intl		terminate:ctrl_alt_bksp
pt-latin1		pt	pc105		-		terminate:ctrl_alt_bksp
ro-std-cedilla		ro	pc105		std_cedilla	terminate:ctrl_alt_bksp
tj_alt-UTF8		tj	pc105		-		terminate:ctrl_alt_bksp
de-latin1-nodeadkeys	de	pc105		nodeadkeys	terminate:ctrl_alt_bksp
no			no	pc105		-		terminate:ctrl_alt_bksp
bg_bds-utf8		bg,us	pc105		-		terminate:ctrl_alt_bksp,grp:shifts_toggle,grp_led:scroll
dvorak			us	pc105		dvorak		terminate:ctrl_alt_bksp
dvorak			us	pc105		dvorak-alt-intl	terminate:ctrl_alt_bksp
ru			ru,us	pc105		-		terminate:ctrl_alt_bksp,grp:shifts_toggle,grp_led:scroll
cz-lat2			cz	pc105		qwerty		terminate:ctrl_alt_bksp
pl2			pl	pc105		-		terminate:ctrl_alt_bksp
es			es	pc105		-		terminate:ctrl_alt_bksp
ro-cedilla		ro	pc105		cedilla		terminate:ctrl_alt_bksp
ie			ie	pc105		-		terminate:ctrl_alt_bksp
et			ee	pc105		-		terminate:ctrl_alt_bksp
sk-qwerty		sk	pc105		-		terminate:ctrl_alt_bksp,qwerty
sk-qwertz		sk	pc105		-		terminate:ctrl_alt_bksp
fr-latin9		fr	pc105		latin9		terminate:ctrl_alt_bksp
fr_CH-latin1		ch	pc105		fr		terminate:ctrl_alt_bksp
cf			ca	pc105		-		terminate:ctrl_alt_bksp
sv-latin1		se	pc105		-		terminate:ctrl_alt_bksp
sr-cy			rs	pc105		-		terminate:ctrl_alt_bksp
gr			gr,us	pc105		-		terminate:ctrl_alt_bksp,grp:shifts_toggle,grp_led:scroll
by			by,us	pc105		-		terminate:ctrl_alt_bksp,grp:shifts_toggle,grp_led:scroll
il			il	pc105		-		terminate:ctrl_alt_bksp
kazakh			kz,us	pc105		-		terminate:ctrl_alt_bksp,grp:shifts_toggle,grp_led:scroll
lt.baltic		lt	pc105		-		terminate:ctrl_alt_bksp
lt.l4                  lt	pc105		-		terminate:ctrl_alt_bksp
lt			lt	pc105		-		terminate:ctrl_alt_bksp
khmer			kh,us	pc105		-		terminate:ctrl_alt_bksp
#! /bin/bash
#
# This is used to initially create /var/lib/machines subvolume in case
# the system we're running on is using BTRFS with the specific layout
# used by snapper to perform snapshots, rollbacks, etc...
#
# Unfortunately some distros (TW) already shipped versions with
# systemd creating a plain subvolume which breaks snapper.
#
# If /var/lib/machines is already populated then it's going to be
# pretty ugly to convert the old subvolume into a new one specially
# since it can be in use.
#
# Hopefully not a lot of users are using machinectl to import
# container/VM images. So in most of the cases this directory should
# be empty and we can then simple delete the subvolume and create a
# new one respecting the snapper layout.
#
# In the rare case where /var/lib/machines is populated, we will warn
# the user and let him fix it manually.
#
# In order to avoid ugly dependencies added in systemd package, this
# script should only be called during package updates when
# mksubvolume(8) is available. During installation, /var/lib/machines
# is supposed to be created by the installer now.
#
# See bsc#992573
#

warn() {
	echo >&2 "warning: $@"
}

is_btrfs_subvolume() {
	# On btrfs subvolumes always have the inode 256
	test $(stat --format=%i "$1") -eq 256
}

# This assumes the directory/subvol is emptied by the caller.
rm_subvolume_or_directory() {
	is_btrfs_subvolume "$1" && {
		btrfs subvolume delete "$1"
		return
	}
	rmdir "$1"
}

on_exit() {
	# Simply print a common error message in case something went
	# wrong.
	if test $? -ne 0; then
		warn "Please fix /var/lib/machines manually."
		# FIXME: point to a documentation explaining how to do
		# that.
		exit 1
	fi
}

#
# If something is already mounted don't try to fix anything, the
# subvolume has already been created by either mksubvolume(8) or by
# the admin. In the later case we don't want to screw up his setup.
#
if mountpoint -q /var/lib/machines; then
	exit
fi

#
# Let's try to figure out if the current filesystem uses a Snapper
# BTRFS specific layout. Note that TW uses a different layout than
# SLE...
#
# FIXME: not sure if it's correct, reliable or optimal.
#
case $(findmnt -nr -t btrfs -o FSROOT / 2>/dev/null) in
*.snapshots/*/snapshot*)
	;;
*)
	exit 0
esac

trap on_exit EXIT

if test -d /var/lib/machines; then
	#
	# Ok, we're on a system supporting rollbacks and
	# /var/lib/machines is not a subvolume remotely mounted so it
	# cannot be suitable for systems supporting rollback. Fix it.
	#
	echo "Making /var/lib/machines suitable for rollbacks..."

	type mksubvolume >/dev/null 2>&1 || {
		warn "mksubvolume(8) is not installed, aborting."
		exit 1
	}
	test "$(ls -A /var/lib/machines/)" && {
		warn "/var/lib/machines is not empty, aborting."
		exit 1
	}

	echo "Deleting empty /var/lib/machines directory/subvolume"
	rm_subvolume_or_directory /var/lib/machines || {
		warn "fail to delete /var/lib/machines"
		exit 1
	}
fi

# At this point /var/lib/machines shouldn't exist.
echo "Creating /var/lib/machines subvolume suitable for rollbacks."
mksubvolume /var/lib/machines
