summaryrefslogtreecommitdiff
path: root/auto/functions/compat
blob: 25a4a715c70186f5c410f9b6131bd7d356b0496d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
export LB_VERSION=$VERSION
export LB_BASE="${LB_BASE:-/usr/share/live/build}"

current_script="$(basename "$0"|sed 's/^lb_//')"

Compat_arguments ()
{
	while [ "$#" -gt 0 ]
	do
		arg="$1"
		shift
		case "$arg" in
		-r|--repositories) arg="--archives";;
		--architecture) arg="--architectures";;
		--syslinux-theme) ;;
		# ignore other unsupported arguments
		--syslinux-*|--bootstrap-config|-e|--encryption|-l|--language) shift; continue;;
		--binary-indices|--packages|--symlinks|--sysvinit|--tasks|--virtual-root-size) shift; continue;;
		--packages-lists|--package-lists|-p) Compat_packagelists $1; shift; continue;;
		esac
		echo -n "$arg$IFS"
	done
}

Compat_config ()
{
[ -e config/chroot ] && [ "$LB_ARCHIVES" ] && cat <<eof >> config/chroot

# Compat (Live-build 2 -> 3)
LB_REPOSITORIES="$LB_ARCHIVES"
LB_PACKAGES_LISTS="$LB_PACKAGE_LISTS"
eof
[ -e config/bootstrap ] && [ "$LB_ARCHITECTURES" ] && cat <<eof >> config/bootstrap

# Compat (Live-build 2 -> 3)
LB_ARCHITECTURE="$LB_ARCHITECTURES"
eof
}

Compat_dir ()
{
	dir2="$1"
	dir3="$2"
	ext2="$3"
	ext3="$4"
	[ ! -e "config/$dir2" ] && return 0
	if [ -z "$ext2$ext3" ]; then
		rm -r "config/$dir3"
		ln -s "$(basename "$dir2")" "config/$dir3"
	else
		mkdir -p config/$dir3
		for i in config/$dir2/*
		do
			[ ! -e "$i" ] && return
			target="$(basename "$i" $ext2)$ext3"
			rm -f config/$dir3/"$target"
			if [ -d "$i" ]; then
				ln -s "../../../$i" /config/$dir3/"$target"
			else
				cp -l "$i" config/$dir3/"$target"
			fi
		done
	fi
	touch config/$dir3.compat
}

Compat_packagelists()
{
	mkdir -p config/package-lists
	(
		echo '# AUTOGENERATED from "lb config -p" option - DO NOT CHANGE'
		IFS=" "
		for packagelist in $1
		do
			echo "#include <$packagelist>"
		done
	) > config/package-lists/compat.list.chroot
}

Compat_clean()
{
	for i in config/*.compat
	do
		[ -e "$i" ] || return 0
		target="$(basename "$i" .compat)"
		[ -e config/$target ] || continue
		rm -r config/$target
		rm "$i"
	done
	return 0
}

case "$LB_VERSION" in
3*)
	case "$current_script" in
	config)
		if [ -z "$LB_COMPAT_CONFIG_AUTO" ]; then
			export LB_COMPAT_CONFIG_AUTO=1
			auto/config "$@"
			exit $?
		fi
		OIFS="$IFS"; IFS="$(printf \\a)"
		set -- $(Compat_arguments "$@")
		IFS="$OIFS"
		[ -z "$LB_ARCHIVES" ] && LB_ARCHIVES="$LB_REPOSITORIES"
		LB_REPOSITORIES="$LB_ARCHIVES" 
		[ -z "$LB_PACKAGE_LISTS" ] && LB_PACKAGE_LISTS="$LB_PACKAGES_LISTS"
		LB_PACKAGES_LISTS="$LB_PACKAGE_LISTS"
		[ -z "$LB_ARCHITECTURES" ] && LB_ARCHITECTURES="$LB_ARCHITECTURE"
		LB_ARCHITECTURE="$LB_ARCHITECTURES"
		trap Compat_config EXIT
		;;
	chroot_apt)
		Compat_dir chroot_local-packages packages.chroot
		;;
	chroot_archives)
		mkdir -p config/archives
		touch config/archives.compat
		. config/bootstrap
		for REPO in $LB_ARCHIVES
		do
			for i in config/repositories/$REPO config/repositories/$REPO.gpg
			do
				[ ! -e "$i" ] && continue
				case "$i" in
				*.gpg) target="$(basename "$i" .gpg).key";;
				*) target="$(basename "$i" .list).list";;
				esac
				rm -f config/archives/"$target"
				cp -l "$i" config/archives/"$target"
			done
		done
		;;
	chroot_preseed)
		Compat_dir chroot_local-preseed preseed .cfg .preseed
		;;
	chroot_includes)
		Compat_dir chroot_local-includes includes.chroot
		;;
	chroot_hooks)
		Compat_dir chroot_local-hooks hooks - .chroot
		;;
	binary_hooks)
		Compat_dir binary_local-hooks hooks - .binary
		;;
	build|clean)
		trap Compat_clean EXIT
		;;
	esac
	[ -d config/lists ] && . auto/compat
	;;
esac