#!/bin/sh

## live-debconfig(7) - System Configuration Scripts
## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##
## The complete text of the GNU General Public License
## can be found in /usr/share/common-licenses/GPL-3 file.


set -e

# Setup local debconf
if [ ! -e /var/lib/live/debconfig ]
then
	mkdir -p /var/lib/live/debconfig
	chmod 0700 /var/lib/live/debconfig
fi

if [ ! -e /var/lib/live/debconfig/systemrc ]
then

cat > /var/lib/live/debconfig/systemrc << EOF
Config: configdb
Templates: templatedb

Name: config
Driver: File
Mode: 644
Reject-Type: password
Filename: /var/lib/live/debconfig/config.dat

Name: passwords
Driver: File
Mode: 600
Backup: false
Required: false
Accept-Type: password
Filename: /var/lib/live/debconfig/passwords.dat

Name: configdb
Driver: Stack
Stack: config, passwords

Name: templatedb
Driver: File
Mode: 644
Filename: /var/lib/live/debconfig/templates.dat
EOF

fi

if [ "${1}" = "--noscripts" ]
then
	exit
fi

# Run debconf scripts
for _SCRIPT in /lib/live/debconfig/*
do
	if [ -x "${_SCRIPT}" ]
	then
		# FIXME: make scripts a multiselect
		"${_SCRIPT}"
	fi
done
