Skip to content

Commit 8871805

Browse files
committed
*.sh: refactor new version method into lib.sh
no need to create a second file just for the version when it can be set in lib.sh git -c safe.directory is needed to be able to run rev-parse as root also contains some minor refactors to arg parsing etc
1 parent 3c75acb commit 8871805

9 files changed

Lines changed: 25 additions & 27 deletions

File tree

build-x86-images.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33
set -eu
44

5+
. ./lib.sh
6+
7+
PROGNAME=$(basename "$0")
58
ARCH=$(uname -m)
69
IMAGES="base enlightenment xfce mate cinnamon gnome kde lxde lxqt"
710
REPO=
811
DATE=$(date +%Y%m%d)
912

1013
help() {
11-
echo "${0#/*}: [-a arch] [-b base|enlightenment|xfce|mate|cinnamon|gnome|kde|lxde|lxqt] [-r repo]" >&2
14+
echo "$PROGNAME: [-a arch] [-b base|enlightenment|xfce|mate|cinnamon|gnome|kde|lxde|lxqt] [-r repo]" >&2
1215
}
1316

14-
while getopts "a:b:hr:" opt; do
17+
while getopts "a:b:hr:V" opt; do
1518
case $opt in
1619
a) ARCH="$OPTARG";;
1720
b) IMAGES="$OPTARG";;
1821
h) help; exit 0;;
1922
r) REPO="-r $OPTARG $REPO";;
23+
V) version; exit 0;;
2024
*) help; exit 1;;
2125
esac
2226
done
@@ -90,7 +94,7 @@ if [ ! -x mklive.sh ]; then
9094
fi
9195

9296
if [ -x installer.sh ]; then
93-
. ./version.sh
97+
MKLIVE_VERSION="$(PROGNAME='' version)"
9498
installer=$(mktemp)
9599
sed "s/@@MKLIVE_VERSION@@/${MKLIVE_VERSION}/" installer.sh > "$installer"
96100
install -Dm755 "$installer" "$INCLUDEDIR"/usr/bin/void-installer

lib.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ is_target_native() {
3333
return $?
3434
}
3535

36+
version() (
37+
set +u
38+
[ -n "$PROGNAME" ] && printf "%s " "$PROGNAME"
39+
echo "$(cat ./version) ${MKLIVE_REV:-"$(git -c safe.directory="$(pwd)" rev-parse --short HEAD 2> /dev/null)"}"
40+
)
41+
3642
info_msg() {
3743
# This function handles the printing that is bold within all
3844
# scripts. This is a convenience function so that the rather ugly

mkimage.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
#-
2727

28-
. ./version.sh
29-
3028
readonly PROGNAME=$(basename "$0")
3129
readonly ARCH=$(uname -m)
3230

@@ -96,8 +94,8 @@ while getopts "b:B:o:r:s:x:h:V" opt; do
9694
r) ROOT_FSTYPE="$OPTARG";;
9795
s) IMGSIZE="$OPTARG";;
9896
x) COMPRESSOR_THREADS="$OPTARG" ;;
99-
V) echo "$PROGNAME $MKLIVE_VERSION"; exit 0;;
100-
h) usage;;
97+
V) version; exit 0;;
98+
*) usage;;
10199
esac
102100
done
103101
shift $((OPTIND - 1))

mklive.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
trap 'error_out $? $LINENO' INT TERM 0
3030
umask 022
3131

32-
. ./version.sh
32+
. ./lib.sh
3333

3434
readonly REQUIRED_PKGS="base-files libgcc dash coreutils sed tar gawk syslinux grub-i386-efi grub-x86_64-efi squashfs-tools xorriso"
3535
readonly INITRAMFS_PKGS="binutils xz device-mapper dhclient dracut-network openresolv"
@@ -312,9 +312,8 @@ while getopts "a:b:r:c:C:T:Kk:l:i:I:S:s:o:p:v:Vh" opt; do
312312
C) BOOT_CMDLINE="$OPTARG";;
313313
T) BOOT_TITLE="$OPTARG";;
314314
v) LINUX_VERSION="$OPTARG";;
315-
V) echo "$PROGNAME $MKLIVE_VERSION"; exit 0 ;;
316-
h) usage;;
317-
*) usage;;
315+
V) version; exit 0;;
316+
*) usage;;
318317
esac
319318
done
320319
shift $((OPTIND - 1))

mknet.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
#-
2929

30-
. ./version.sh
31-
3230
readonly PROGNAME=$(basename "$0")
3331
readonly REQTOOLS="xbps-install tar"
3432

@@ -91,8 +89,8 @@ while getopts "r:c:C:T:K:i:o:k:l:Vh" opt; do
9189
C) BOOT_CMDLINE="$OPTARG";;
9290
T) BOOT_TITLE="$OPTARG";;
9391
S) SPLASH_IMAGE="OPTARG";;
94-
V) echo "$PROGNAME $MKLIVE_VERSION"; exit 0 ;;
95-
h) usage;;
92+
V) version; exit 0;;
93+
*) usage;;
9694
esac
9795
done
9896
shift $((OPTIND - 1))

mkplatformfs.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
#-
2626

27-
. ./version.sh
28-
2927
readonly PROGNAME=$(basename "$0")
3028
readonly ARCH=$(uname -m)
3129
readonly REQTOOLS="xbps-install xbps-reconfigure tar xz"
@@ -88,8 +86,8 @@ while getopts "b:p:k:c:C:r:x:o:nhV" opt; do
8886
x) COMPRESSOR_THREADS="$OPTARG" ;;
8987
o) FILENAME="$OPTARG" ;;
9088
n) COMPRESSION="n" ;;
91-
h) usage; exit 0 ;;
92-
V) echo "$PROGNAME $MKLIVE_VERSION"; exit 0 ;;
89+
V) version; exit 0;;
90+
*) usage; exit 0 ;;
9391
esac
9492
done
9593
shift $((OPTIND - 1))

mkrootfs.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
#-
2727

28-
. ./version.sh
29-
3028
readonly PROGNAME=$(basename "$0")
3129
readonly ARCH=$(uname -m)
3230
readonly REQTOOLS="xbps-install xbps-reconfigure tar xz"
@@ -85,11 +83,11 @@ while getopts "b:C:c:hr:x:o:V" opt; do
8583
b) SYSPKG="$OPTARG";;
8684
C) XBPS_CONFFILE="-C $OPTARG";;
8785
c) XBPS_CACHEDIR="--cachedir=$OPTARG";;
88-
h) usage; exit 0;;
8986
r) XBPS_REPOSITORY="$XBPS_REPOSITORY --repository=$OPTARG";;
9087
x) COMPRESSOR_THREADS="$OPTARG" ;;
9188
o) FILENAME="$OPTARG" ;;
92-
V) echo "$PROGNAME $MKLIVE_VERSION"; exit 0;;
89+
V) version; exit 0;;
90+
*) usage; exit 0;;
9391
esac
9492
done
9593
shift $((OPTIND - 1))

version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.23

version.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)