CH3SNAS:Store-passwd.sh

From NAS-Tweaks

Jump to: navigation, search

Fonz Version of the store-passwd.sh-Script for the DNS-343:

#!/ffp/bin/sh

PATH=/ffp/sbin:/ffp/bin:$PATH

echo "Mounting flash ..."
mount -t minix /dev/mtdblock0 /sys/mtd1
mount -t minix /dev/mtdblock1 /sys/mtd2

echo "Updating files ..."
for d in /sys/mtd1 /sys/mtd2 /mnt/HD_a4/.systemfile/AccountFile /mnt/HD_b4/.systemfile/AccountFile; do
    if [ -d "$d" ]; then
	for f in /etc/passwd /etc/group /etc/shadow /etc/samba/smbpasswd; do
	    b=$(basename $f)
	    if [ -e "$d/$b" ]; then
		echo "  $d/$b"
		cp -f $f $d
	    fi
	done
    fi
done

echo "Unmounting ..."
sync
umount /sys/mtd1
umount /sys/mtd2

echo "Done."

Inspired by this Thread, i (Uli) did a rewrite of the store-passwd.sh-script. You need to use BASH for this to execute. Better use the Script above if you are not sure!

#!/ffp/bin/sh
# This script was written by Ulrich Wolf <ffp [a] wolf-u [dot] li>
# Inspired by the original Scripts of fonz and OneArmedMan

# Defining the various locations for these files:
BACKUPLOCATION[0]="/sys/mtd1"
BACKUPLOCATION[1]="/sys/mtd2"
BACKUPLOCATION[2]="/mnt/HD_a4/.systemfile/AccountFile"
BACKUPLOCATION[3]="/mnt/HD_b4/.systemfile/AccountFile"

# Defining the backup-locations of the files
BACKUPFILE[0]="/etc/shadow"
BACKUPFILE[1]="/etc/group"
BACKUPFILE[2]="/etc/passwd"
BACKUPFILE[3]="/etc/samba/smbpasswd"
# Inactive Files
#BACKUPFILE[4]="/etc/ftp_tbl"
#BACKUPFILE[5]="/etc/ftpgroup"

# Mounting the internal DRAM
mount -t minix /dev/mtdblock0 /sys/mtd1
mount -t minix /dev/mtdblock1 /sys/mtd2

# Iterate through the files for backup of the files
for BUFILESEQ in $(seq 0 $((${#BACKUPFILE[@]} - 1)))
do
	# Iterate through the backup-locations of the files
	for BULOCSEQ in $(seq 0 $((${#BACKUPLOCATION[@]} - 1)))
	do
		if [ -e ${BACKUPLOCATION[$BULOCSEQ]}/${BACKUPFILE[$BUFILESEQ]##*/} ]; then
			# File exists, copy the original one
			echo -n "${BACKUPFILE[$BUFILESEQ]##*/} found in ${BACKUPLOCATION[$BULOCSEQ]}, copying"
			cp -f ${BACKUPFILE[$BUFILESEQ]} ${BACKUPLOCATION[$BULOCSEQ]}/. 2> /dev/null && echo "done" || echo "failed"
		else
			# File does not exist, skip
			echo "${BACKUPFILE[$BUFILESEQ]##*/} not found in ${BACKUPLOCATION[$BULOCSEQ]}, skipping"
		fi
	done
done


echo -n "Flushing unwritten filesystem I/O buffers..."
sync && echo "done" || echo "failed"

# Unmount the internal DRAM
umount /sys/mtd1
umount /sys/mtd2

echo "Backup complete"
exit 0
Personal tools
Advertisement