Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[40fda4]: scripts / S99defaultpasswd Maximize Restore History

Download this file

S99defaultpasswd    62 lines (47 with data), 1.7 kB

#!/bin/sh

WEBROOT=/mnt/flash/www/cgi-bin
WEBROOT_BACKUP=/mnt/flash/backups
FILECMP=/mnt/flash/root/bin/filecmp

button=$(/bin/cpm -N BUTTON)

if [ "$button" == "1" ]; then
	# Backup /etc/passwd if it differs from the current backup
	cmpresult=$($FILECMP /etc/passwd /etc/passwd.bak)
	if [ "$cmpresult" != "1" ]; then
		cp /etc/passwd /etc/passwd.bak
	fi
	# Replace current /etc/passwd with Standard file if it differs
	cmpresult=$($FILECMP /etc.romfs/passwd /etc/passwd)
	if [ "$cmpresult" != "1" ]; then
		cp /etc.romfs/passwd /etc/passwd
	fi

	# Backup .htaccess if it differs from the current backup
	cmpresult=$($FILECMP  $WEBROOT/.htaccess $WEBROOT_BACKUP/.htaccess_backup)
	if [ "$cmpresult" != "1" ]; then
		cp $WEBROOT/.htaccess $WEBROOT_BACKUP/.htaccess_backup
	fi

	# Replace current .htaccess if it differs from the Standardfile
	cmpresult=$($FILECMP  $WEBROOT/.htaccess $WEBROOT_BACKUP/.htaccess_orig)
	if [ "$cmpresult" != "1" ]; then
		cp $WEBROOT_BACKUP/.htaccess_orig $WEBROOT/.htaccess
	fi
	

else 
	#Restore /etc/passwd Backup if it differs from the current file
	cmpresult=$($FILECMP /etc/passwd /etc/passwd.bak)
	if [ "$cmpresult" != "1" ]; then
		cp /etc/passwd.bak /etc/passwd
	fi

	# Restor .htaccess if it differs from the current file
	cmpresult=$($FILECMP  $WEBROOT/.htaccess $WEBROOT_BACKUP/.htaccess_backup)
	if [ "$cmpresult" != "1" ]; then
		cp $WEBROOT_BACKUP/.htaccess_backup $WEBROOT/.htaccess
	fi	
fi



#Fallback if File does not exist or has zero length

if [ -s /etc/passwd ]; then
else
	cp /etc.romfs/passwd /etc/passwd
fi

if [ -s $WEBROOT/.htaccess ]; then
else
	cp $WEBROOT_BACKUP/.htaccess_orig $WEBROOT/.htaccess
fi