-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd
executable file
·108 lines (101 loc) · 2.73 KB
/
add
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
#!/usr/bin/bash
function MsgOk { printf "\033[0;32m${@}\033[0m\n"; }
function MsgEr { printf "\033[0;31m${@}\033[0m\n"; }
function MsgHi { printf "\033[0;33m${@}\033[0m\n"; }
function Abort { MsgEr "$1"; exit 1; }
function add_pkgs {
local arch=""
local file=""
local repodb="$MY_REPONAME.db.tar.gz"
local root="$MY_REPOROOT"
for pkg in $@
do
if [[ ! -f "$pkg" ]]; then
MsgHi "<pkg> is not a file: $pkg"
continue
fi
if [[ ! "$pkg" =~ ([^-\.]+)\.pkg\.tar\..* ]]; then
MsgHi "Could not parse <pkg> architecture: $pkg"
continue
fi
arch="${BASH_REMATCH[1]}"
file="${pkg##*/}"
if [[ $arch == "any" ]]; then
for repodir in "$root/"*; do
cp $pkg "$repodir/"
repo-add -R "$repodir/$repodb" "$repodir/$file"
done
else
repodir="$root/$arch"
if [[ ! -d "$repodir" ]]; then
MsgHi "Repo not a dir: $repodir"
continue
fi
cp $pkg "$repodir/"
repo-add -R "$repodir/$repodb" "$repodir/$file"
fi
done
create_indexhtml
}
function create_indexhtml {
local root="$MY_REPOROOT"
for repodir in "$root/"*/; do
local arch=$(basename $repodir)
echo "==> Creating updated index file '$repodir/index.html'"
cat <<- EOF > "$repodir/index.html"
<!doctype html><html><head>
<title>RepoSide ${arch}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../../main.css" rel="stylesheet"/>
<style>
article { max-width: 80ch; margin: auto; }
span { float: right; }
table { width: 100%; }
td:last-child { text-align: right; }
</style>
</head><body>
<article>
<h1><a href="https://reposi.de">RepoSide</a> <span>${arch}</span></h1>
<table><thead></thead><tbody>
EOF
for pkgfile in "$repodir/"*.pkg.*; do
mapfile -t pkginfo < <(tar xfO "$pkgfile" .PKGINFO)
local file="${pkgfile##*/}"
local name=""
local ver=""
local desc=""
local url=""
for line in "${pkginfo[@]}"; do
mapfile -td \= parts <<<"$line"
local key="${parts[0]}"
local val="${parts[1]}"
val="${val#"${val%%[![:space:]]*}"}"
key="${key%"${key##*[![:space:]]}"}"
val="${val%"${val##*[![:space:]]}"}"
[[ $key == "pkgname" ]] && name="$val"
[[ $key == "pkgver" ]] && ver="$val"
[[ $key == "pkgdesc" ]] && desc="$val"
[[ $key == "url" ]] && url="$val"
done
cat <<- EOF >> "$repodir/index.html"
<tr>
<td>$name</td>
<td>$ver</td>
<td>$desc</td>
<td><a href="$file">pkg</a></td>
<td><a href="$url">url</a></td>
</tr>
EOF
done
cat <<- 'EOF' >> "$repodir/index.html"
</tbody></table></article>
</body></html>
EOF
done
}
MY_REPONAME="reposide"
MY_REPOROOT=$(readlink -f "$(dirname "$0")")"/site/archlinux"
if [[ $# -lt 1 ]]; then
Abort "Please provide package path(s) to add"
fi
add_pkgs $@