ansitest/proxmox/symlink-samba-isos.sh

90 lines
3.0 KiB
Bash
Raw Normal View History

2024-02-18 09:50:42 -07:00
#!/bin/bash
2024-11-27 11:28:01 -07:00
# Traverses subdirs on SMB net share and symlinks everything into 1 flat dir on proxmox
# Saves on ISO storage space across PVE nodes
# 2024.Feb kneutron / edits 2024.Nov
2024-02-18 09:50:42 -07:00
# shared ISOs are mounted via samba from macpro on 2.5gbit network, R/O
# fstab:
# //macpro-25g/shrcompr-ztoshtera6 /mnt/imac5 cifs noauto,noexec,credentials=/root/.smb-macpro,uid=root,ro 0 0
2024-11-27 11:28:01 -07:00
# NOTE Pass "1" as arg to auto-delete broken symlinks
2024-11-27 11:12:34 -07:00
2024-11-27 11:28:01 -07:00
# Rerun the script on each PVE node if you update / delete ISOs on the share / run nightly in cron
2024-11-27 11:12:34 -07:00
2024-11-27 11:28:01 -07:00
# for cron
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/games:/usr/games:/root/bin:/root/bin/boojum:/usr/X11R6/bin:/usr/NX/bin:
# Example root crontab entry:
# every day @ 11:01pm, refresh ISO symlinks and autodelete stale ones
#1 23 * * * /root/bin/boojum/symlink-samba-isos.sh 1 2>&1 >/root/symlink-samba-isos.log
# TODO set to 0 if you only have 1 shared ISO dir
2024-11-27 11:28:28 -07:00
enable2nddir=0
2024-02-18 09:50:42 -07:00
2024-11-27 11:28:01 -07:00
# Destination dir for iso symlinks
2024-02-18 09:50:42 -07:00
# NOTE - default proxmox iso storage is /var/lib/vz
2024-05-20 12:03:30 -06:00
# faster ones here
2024-03-22 15:44:38 -06:00
cd /var/lib/vz/template/iso || exit 44;
2024-02-18 09:50:42 -07:00
# grep iso at the end skips any misc non-iso files that were part of a torrent
2024-11-27 11:12:34 -07:00
# NOTE this is 2.5Gbit samba mount to zint1000pro - faster
# only if mounted, otherwise skip
# xxx TODO EDITME
mnt=macpro-zint1000
if [ $(df |grep -c $mnt) -gt 0 ]; then
ln -sfn $(find /mnt/$mnt/ISO/ |grep iso$) .
2024-05-20 12:03:30 -06:00
#ls -l
2024-11-27 11:12:34 -07:00
echo "o Checking for broken symlinks:"
pwd
if [ "$1" = "1" ]; then
echo "o Auto-deleting broken symlinks per arg passed"
2024-11-27 11:28:01 -07:00
find . -xtype l -print -delete # autofix broken sym
2024-11-27 11:12:34 -07:00
else
# display only, admin needs to fix
find . -xtype l
fi # if autofix broken symlinks
# find . -xtype l -exec rm -v {} \; # fix broken sym
fi # if df
2024-05-20 12:03:30 -06:00
2024-11-27 11:12:34 -07:00
if [ $enable2nddir -gt 0 ]; then
# secondary ISO dir [optional]
2024-11-27 11:15:45 -07:00
# This is the destination dir on pve - xxx TODO EDITME
2024-11-27 11:12:34 -07:00
cd /mnt/seatera4-xfs/template/iso || exit 44;
2024-11-27 11:28:01 -07:00
# this is the samba mount - xxx TODO EDITME
2024-11-27 11:12:34 -07:00
mnt=imac5
if [ $(df |grep -c $mnt) -gt 0 ]; then
echo '====='
echo "o Symlinking 2nd dir $mnt to $PWD"
ln -sfn $(find /mnt/$mnt/ISO/ |grep iso$) .
2024-11-27 11:28:01 -07:00
# show broken/stale symlinks
2024-11-27 11:12:34 -07:00
pwd
echo "o Checking for broken symlinks from $mnt:"
if [ "$1" = "1" ]; then
echo "o Auto-deleting broken symlinks per arg passed"
find . -xtype l -print -delete # fix broken sym
else
# display only, admin needs to fix
find . -xtype l
fi # if autofix broken symlinks
fi # if df
fi # if 2nd dir
2024-02-18 09:50:42 -07:00
exit;
2024-05-20 12:03:30 -06:00
# alternative:
2024-11-27 11:12:34 -07:00
#[ $(which symlinks |wc -l) -eq 0 ] && apt install -y symlinks
#symlinks -r .
2024-05-20 12:03:30 -06:00
2024-11-27 11:12:34 -07:00
#REF: https://www.reddit.com/r/Proxmox/comments/1aqn2sc/connecting_to_read_only_nfs_for_iso/
2024-02-18 09:50:42 -07:00
2024-11-27 11:12:34 -07:00
#2024.0520 FIXED did not remove stale/broken symlinks - use midnight commander to detect them
#REF: https://linuxhandbook.com/find-broken-symlinks/
2024-05-20 12:03:30 -06:00
#ln -sfn $(find /zseatera4mir/from-macpro-ztoshtera6/shrcompr-ztoshtera6/ISO/ |grep iso$) .
# xxx 2024.0324, macpro was off most of the weekend
2024-11-27 11:12:34 -07:00
# NOTWORK
#argdel=""
#[ "$1" = "1" ] && argdel="-exec rm -v {} \;" # fix broken sym