-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinuxPackager.psm1
More file actions
107 lines (80 loc) · 2.75 KB
/
LinuxPackager.psm1
File metadata and controls
107 lines (80 loc) · 2.75 KB
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
function Get-LinuxBinaryArch {
param($Folder)
$in = "/mnt/" + ($Folder.Substring(0,1).ToLower() + $Folder.Substring(2).Replace('\','/'))
$cmd = "find '$in' -type f -executable -exec file {} \; | grep ELF | head -n 1"
$r = wsl -d Ubuntu --exec bash -lc $cmd 2>$null
if ($r -match "aarch64") {
return @{ deb="arm64"; rpm="aarch64"; tag="ARM64" }
}
if ($r -match "x86-64|x86_64") {
return @{ deb="amd64"; rpm="x86_64"; tag="X64" }
}
return @{ deb="noarch"; rpm="noarch"; tag="NOARCH" }
}
function makedeb {
param($F, $O)
$name = (Get-Item $F).Name.ToLower()
$arch = Get-LinuxBinaryArch $F
$in = "/mnt/" + ($F.Substring(0,1).ToLower() + $F.Substring(2).Replace('\','/'))
$outFile = Join-Path $O "$name$($arch.tag).deb"
$out = "/mnt/" + ($outFile.Substring(0,1).ToLower() + $outFile.Substring(2).Replace('\','/'))
$cmd = @"
rm -rf /tmp/deb
mkdir -p /tmp/deb/usr/local/bin
mkdir -p /tmp/deb/DEBIAN
find '$in' -type f -executable -exec cp {} /tmp/deb/usr/local/bin/ \; 2>/dev/null || true
cat > /tmp/deb/DEBIAN/control <<EOF
Package: $name
Version: 1.0.0
Architecture: $($arch.deb)
Maintainer: Andrea
Depends: libc6, libstdc++6
Description: Auto package
EOF
chmod 755 /tmp/deb/DEBIAN
chmod 644 /tmp/deb/DEBIAN/control
dpkg-deb --build /tmp/deb '$out' >/dev/null 2>&1
rm -rf /tmp/deb
"@
$cmd = $cmd -replace "`r",""
wsl -d Ubuntu --exec bash -lc $cmd 2>$null | Out-Null
}
function makerpm {
param($F, $O)
$name = (Get-Item $F).Name.ToLower()
$arch = Get-LinuxBinaryArch $F
$in = "/mnt/" + ($F.Substring(0,1).ToLower() + $F.Substring(2).Replace('\','/'))
$outFile = Join-Path $O "$name$($arch.tag).rpm"
$out = "/mnt/" + ($outFile.Substring(0,1).ToLower() + $outFile.Substring(2).Replace('\','/'))
$cmd = @"
rm -rf /tmp/rpmbuild
mkdir -p /tmp/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS,db}
shopt -s dotglob
cp -r '$in'/* /tmp/rpmbuild/SOURCES/ 2>/dev/null || true
rm -rf /tmp/rpmbuild/SOURCES/DEBIAN
printf "Name: $name
Version: 1.0.0
Release: 1
Summary: auto
License: MIT
BuildArch: $($arch.rpm)
%%description
auto
%%install
mkdir -p %%{buildroot}/usr/local/bin
cp -r /tmp/rpmbuild/SOURCES/. %%{buildroot}/usr/local/bin/
%%files
/usr/local/bin
" > /tmp/rpmbuild/SPECS/pkg.spec
rpmbuild --quiet \
--define "_topdir /tmp/rpmbuild" \
--define "_dbpath /tmp/rpmbuild/db" \
--nodeps \
-bb /tmp/rpmbuild/SPECS/pkg.spec >/dev/null 2>&1
cp /tmp/rpmbuild/RPMS/*/*.rpm '$out' 2>/dev/null || true
rm -rf /tmp/rpmbuild
"@
$cmd = $cmd -replace "`r",""
wsl -d Ubuntu --exec bash -lc $cmd 2>$null | Out-Null
}
Export-ModuleMember -Function makedeb, makerpm, Get-LinuxBinaryArch