Skip to content

Commit

Permalink
fix: maintain dracut version in dracut.sh
Browse files Browse the repository at this point in the history
The git release tag does not contain the `dracut-version.sh` file and
therefore `git archive` will lack this file as well. The Makefile
attempts to populate version information from git tags (which is
impossible in an unpacked release tarball) and, failing that, reverts to
whatever would be encoded in that file if it were sourced.

Maintain the dracut version directly in `dracut.sh` and call
`dracut.sh --version` to get the version number. The version can be
changed with a simple sed command to a new version (for releases or for
distributors that want to include the packaging version):

```
sed -i "s/^DRACUT_VERSION=.*$/DRACUT_VERSION=\"${NEW_VERSION}\"/" dracut.sh
```

Fixes #2169
Signed-off-by: Benjamin Drung <[email protected]>
  • Loading branch information
bdrung committed Aug 24, 2023
1 parent 0b81e8e commit 2cafa15
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 47 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
test*.img
/.buildpath
/.project
/dracut-version.sh
/src/install/dracut-install
/*.rpm
/*.[0-9]
Expand Down
25 changes: 8 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
-include dracut-version.sh

DRACUT_MAIN_VERSION ?= $(shell env GIT_CEILING_DIRECTORIES=$(CURDIR)/.. git describe --abbrev=0 --tags --always 2>/dev/null || :)
ifeq ($(DRACUT_MAIN_VERSION),)
DRACUT_MAIN_VERSION = $(DRACUT_VERSION)
endif
DRACUT_FULL_VERSION ?= $(shell env GIT_CEILING_DIRECTORIES=$(CURDIR)/.. git describe --tags --always 2>/dev/null || :)
DRACUT_FULL_VERSION ?= $(shell ./dracut.sh --version | cut -d' ' -f 2-)
ifeq ($(DRACUT_FULL_VERSION),)
DRACUT_FULL_VERSION = $(DRACUT_VERSION)
endif
DRACUT_MAIN_VERSION ?= $(shell echo "$(DRACUT_FULL_VERSION)" | sed 's/\([0-9]\+\).*/\1/')
ifeq ($(DRACUT_MAIN_VERSION),)
DRACUT_MAIN_VERSION = $(DRACUT_VERSION)
endif

HAVE_SHELLCHECK ?= $(shell command -v shellcheck >/dev/null 2>&1 && echo yes)
HAVE_SHFMT ?= $(shell command -v shfmt >/dev/null 2>&1 && echo yes)
Expand Down Expand Up @@ -48,9 +46,9 @@ man8pages = man/dracut.8 \

manpages = $(man1pages) $(man5pages) $(man7pages) $(man8pages)

.PHONY: install clean archive testimage test all check AUTHORS CONTRIBUTORS doc dracut-version.sh
.PHONY: install clean archive testimage test all check AUTHORS CONTRIBUTORS doc

all: dracut-version.sh dracut.pc dracut-install src/skipcpio/skipcpio dracut-util
all: dracut.pc dracut-install src/skipcpio/skipcpio dracut-util

%.o : %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(KMOD_CFLAGS) $< -o $@
Expand Down Expand Up @@ -163,7 +161,6 @@ install: all
mkdir -p $(DESTDIR)$(pkglibdir)/dracut.conf.d
install -m 0755 dracut-init.sh $(DESTDIR)$(pkglibdir)/dracut-init.sh
install -m 0755 dracut-functions.sh $(DESTDIR)$(pkglibdir)/dracut-functions.sh
install -m 0755 dracut-version.sh $(DESTDIR)$(pkglibdir)/dracut-version.sh
ln -fs dracut-functions.sh $(DESTDIR)$(pkglibdir)/dracut-functions
install -m 0755 dracut-logger.sh $(DESTDIR)$(pkglibdir)/dracut-logger.sh
install -m 0755 dracut-initramfs-restore.sh $(DESTDIR)$(pkglibdir)/dracut-initramfs-restore
Expand Down Expand Up @@ -218,18 +215,13 @@ endif
mkdir -p $(DESTDIR)${pkgconfigdatadir}
install -m 0644 dracut.pc $(DESTDIR)${pkgconfigdatadir}/dracut.pc

dracut-version.sh:
@rm -f dracut-version.sh
@printf "#!/bin/sh\n# shellcheck disable=SC2034\nDRACUT_VERSION=%s\n" "$(DRACUT_FULL_VERSION)" > dracut-version.sh

