Nxl67002 - AndLinux - Files: Difference between revisions

From miki
Jump to navigation Jump to search
Line 693: Line 693:


=== Directory ~/bin ===
=== Directory ~/bin ===
'''backup_noekeon''' - This file must be '''chmod +755'''.
'''backup_main''' - This file must be '''chmod +700'''.
{{hiddenSourceFile|~/|backup_noekeon|<source lang="bash" class="backup_noekeon">
{{hiddenSourceFile|~/bin/|backup_main|<source lang="bash" class="backup_main">
#! /bin/bash
#! /bin/bash


# This script will create a backup of the miki wiki database on noekeon.org
# This script will create a backup of the miki wiki database on noekeon.org
# Backup will be saved in ~/backup


# Helper functions
# Some environment variable
#
BACKUPDIR=~/backup
# These functions assume that the following env. variables are defined:
WIKINAME=www.noekeon.org_miki
#
FSQLNAMEBASE=$BACKUPDIR/wiki-$WIKINAME-$(date '+%Y%m%d')
# THISDAY
FFILENAMEBASE=$BACKUPDIR/wiki-$WIKINAME-$(date '+%Y%m%d')
# THISWEEK
FSQLNAME=${FSQLNAMEBASE}.sql.gz
# THISMONTH
FFILENAME=${FFILENAMEBASE}.tar.gz
# THISYEAR
MAXBACKUPCOUNT=3
# NEXTDAILY
BACKUPRC=~/.mybackuprc
# NEXTWEEKLY
THISWEEK=$(date '+%Y%V')
# NEXTMONTHLY
THISMONTH=$(date '+%Y%m')
# NEXTYEARLY
THISYEAR=$(date '+%Y')
# BACKUPPREFIX
# BACKUPID
# BACKUPEXT
# BACKUPCMD
# BACKUPDIR


if [ -n "$1" ]; then
#Read our resource file if it exists, or create a new one...
BACKUP_DEF_FILE=$1
if [ -a $BACKUPRC ]
then
# ! HOMEDIR must be chmod 755 at most, and $BACKUPRC chmod 644 at most
. $BACKUPRC
else
else
echo "Usage: $0 backup-definition-file"
NEXTWEEKLY=$THISWEEK # Next weekly is this week by default
echo
NEXTMONTHLY=$THISMONTH # Next monthly is this month by default
echo "Format of backup-definition-file: one or more entry as follows, separated by empty lines."
NEXTYEARLY=$THISYEAR # Next yearly is this year by default
echo
echo " BACKUPPREFIX=prefix_of_all_backup_files_for_this_entry"
echo " BACKUPID=some_id_used_to_generate_backup_file_name"
echo " BACKUPEXT=sql.gz"
echo " BACKUPCMD=\"... some command generating the backup data to standard output ... \""
exit 1
fi
fi


function makeweekly()
#Create backup parent directory
{
mkdir -p $BACKUPDIR
local FNAMENEW=${FNAMEBASE}.weekly.${BACKUPEXT}
echo "Creating backup file '${FNAMENEW}'..."
cp $FNAMEDAILY ${FNAMENEW}
NEXTWEEKLY=$((NEXTWEEKLY+1)) # This will overflow but 201001 > 200954 so it's ok
}


function makedaily()
function makemonthly()
{
{
local FSQLNAMENEW=${FSQLNAMEBASE}.daily.sql.gz
local FNAMENEW=${FNAMEBASE}.monthly.${BACKUPEXT}
echo "Creating backup file ${FSQLNAMENEW}..."
echo "Creating backup file '${FNAMENEW}'..."
cp $FNAMEDAILY ${FNAMENEW}
mv $FSQLNAME ${FSQLNAMENEW} # We rename the file!
NEXTMONTHLY=$((NEXTMONTHLY+1)) # This will overflow but 201001 > 200913 so it's ok
local FFILENAMENEW=${FFILENAMEBASE}.daily.tar.gz
echo "Creating backup file ${FFILENAMENEW}..."
mv $FFILENAME ${FFILENAMENEW} # We rename the file!
}
}


function makeweekly()
function makeyearly()
{
{
local FSQLNAMENEW=${FSQLNAMEBASE}.weekly.sql.gz
local FNAMENEW=${FNAMEBASE}.yearly.${BACKUPEXT}
echo "Creating backup file ${FSQLNAMENEW}..."
echo "Creating backup file '${FNAMENEW}'..."
cp $FSQLNAME ${FSQLNAMENEW}
cp $FNAMEDAILY ${FNAMENEW}
NEXTYEARLY=$((NEXTYEARLY+1))
local FFILENAMENEW=${FFILENAMEBASE}.weekly.tar.gz
echo "Creating backup file ${FFILENAMENEW}..."
cp $FFILENAME ${FFILENAMENEW}
NEXTWEEKLY=$((NEXTWEEKLY+1)) # This will overflow but 201001 > 200954 so it's ok
}
}


function makemonthly()
function rmoldest()
{
{
local SUFFIX=$1
local FSQLNAMENEW=${FSQLNAMEBASE}.monthly.sql.gz
local NBR=$2
echo "Creating backup file ${FSQLNAMENEW}..."

cp $FSQLNAME ${FSQLNAMENEW}
#Count files
local FFILENAMENEW=${FFILENAMEBASE}.monthly.tar.gz
file_count=$(ls ${BACKUPDIR}/*${SUFFIX}| wc -l)
echo "Creating backup file ${FFILENAMENEW}..."

cp $FFILENAME ${FFILENAMENEW}
#Delete files while we have more than $NBR
NEXTMONTHLY=$((NEXTMONTHLY+1)) # This will overflow but 201001 > 200913 so it's ok
while [ $file_count -gt $NBR ]
do
#Delete alphabetically oldest file (ls sort by name is default)
rm $(ls ${BACKUPDIR}/*${SUFFIX} | head -n 1)
#Count files again
file_count=$(ls ${BACKUPDIR}/*${SUFFIX}| wc -l)
done
}
}


function makeyearly()
function create-backups()
{
{
# Some environment variables
local FSQLNAMENEW=${FSQLNAMEBASE}.yearly.sql.gz
BACKUPDIR=~/backup
echo "Creating backup file ${FSQLNAMENEW}..."
BACKUPRC=~/.backup-${BACKUPID}.${BACKUPEXT}.rc
cp $FSQLNAME ${FSQLNAMENEW}
THISDAY=$(date '+%Y%j')
local FFILENAMENEW=${FFILENAMEBASE}.yearly.tar.gz
THISWEEK=$(date '+%Y%V')
echo "Creating backup file ${FFILENAMENEW}..."
THISMONTH=$(date '+%Y%m')
cp $FFILENAME ${FFILENAMENEW}
THISYEAR=$(date '+%Y')
NEXTYEARLY=$((NEXTYEARLY+1))

#Read our resource file if it exists, or create a new one...
if [ -a $BACKUPRC ]
then
# ! HOMEDIR must be chmod 755 at most, and $BACKUPRC chmod 644 at most
. $BACKUPRC
else
NEXTDAILY=$THISDAY # Next daily is this day by default
NEXTWEEKLY=$THISWEEK # Next weekly is this week by default
NEXTMONTHLY=$THISMONTH # Next monthly is this month by default
NEXTYEARLY=$THISYEAR # Next yearly is this year by default
fi

#We exit immediately if script was already run today...
[ $THISDAY -ge $NEXTDAILY ] || return 0

echo "Creating backup for:"
echo " BACKUPPREFIX=$BACKUPPREFIX"
echo " BACKUPID=$BACKUPID"
echo " BACKUPEXT=$BACKUPEXT"
echo " BACKUPCMD=$BACKUPCMD"

# Some environment variables
FNAMEBASE=${BACKUPDIR}/${BACKUPPREFIX}-$(date '+%Y%m%d')-${BACKUPID}
FNAMEDAILY=${FNAMEBASE}.daily.${BACKUPEXT}
#First we need to restore the ssh-agent context, if any
eval $(/usr/local/bin/ssh-agent-refresh.sh) > /dev/null
#Create backup parent directory
mkdir -p $BACKUPDIR
#We create the daily backup file
echo "Creating the daily backup file '$FNAMEDAILY'..."
eval $BACKUPCMD > "$FNAMEDAILY"
NEXTDAILY=$((NEXTDAILY+1)) # This will overflow but 2010001 > 2009367 so it's ok
#Now, depending on current date, we'll create weekly, monthly or yearly backups...
[ $THISWEEK -ge $NEXTWEEKLY ] && makeweekly
[ $THISMONTH -ge $NEXTMONTHLY ] && makemonthly
[ $THISYEAR -ge $NEXTYEARLY ] && makeyearly
#Now let's delete the oldest backups
rmoldest "-${BACKUPID}.daily.${BACKUPEXT}" "3"
rmoldest "-${BACKUPID}.weekly.${BACKUPEXT}" "3"
rmoldest "-${BACKUPID}.monthly.${BACKUPEXT}" "3"
rmoldest "-${BACKUPID}.yearly.${BACKUPEXT}" "3"
#Finally we update our resource file
umask 022
echo "NEXTDAILY=${NEXTDAILY}" >$BACKUPRC
echo "NEXTWEEKLY=${NEXTWEEKLY}" >>$BACKUPRC
echo "NEXTMONTHLY=${NEXTMONTHLY}" >>$BACKUPRC
echo "NEXTYEARLY=${NEXTYEARLY}" >>$BACKUPRC
}
}


#Creates the backup for each entry in the backup definition file
#First we need to restore the ssh-agent context, if any
while read -u 3 LINE; do
eval $(/usr/local/bin/ssh-agent-refresh.sh) > /dev/null
if [ -z "$LINE" ]; then
BACKUPPREFIX=
BACKUPID=
BACKUPEXT=
BACKUPCMD=
else
eval $LINE
[ -n "$BACKUPPREFIX" ] && [ -n "$BACKUPID" ] && [ -n "$BACKUPEXT" ] && [ -n "$BACKUPCMD" ] && create-backups
fi
done 3< $BACKUP_DEF_FILE
</source>
}}


'''set-network.sh''' - This file must be '''chmod +700'''.
#We create the SQL backup file
{{hiddenSourceFile|~/bin/|set-network.sh|<source lang="bash" class="set-network.sh">
echo "Backing up the MySQL database to '$FSQLNAME'..."
#! /bin/bash
ssh noekeon '~daemenj/private/backup_wiki ~daemenj/kiwi.noekeon.org/miki/LocalSettings.php' > "$FSQLNAME"


# Exit if no network name given or if no corresponding configuration file
#We create the wiki directory backup file
NETWORK=$1
echo "Backing up the files & extensions to '$FFILENAME'..."
[ -n "$NETWORK" ] || exit 1
ssh noekeon 'cd ~daemenj/kiwi.noekeon.org; /usr/bin/nice -n 19 tar -cz miki/' > "$FFILENAME"


# Some logging...
#Now, depending on current date, we'll create daily, weekly, monthly or yearly backups...
echo -e "\t[$HOSTNAME] Running $(basename $0) '$NETWORK'..." 1>&2
[ $THISWEEK -ge $NEXTWEEKLY ] && makeweekly
[ $THISMONTH -ge $NEXTMONTHLY ] && makemonthly
[ $THISYEAR -ge $NEXTYEARLY ] && makeyearly
makedaily


# Checked all needed files are present...
SSH_CONFIG_FILE=~/".ssh/config-$NETWORK"
if ! [ -a $SSH_CONFIG_FILE -a -a /etc/privoxy/config-$NETWORK ]; then
echo "ERROR! I don't know how to reconfigure network '$NETWORK'" 1>&2
exit 255
fi


#Now let's delete the oldest backups
# Now let's reconfigure as needed...
if [ $NETWORK = "nxp_auth" ]; then
echo -e "\t!!! UPDATE PASSWORD AT ~/.ssh/proxy.conf AND RE-RUN THIS COMMAND !!!"
fi


~/bin/sshproxy stop
function rmoldest()
ln -sf $SSH_CONFIG_FILE ~/.ssh/config
sudo /etc/privoxy/set-network-config "$NETWORK"
~/bin/sshproxy start
</source>
}}

'''sshproxy''' - This file must be '''chmod +700'''.
{{hiddenSourceFile|~/bin/|sshproxy|<source lang="bash" class="sshproxy">
#! /bin/sh
#
# sshproxy Setup ssh port forwarding (imap) and SOCKS 5 proxy
# ssh connection is made persistent thanks to autossh
#
# Author: Michaël Peeters
#
# Prerequisite: ssh-agent must be running in background (autossh won't ask for password)
#
# chkconfig: 235 70 40
# description: sshproxy startup script.

SUBSYS=sshproxy
TARGET=/usr/bin/autossh
BINDADDRESS=0.0.0.0 #0.0.0.0 external connection allowed; 127.0.0.1 only connection from localhost allowed

# Source function library.
#. /etc/rc.d/init.d/functions

# Some macros to make the below more readable
#PID_FILE=/var/run/$SUBSYS.pid
#LOCK_FILE=/var/lock/subsys/$SUBSYS
PID_FILE=~/.$SUBSYS.pid
LOCK_FILE=~/.$SUBSYS.lock

echo_success()
{
{
echo "\t\t[OK ]"
local EXT=$1
}
local TYPE=$2
local NBR=$3


echo_failure()
#Count files
{
file_count=$(ls $BACKUPDIR/*.${TYPE}${EXT}| wc -l)
echo "\t\t[FAILED]"
}



#Delete files while we have more than $NBR
start()
while [ $file_count -gt $NBR ]
{
do
echo -n "Starting $SUBSYS:"
#Delete alphabetically oldest file (ls sort by name is default)

rm $(ls $BACKUPDIR/*.${TYPE}${EXT} | head -n 1)
if [ -f $LOCK_FILE ]; then
#Count files again
RETVAL=1
file_count=$(ls $BACKUPDIR/*.${TYPE}${EXT}| wc -l)
else
done
export AUTOSSH_PIDFILE=$PID_FILE
export AUTOSSH_POLL=300
/usr/bin/autossh -M 0 -f -N -n -q -L ${BINDADDRESS}:9025:smtp.priorweb.be:25 -L ${BINDADDRESS}:9143:mail.priorweb.be:143 -L ${BINDADDRESS}:9026:mail.altranweb.be:25 -L ${BINDADDRESS}:9144:mail.altranweb.be:143 -D ${BINDADDRESS}:1080 noekeon
RETVAL=$?
fi

if [ $RETVAL -eq 0 ]; then
touch $LOCK_FILE
echo_success
else
echo_failure
fi
}
}


stop()
rmoldest ".sql.gz" "daily" "3"
{
rmoldest ".tar.gz" "daily" "3"
# don't delete lock file while pid file not deleted
rmoldest ".sql.gz" "weekly" "3"
# don't delete pidfile while process is running
rmoldest ".tar.gz" "weekly" "3"

rmoldest ".sql.gz" "monthly" "3"
echo -n "Stopping $SUBSYS:"
rmoldest ".tar.gz" "monthly" "3"

rmoldest ".sql.gz" "yearly" "3"
status
rmoldest ".tar.gz" "yearly" "3"
case "$RETVAL" in
0)
( kill -TERM $pid || kill -KILL $pid ) >/dev/null
RETVAL=$?
;;
1) RETVAL=0;;
2) RETVAL=0;;
*) ;;
esac

if [ $RETVAL -eq 0 ]; then
rm -f $LOCK_FILE
rm -f $PID_FILE
echo_success
else
echo_failure
fi
}

status()
{
# no lockfile --> (3) Not started.
# lockfile present, no pidfile --> (2) Started, but terminated
# lockfile & pidfile present, no process --> (1) Started, but killed
# lockfile, pidfile & process present --> (0) Started.
# -- note this is opposite order compared to status function, but support multiple autossh running concurrently

unset pid
read pid 2>/dev/null < $PID_FILE

if [ ! -f $LOCK_FILE ]; then
# /var/lock/subsys/$SUBSYS doesn't exist
RETVAL=3
elif [ "$pid" = "" ] ; then
# lock file exists, but file "/var/run/*.pid" doesn't exist
RETVAL=2
elif ( ! ps -p $pid | grep -q $pid ) ; then
# Both files exist but process is not running anymore...
RETVAL=1
else
# Everything is fine
RETVAL=0
fi
}

reload()
{
read pid 2>/dev/null < $PID_FILE
kill -HUP $pid
RETVAL=$?
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
case "$RETVAL" in
0)
echo -n "$SUBSYS (pid $pid) is running"
if ( ps -fu $USER | grep -q " $pid .*/ssh " ) ; then echo " and connection is alive..."; else echo " but connection is dead..."; fi
;;
1)
echo "$SUBSYS dead but pid file exists"
;;
2)
echo "$SUBSYS dead but subsys locked..."
;;
3)
echo "$SUBSYS is stopped"
;;
esac
;;
reload)
reload
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|status|reload|restart}"
RETVAL=1
esac

exit $RETVAL
</source>
}}

