File: live-update-initramfs

package info (click to toggle)
live-tools 1%3A20190831.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 324 kB
  • sloc: sh: 921; makefile: 138
file content (94 lines) | stat: -rwxr-xr-x 2,574 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

# live-tools(7) - System Support Scripts
# Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
#
# This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
# This is free software, and you are welcome to redistribute it
# under certain conditions; see COPYING for details.

set -e

if [ ! -e /usr/sbin/update-initramfs.orig.initramfs-tools ]
then
	echo "E: /usr/sbin/update-initramfs.orig.initramfs-tools - command not found"
	echo "E: On Debian based systems, update-initramfs from initramfs-tools"
	echo "E: can be installed with:"
	echo "E:   apt-get install initramfs-tools"

	exit 1
fi

# system is a live system and not a system in the process of being built by live-build
if [ ! -e /.live-build ] && grep -qs "boot=live" /proc/cmdline
then
	if grep -qs "\/run\/live\/medium" /proc/mounts
	then
		# live system with live media mounted as /run/live/medium
		_DEVICE="$(awk '/\/run\/live\/medium/ { print $1 }' /proc/mounts)"

		mount -o remount,rw ${_DEVICE} > /dev/null 2>&1 || true

		if touch /run/live/medium/.test > /dev/null 2>&1
		then
			_READ_WRITE="true"

			rm -f /run/live/medium/.test
		else
			_READ_WRITE="false"
		fi
	else
		# live system without live media mounted as /run/live/medium
		echo "I: update-initramfs is disabled (live system is running without media mounted on /run/live/medium)."

		exit 0
	fi
else
	# non-live system
	/usr/sbin/update-initramfs.orig.initramfs-tools "${@}"

	exit "${?}"
fi

case "${_READ_WRITE}" in
	true)
		# Updating initramfs
		/usr/sbin/update-initramfs.orig.initramfs-tools "${@}"

		if [ "$(ls /boot/vmlinuz-* | wc -l)" -gt 1 ]
		then
			_NUMBER="1"

			for _VMLINUZ in /boot/vmlinuz-*
			do
				_VERSION="$(basename ${_VMLINUZ} | sed -e 's|vmlinuz-||')"

				cp /boot/vmlinuz-${_VERSION} /run/live/medium/live/vmlinuz${_NUMBER}.new
				if [ -e /boot/initrd.img-${_VERSION} ]; then
					cp /boot/initrd.img-${_VERSION} /run/live/medium/live/initrd${_NUMBER}.img.new
				fi

				_NUMBER="$((${_NUMBER} + 1))"
			done
		else
			_VMLINUZ=$(echo /boot/vmlinuz-*)
			_VERSION="$(basename ${_VMLINUZ} | sed -e 's|vmlinuz-||')"
			cp $_VMLINUZ /run/live/medium/live/vmlinuz.new
			if [ -e /boot/initrd.img-${_VERSION} ]; then
				cp /boot/initrd.img-${_VERSION} /run/live/medium/live/initrd.img.new
			fi

		fi
		for f in /run/live/medium/live/vmlinuz*.new \
		         /run/live/medium/live/initrd*.new; do
			if [ -e $f ]; then
				mv $f ${f%.new}
			fi
		done
		;;

	false)
		echo "I: update-initramfs is disabled (live system is running on read-only media)."
		exit 0
		;;
esac