added files

This commit is contained in:
Dan 2022-01-23 16:30:57 +13:00
parent 815a94546c
commit 79bfb93acd
Signed by: dan
GPG Key ID: 57ABEF39C546B028
8 changed files with 162 additions and 0 deletions

11
1.cleanup_cache.hook Normal file
View File

@ -0,0 +1,11 @@
[Trigger]
Type = Package
Operation = Remove
Operation = Install
Operation = Upgrade
Target = *
[Action]
Description = Removing obsolete cached package files (keeping the latest two)...
When = PostTransaction
Exec = /usr/bin/paccache -rvk2

View File

@ -0,0 +1,11 @@
[Trigger]
Type = Package
Operation = Remove
Operation = Install
Operation = Upgrade
Target = *
[Action]
Description = Archive packages to your archive server.
When = PostTransaction
Exec = /root/archive_packages.sh

View File

@ -0,0 +1,11 @@
[Trigger]
Type = Package
Operation = Remove
Operation = Install
Operation = Upgrade
Target = *
[Action]
Description = Archive packages to your archive server.
When = PostTransaction
Exec = /root/repo-add.sh

10
archive_packages.sh Normal file
View File

@ -0,0 +1,10 @@
#!/bin/bash
# Variables
arch=$(uname -m)
## Add your archive server ip and user (rsync auth user)
server="$(cat /etc/rsyncd.server)"
user="$(cat /etc/rsyncd.user)"
# Rsync daemon
rsync -chavzP --password-file=/etc/rsyncd.password --ignore-existing /var/cache/pacman/pkg/*pkg* rsync://$user@$server/archiverepo/archlinux/$arch

24
client.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
# Variables
read -p "Enter your archive server ip address: " server
read -p "Enter your user for rsync daemon credentials: " user
read -p "Enter your password: " -s password
# Hooks
mkdir /etc/pacman.d/hooks/
cp 1.cleanup_cache.hook /etc/pacman.d/hooks/
cp 2.archive_packages-client.hook /etc/pacman.d/hooks/2.archive_packages.hook
# Script/s
cp archive_packages.sh /root/
chmod +x /root/archive_packages.sh
# Rsync credentials
echo "$user" > /etc/rsyncd.user
echo "$password" > /etc/rsyncd.password
echo "$server" > /etc/rsyncd.server
chmod 400 /etc/rsyncd.user /etc/rsyncd.password /etc/rsyncd.server
# Add repository to pacman.conf
echo "[homerepo]
Server = http://$server:8080/archlinux/\$arch" >> /etc/pacman.conf

35
delete.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
# Delete everything
read -r -p "You are going to delete everything. Are you sure? [YES/no] " prompt
if [[ $prompt == "YES" ]]
then
arch=$(uname -m)
# Hooks
rm /etc/pacman.d/hooks/1.cleanup_cache.hook
rm /etc/pacman.d/hooks/2.archive_packages.hook
# scripts
rm /root/repo-add.sh
rm /root/archive_packages.sh
# Repo
rm -r /srv/http/repo/
# Pacman config
sed -i "s|CacheDir = /srv/http/repo/archlinux/$arch/|#CacheDir = /var/cache/pacman/pkg/|g" /etc/pacman.conf
head -n -2 /etc/pacman.conf > tmp.txt && mv tmp.txt /etc/pacman.conf
# Rsync
rm /etc/rsyncd.secrets
rm /etc/rsyncd.user
rm /etc/rsyncd.password
rm /etc/rsyncd.server
else
echo "Nothing has been deleted."
fi

3
repo-add.sh Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
# Used for `2.archive_packages-SERVER.hook` and rsync daemon `post-xfer exec = /root/repo-add.sh`
repo-add /srv/http/repo/archlinux/*/homerepo.db.tar.zst /srv/http/repo/archlinux/*/{*.zst,*.gz,*.xz}

57
server.sh Normal file
View File

@ -0,0 +1,57 @@
#!/bin/bash
# Variables
arch=$(uname -m)
server="$(ip addr show | grep "inet " | grep -v 127.0.0. | head -1 | cut -d" " -f6 | cut -d/ -f1)"
## Rsync credentials
read -p "Enter your user for rsync daemon credentials: " user
read -p "Enter your password: " -s password
# Hooks
mkdir /etc/pacman.d/hooks/
cp 1.cleanup_cache.hook /etc/pacman.d/hooks/
cp 2.archive_packages-server.hook /etc/pacman.d/hooks/2.archive_packages.hook
# Script/s
cp repo-add.sh /root/
chmod +x /root/repo-add.sh
# Database
mkdir -p /srv/http/repo/archlinux/{x86_64,aarch64}/AUR
repo-add /srv/http/repo/archlinux/x86_64/homerepo.db.tar.zst
repo-add /srv/http/repo/archlinux/x86_64/AUR/homerepo.db.tar.zst
repo-add /srv/http/repo/archlinux/aarch64/homerepo.db.tar.zst
repo-add /srv/http/repo/archlinux/aarch64/AUR/homerepo.db.tar.zst
# Move existing packages
mv /var/cache/pacman/pkg/*pkg* /srv/http/repo/archlinux/$arch/
repo-add /srv/http/repo/archlinux/$arch/homerepo.db.tar.zst /srv/http/repo/archlinux/$arch/{*.zst,*.gz,*.xz}
chown -R http: /srv/http/repo/
# Change cache path in pacman.conf
sed -i "s|#CacheDir = /var/cache/pacman/pkg/|CacheDir = /srv/http/repo/archlinux/$arch/|g" /etc/pacman.conf
# Rsync daemon
## Credentials
echo "$user:$password" > /etc/rsyncd.secrets
chmod 400 /etc/rsyncd.secrets
## Config
echo "[archiverepo]
path = /srv/http/repo/
comment = Arch Archive Repository
timeout = 300
read only = false
uid = 33
gid = 33
post-xfer exec = /root/repo-add.sh
# Security
auth users = $user
secrets file = /etc/rsyncd.secrets
# Optional
#hosts allow = 192.168.1.0/255.255.255.0
" >> /etc/rsyncd.conf
systemctl enable --now rsyncd.service
# Add repository to pacman.conf
echo "[homerepo]
Server = http://$server:8080/archlinux/\$arch" >> /etc/pacman.conf