'''startup.sh''' - This file must be '''chmod +700'''.
{{hiddenSourceFile|~/bin/|startup.sh|<source lang="bash" class="startup.sh">
#! /bin/bash

# Start ssh-agent and add key
##############################
eval `ssh-agent-refresh.sh` >/dev/null
if ( ! ( ssh-add -L | grep -q $USER ) ); then ssh-add; fi


# Start ssh-proxy - USELESS - ALWAYS FOLLOWED BY A CALL TO ~/bin/network-* which restarts sshproxy anyway
#Finally we update our resource file
##############################
umask 022
#~/bin/sshproxy stop >/dev/null
echo "NEXTWEEKLY=${NEXTWEEKLY}" >$BACKUPRC
#~/bin/sshproxy start
echo "NEXTMONTHLY=${NEXTMONTHLY}" >>$BACKUPRC
echo "NEXTYEARLY=${NEXTYEARLY}" >>$BACKUPRC
</source>
</source>
}}
}}

Revision as of 22:52, 16 November 2009

These are the configuration files on Configuration NXP Dell Latitude D620 - AndLinux.

Windows Host files

settings.txt

AndLinux files

Directory /etc

Directory /usr/local/bin

be - This script would ideally require to add the following line to /etc/sudoers:

ALL ALL=(ALL) NOPASSWD: /bin/loadkeys

directory ~

.bashrc - Everything before #### CUSTOMIZATION is the original file.

Directory ~/.ssh

Directory ~/etc

crontab - Install this file with

crontab -u beq06659 ~/etc/crontab

Directory ~/bin

backup_main - This file must be chmod +700.

set-network.sh - This file must be chmod +700.

sshproxy - This file must be chmod +700.

startup.sh - This file must be chmod +700.