Skip to content

Instantly share code, notes, and snippets.

@jakubskrz
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakubskrz/4b7e3f21b745c9442d53 to your computer and use it in GitHub Desktop.
Save jakubskrz/4b7e3f21b745c9442d53 to your computer and use it in GitHub Desktop.
Jednoduchý skript pro zformátování USB HDD a nastavení sdílení přes Sambu pro router Turris
#!/bin/ash
# Nainstaluj modul pro formatovani ext4 partitions
opkg update
opkg install kmod-usb-storage kmod-fs-ext4
# Vypis seznam pripojenych disku a zeptej se, ktery pouzit
echo -e "Vypisuji aktualne pripojene disky:"
blkid
echo -e "Zadejte disk, ktery chcete pouzit (napr. /dev/sda1): \c "
read DISK
# Radeji se jeste jednou ujisti, ze uzivatel chce disk smazat
echo -e "\nVAROVANI!! Vybrany disk bude nenavratne smazan!"
echo -e "Prijdete tak o veskera data na nem ulozena! Pokracovat? [ano/NE] \c "
read POTVRZENI
if [ $POTVRZENI = "ano" ]; then
# Vytvor na zvolenem disku ext4 partition
mkfs.ext4 $DISK
# Vytvor adresar, do ktereho disk pripojime
mkdir -p /mnt/test
# Mountni disk a povol jeho automaticke pripojovani
echo config mount >> /etc/config/fstab
echo -e "\toption 'device' '$DISK'" >> /etc/config/fstab
echo -e "\toption 'fstype' 'ext4'" >> /etc/config/fstab
echo -e "\toption 'enabled' '1'" >> /etc/config/fstab
echo -e "\toption 'target' '/mnt/test'\n" >> /etc/config/fstab
`/etc/init.d/fstab enable`
`/etc/init.d/fstab restart`
# Zeptej se na jmeno, ktere se ma pouzit pro Sambu
echo -e "Zadejte jmeno pod jakym chcete videt disk v siti: \c "
read JMENO
# Nastav sdileni rootu disku pres Sambu
echo config samba >> /etc/config/samba
echo -e "\toption workgroup 'WORKGROUP'" >> /etc/config/samba
echo -e "\toption name '$JMENO'" >> /etc/config/samba
echo -e "\toption homes '0'\t" >> /etc/config/samba
echo config sambashare >> /etc/config/samba
echo -e "\toption name 'test'" >> /etc/config/samba
echo -e "\toption path '/mnt/test'" >> /etc/config/samba
echo -e "\toption read_only 'no'" >> /etc/config/samba
echo -e "\toption guest_ok 'yes'\t" >> /etc/config/samba
`/etc/init.d/samba enable`
`/etc/init.d/samba restart`
echo "Hotovo! Disk by nyni mel byt videt ve vasi siti."
exit 0
else
echo "Ok, koncim.."
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment