Skip to content

Instantly share code, notes, and snippets.

@zekrom-vale
Created July 22, 2020 12:53
Show Gist options
  • Save zekrom-vale/f208c825ff750a629b46bb042c9522fe to your computer and use it in GitHub Desktop.
Save zekrom-vale/f208c825ff750a629b46bb042c9522fe to your computer and use it in GitHub Desktop.
SAMBA auto power for ATX NAS
#!/bin/bash
p=`cat /sys/class/gpio/gpio4/value`
if [[ $p -eq 1 ]]; then
sudo systemctl stop smbd
# Change to your mdadm mount point (May be /dev/md127 or somthing due to a bug)
sudo umount /dev/md127
# sudo umount /dev/md/main
# Will return $? != 0 if bussy
while true; do
# Change to your mdadm mount point
sudo mdadm --stop /dev/md/main
if [[ $? ]]; then
sudo echo "0" > /sys/class/gpio/gpio4/value
sudo systemctl start smbd
break
fi
done
fi
#!/bin/bash
# Set pin 4 to high to enable PSU
p=`cat /sys/class/gpio/gpio4/value`
if [[ $p -eq 0 ]]; then
sudo echo "1" > /sys/class/gpio/gpio4/value
sleep 20
echo assemble
sudo mdadm --assemble --scan
echo mount
# Replace the UUID with the your UUID
sudo mount --uuid ca87639e-7acd-4287-848a-d2a0b78667a5 /mnt &
echo restart smbd
sudo systemctl restart smbd
fi
#!/bin/bash
# # Samba config
# sudo nano /etc/samba/smb.conf
# testparm
# sudo systemctl restart smbd
# NAS set up folowing https://www.ricmedia.com/build-raspberry-pi3-raid-nas-server/
# DO NOT INCLUDE THE MOUNT IN fstab, this will prevent the system to boot without the drive
# This script uses pin 4 so change gpio4 to your pin and the export
# set pin 4 to output
cat /sys/class/gpio/gpio4/direction
if [[ $? ]]; then
sudo echo "4" > /sys/class/gpio/export
sudo echo "out" > /sys/class/gpio/gpio4/direction
fi
sudo systemctl start smbd
while [[ true ]]; do
echo loop
if [[ `sudo /samba/inuse.sh` -eq 0 ]]; then
echo off
sudo /samba/ATXoff.sh
sleep 1
else
echo on
sudo /samba/ATXon.sh
sleep 1m
fi
done
#!/bin/bash
if [[ `sudo smbstatus -b | wc -l` -le 4 ]]; then
echo 0
else
echo 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment