summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 1a3934ce09db58bc7c1d64ad37d64e386d52ed98 (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
# This file is part of https://aur.archlinux.org/packages/mkinitcpio-systemd-tool/

pkgdesc='Provisioning tool for systemd in initramfs (systemd-tool)'
pkgname=mkinitcpio-systemd-tool
pkgver=20
pkgrel=1
url="https://github.com/random-archer/$pkgname"
source=("git+${url}.git")
depends=(
    'mkinitcpio' 
    'systemd'
)
optdepends=(
    'cryptsetup:      required by initrd-cryptsetup.service' 
    'dropbear:        required by initrd-dropbear.service' 
    'busybox:         required by initrd-tinysshd.service' 
    'tinyssh:         required by initrd-tinysshd.service' 
    'tinyssh-convert: required by initrd-tinysshd.service' 
    'mc:              required by initrd-debug-progs.service' 
)
makedepends=(
    'git'
)
backup=(
    'etc/mkinitcpio.d/crypttab'
    'etc/mkinitcpio.d/fstab'
    'etc/systemd/network/initrd-network.network'
    'etc/systemd/system/initrd-build.sh'
    'etc/systemd/system/initrd-cryptsetup.path'
    'etc/systemd/system/initrd-cryptsetup.service'
    'etc/systemd/system/initrd-debug-progs.service'
    'etc/systemd/system/initrd-debug-shell.service'
    'etc/systemd/system/initrd-dropbear.service'
    'etc/systemd/system/initrd-tinysshd.service'
    'etc/systemd/system/initrd-emergency.service'
    'etc/systemd/system/initrd-network.service'
    'etc/systemd/system/initrd-shell.service'
    'etc/systemd/system/initrd-shell.sh'
    'etc/systemd/system/initrd-sysroot-mount.service'
)
conflicts=(
    'mkinitcpio-dropbear'
    'mkinitcpio-tinyssh'
)
arch=('any')
md5sums=('SKIP')
license=('Apache')

# select proper version depending on marker file presence:
# * create .PKGDEV to use latest development version (from master branch)
# * create .PKGREL to use latest release version (named with release tag vNNN)
# * remove all markes and set pkgver=NNN above to use an existing vNNN release tag (the default)
pkgver() {
    local base=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)
    local repo="$base/$pkgname" # bare repo location
    local marker_develop="$base/.PKGDEV"
    local marker_release="$base/.PKGREL"
    local head_count=$(git -C "$repo" rev-list --count HEAD)
    local short_hash=$(git -C "$repo" rev-parse --short HEAD)
    local release_info=$(git -C "$repo" describe --long --tags --match "v[0-9]*")
    local release_number=$(echo "$release_info" | sed -r 's/^v([0-9]+)-.*/\1/')
    local release_version="${release_number}" # example: 3
    local develop_version="${release_number}.${head_count}.${short_hash}" # example: 3.25.d069dad
    if [[ -f "$marker_develop" ]] ; then 
        printf "$develop_version" ;
    elif [[ -f "$marker_release" ]] ; then 
        printf "$release_version" ;
    else 
        printf "$pkgver"
    fi
}

# 1.
prepare() {
    local repo="$srcdir/$pkgname" # working repo location
    local version=$(pkgver) # proper version number (release) or string (development)
    local target=$([[ $version =~ ^[0-9]+$ ]] && printf "v$version" || printf "master")
    git -C "$repo" checkout --quiet "$target" # checkout proper version
    git -C "$repo" status # verify working repo change
    true
}

# 2.
build() {
    true
}

# 3.
check() {
    true
}

# 4.
package() {
    
    local hook="systemd-tool"
    
    local source="$srcdir/$pkgname"
    
    local target="$pkgdir/usr/lib/initcpio"
    install -D -m644 "$source/mkinitcpio-hook.sh"       "$target/hooks/$hook"
    install -D -m644 "$source/mkinitcpio-install.sh"    "$target/install/$hook"

    local target="$pkgdir/usr/share/$pkgname"
    install -D -m644 "$source/LICENSE.md"               "${target}/LICENSE.md"
    install -D -m644 "$source/README.md"                "${target}/README.md"

    local target="$pkgdir/etc/mkinitcpio.d/"
    install -D -m644 "$source/crypttab"                 "$target/crypttab"
    install -D -m644 "$source/fstab"                    "$target/fstab"
                
    local target="$pkgdir/etc/systemd/network"
    local path= unit=
    for path in $(ls "$source" | grep -E "[.](network)$") ; do
        unit=$(basename $path)
        install -D -m644 "$source/$unit"  "$target/$unit"
    done

    local target="$pkgdir/etc/systemd/system"
    local path= unit=
    for path in $(ls "$source" | grep -E "[.](path|service|target)$") ; do
        unit=$(basename $path)
        install -D -m644 "$source/$unit"  "$target/$unit"
    done
    install -D -m644 "$source/initrd-build.sh"              "$target/initrd-build.sh"
    install -D -m644 "$source/initrd-shell.sh"              "$target/initrd-shell.sh"

}