1
|
#!/bin/sh
|
2
|
# psp.sh, an alternative to asp for working with Parabola (initial draft)
|
3
|
# Copyright (C) 2021 alicia@ion.nu
|
4
|
#
|
5
|
# This program is free software: you can redistribute it and/or modify
|
6
|
# it under the terms of the GNU Affero General Public License as published by
|
7
|
# the Free Software Foundation, either version 3 of the License, or
|
8
|
# (at your option) any later version.
|
9
|
#
|
10
|
# This program is distributed in the hope that it will be useful,
|
11
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
# GNU Affero General Public License for more details.
|
14
|
#
|
15
|
# You should have received a copy of the GNU Affero General Public License
|
16
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
|
18
|
ttl=3600
|
19
|
repos='libre pcr packages community'
|
20
|
# libre
|
21
|
repo_libre_url='https://git.parabola.nu/abslibre.git'
|
22
|
repo_libre_path='/libre'
|
23
|
# pcr
|
24
|
repo_pcr_url='https://git.parabola.nu/abslibre.git'
|
25
|
repo_pcr_path='/pcr'
|
26
|
# TODO: We assume that the packages in arch's master branches match their individual package branches. Check that this is accurate?
|
27
|
# core, extra, & testing
|
28
|
repo_packages_url='https://github.com/archlinux/svntogit-packages.git'
|
29
|
repo_packages_path=''
|
30
|
# community & multilib
|
31
|
repo_community_url='https://github.com/archlinux/svntogit-community.git'
|
32
|
repo_community_path=''
|
33
|
updaterepo()
|
34
|
{
|
35
|
gitname="`basename "$1"`"
|
36
|
repopath="$2"
|
37
|
reponame="$3"
|
38
|
if [ ! -e "${HOME}/.local/var/psp/git/${gitname}" ]; then
|
39
|
mkdir -p "${HOME}/.local/var/psp/git"
|
40
|
# TODO: Option to clone full depth? Could be useful for package history, but takes a lot of space
|
41
|
git clone --depth 1 "$1" "${HOME}/.local/var/psp/git/${gitname}" && \
|
42
|
date '+%s' > "${HOME}/.local/var/psp/git/${gitname}/.timestamp"
|
43
|
else
|
44
|
oldtime="`cat "${HOME}/.local/var/psp/git/${gitname}/.timestamp"`"
|
45
|
time="`date '+%s'`"
|
46
|
if [ "`expr "$oldtime" + "$ttl"`" -lt "$time" ]; then
|
47
|
echo "Updating ${reponame}"
|
48
|
(cd "${HOME}/.local/var/psp/git/${gitname}" && git pull) && \
|
49
|
echo "$time" > "${HOME}/.local/var/psp/git/${gitname}/.timestamp"
|
50
|
fi
|
51
|
fi
|
52
|
mkdir -p "${HOME}/.local/var/psp/repos"
|
53
|
ln -s "../git/${gitname}${repopath}" "${HOME}/.local/var/psp/repos/${reponame}" 2> /dev/null
|
54
|
}
|
55
|
getvar(){ eval "echo \"\$${1}\""; }
|
56
|
package="$1"
|
57
|
for repo in ${repos}; do
|
58
|
url="`getvar "repo_${repo}_url"`"
|
59
|
path="`getvar "repo_${repo}_path"`"
|
60
|
updaterepo "$url" "$path" "$repo"
|
61
|
repodir="${HOME}/.local/var/psp/git/`basename "$url"`"
|
62
|
if [ -d "${repodir}${path}/${package}" ]; then
|
63
|
if [ -f "${repodir}${path}/${package}/PKGBUILD" ]; then
|
64
|
dir="${repodir}${path}/${package}"
|
65
|
elif [ -f "${repodir}${path}/${package}/trunk/PKGBUILD" ]; then
|
66
|
dir="${repodir}${path}/${package}/trunk"
|
67
|
else break; fi
|
68
|
echo "Found '${package}' in ${repo}"
|
69
|
ln -s "$dir" "$package"
|
70
|
exit
|
71
|
fi
|
72
|
done
|
73
|
echo "Package '${package}' not found"
|