clean:
$(RM) *~
$(RM) */*~
$(RM) */*/*~
$(RM) $(manpages:%=%.xml) dracut.xml
$(RM) test-*.img
$(RM) dracut-*.tar.bz2 dracut-*.tar.xz
$(RM) dracut-version.sh
$(RM) dracut-install src/install/dracut-install $(DRACUT_INSTALL_OBJECTS)
$(RM) skipcpio/skipcpio $(SKIPCPIO_OBJECTS)
$(RM) dracut-util util/util $(UTIL_OBJECTS)
Expand All @@ -241,10 +233,9 @@ clean:
dist: dracut-$(DRACUT_MAIN_VERSION).tar.xz

dracut-$(DRACUT_MAIN_VERSION).tar.xz: doc syncheck
@echo "DRACUT_VERSION=$(DRACUT_MAIN_VERSION)" > dracut-version.sh
git archive --format=tar $(DRACUT_MAIN_VERSION) --prefix=dracut-$(DRACUT_MAIN_VERSION)/ > dracut-$(DRACUT_MAIN_VERSION).tar
mkdir -p dracut-$(DRACUT_MAIN_VERSION)
for i in $(manpages) dracut.html dracut-version.sh; do [ "$${i%/*}" != "$$i" ] && mkdir -p "dracut-$(DRACUT_MAIN_VERSION)/$${i%/*}"; cp "$$i" "dracut-$(DRACUT_MAIN_VERSION)/$$i"; done
for i in $(manpages) dracut.html; do [ "$${i%/*}" != "$$i" ] && mkdir -p "dracut-$(DRACUT_MAIN_VERSION)/$${i%/*}"; cp "$$i" "dracut-$(DRACUT_MAIN_VERSION)/$$i"; done
tar --owner=root --group=root -rf dracut-$(DRACUT_MAIN_VERSION).tar $$(find dracut-$(DRACUT_MAIN_VERSION) -type f)
rm -fr -- dracut-$(DRACUT_MAIN_VERSION).tar.xz dracut-$(DRACUT_MAIN_VERSION)
xz -9 dracut-$(DRACUT_MAIN_VERSION).tar
Expand Down
31 changes: 3 additions & 28 deletions dracut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

DRACUT_VERSION="059"

# store for logging

unset BASH_ENV
Expand All @@ -36,13 +38,6 @@ readonly dracut_cmd=$(readlink -f "$0")
set -o pipefail

usage() {
[[ $sysroot_l ]] && dracutsysrootdir="$sysroot_l"
[[ $dracutbasedir ]] || dracutbasedir="$dracutsysrootdir"/usr/lib/dracut
if [[ -f $dracutbasedir/dracut-version.sh ]]; then
# shellcheck source=./dracut-version.sh
. "$dracutbasedir"/dracut-version.sh
fi

# 80x25 linebreak here ^
cat << EOF
Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
Expand All @@ -63,12 +58,6 @@ EOF
}

long_usage() {
[[ $dracutbasedir ]] || dracutbasedir="$dracutsysrootdir"/usr/lib/dracut
if [[ -f $dracutbasedir/dracut-version.sh ]]; then
# shellcheck source=./dracut-version.sh
. "$dracutbasedir"/dracut-version.sh
fi

# 80x25 linebreak here ^
cat << EOF
Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
Expand Down Expand Up @@ -292,15 +281,6 @@ For example:
EOF
}

long_version() {
[[ $dracutbasedir ]] || dracutbasedir="$dracutsysrootdir"/usr/lib/dracut
if [[ -f $dracutbasedir/dracut-version.sh ]]; then
# shellcheck source=./dracut-version.sh
. "$dracutbasedir"/dracut-version.sh
fi
echo "dracut $DRACUT_VERSION"
}

# Fills up host_devs stack variable and makes sure there are no duplicates
push_host_devs() {
local _dev
Expand Down Expand Up @@ -854,7 +834,7 @@ while :; do
machine_id_l="no"
;;
--version)
long_version
echo "dracut $DRACUT_VERSION"
exit 0
;;
--)
Expand Down Expand Up @@ -1291,11 +1271,6 @@ if [[ $print_cmdline ]]; then
kmsgloglvl=0
fi
if [[ -f $dracutbasedir/dracut-version.sh ]]; then
# shellcheck source=./dracut-version.sh
. "$dracutbasedir"/dracut-version.sh
fi
if systemd-detect-virt -c &> /dev/null; then
export DRACUT_NO_MKNOD=1 DRACUT_NO_XATTR=1
if [[ $hostonly ]]; then
Expand Down
5 changes: 4 additions & 1 deletion tools/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ cat NEWS_header.md NEWS_header_new.md NEWS_body_new.md NEWS_body_with_conttribut
# message for https://github.com/dracutdevs/dracut/releases/tag
cat -s NEWS_body_new.md CONTRIBUTORS.md > release.md

# Set new dracut version
sed -i "s/^DRACUT_VERSION=.*$/DRACUT_VERSION=\"${NEW_VERSION}\"/" dracut.sh

# Check in AUTHORS and NEWS.md
git config user.name "Dracut Release Bot"
git config user.email "<>"
git commit -m "docs: update NEWS.md and AUTHORS" NEWS.md AUTHORS
git commit -m "release dracut $NEW_VERSION" NEWS.md AUTHORS dracut.sh
git push origin master
git tag "$NEW_VERSION" -m "$NEW_VERSION"
git push --tags
Expand Down

0 comments on commit 2cafa15

Please sign in to comment.