bin sh PATH cat usr local etc stdpath move picture files to production

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
#!/bin/sh
PATH=`cat /usr/local/etc/stdpath`
# move picture files to production
# housekeeping
cd /usr/local/etc
CMDNAME=`basename $0`
CONF=`cat $CMDNAME.conf`
LIST=`echo "$CONF"|sed '/^Input/,/^[ ]*$/!d'|sed '/^--*/d'|sed '$d'`
INP=/usr/resin/resin-3.0.19/webapps/backoffice/tmpimages
OUT=/usr/resin/resin-3.0.19/webapps
OUT1=/usr/resin/resin-dev/resin-3.0.19/webapps
OUT2=/usr/resin/resin-apache/resin-3.0.19/webapps
USER=`whoami`
# move pictures according to the configuration file
echo "$LIST"|
while read LINE
do
set -- `echo $LINE`
if [ $# -eq 3 ]
then
if sudo test ! -d $3
then
echo "$3 not a directory" 1>&2
break
elif echo $3|grep -v $INP >/dev/null
then
echo "$3 illegal directory" 1>&2
break
else
echo $3 >/tmp/tmp.$$
fi
elif [ "$1" = "#" ]
then
INPUT=`cat /tmp/tmp.$$`
FILES=`sudo find $INPUT -type f -maxdepth 1 -print`
if [ -n "$FILES" ]
then
sudo rm -f $INPUT/* 2>/dev/null
fi
else
INPUT=`cat /tmp/tmp.$$`
FILES=`sudo find $INPUT -type f -maxdepth 1 -print`
if [ -n "$FILES" ]
then
HOST=`echo $LINE|awk -F: '{print $1}'`
DIR=`echo $LINE|awk -F: '{print $2}'`
if echo $DIR|grep backoffice >/dev/null
then
BACKOFFICE=`echo $DIR|sed 's/images.*//'`
fi
if echo $DIR|grep -v $OUT|grep -v $OUT1|
grep -v $OUT2 >/dev/null
then
echo "$LINE illegal directory"
break
else
STATUS=`ssh -n $HOST "sudo test -d $DIR;\
echo \\$?"`
if [ $STATUS -ne 0 ]
then
echo "$LINE not a directory"
if echo $DIR|grep travelist >/dev/null
then
TRAVELIST=`echo $DIR|
sed 's/images.*//'`
cd $BACKOFFICE
scp -pqr images $HOST:/tmp
ssh $HOST "cd /tmp;sudo cp\
-fpr images $TRAVELIST;\
sudo chown -Rf root:root\
$TRAVELIST/images;sudo rm\
-rf /tmp/images"
else
break
fi
fi
fi
if [ `hostname -s` != $HOST ]
then
sudo cp -fp $INPUT/* $HOME/.pictures\
2>/dev/null
OWNER=`ssh -n $HOST "ls -ld $DIR"|
awk '{print $3 ":" $4}'`
sudo chown $USER:$USER $HOME/.pictures/*
scp -pq $HOME/.pictures/* $HOST:$HOME/.pictures
ssh -n $HOST sudo chown $OWNER\
$HOME/.pictures/*
ssh -n $HOST sudo cp -fp $HOME/.pictures/* $DIR
ssh -n $HOST sudo rm -f $HOME/.pictures/*
else
sudo cp -fp $INPUT/* $DIR 2>/dev/null
fi
fi
fi
done
# cleanup and quit
rm -f $HOME/.pictures/*
rm -f /tmp/*.$$
exit