added files
This commit is contained in:
parent
815a94546c
commit
79bfb93acd
8 changed files with 162 additions and 0 deletions
11
1.cleanup_cache.hook
Normal file
11
1.cleanup_cache.hook
Normal 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
|
11
2.archive_packages-client.hook
Normal file
11
2.archive_packages-client.hook
Normal 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
|
11
2.archive_packages-server.hook
Normal file
11
2.archive_packages-server.hook
Normal 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
10
archive_packages.sh
Normal 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
24
client.sh
Normal 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
35
delete.sh
Normal 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
3
repo-add.sh
Normal 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
57
server.sh
Normal 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
|
Loading…
Reference in a new issue