updated on Tue Jan 10 04:01:21 UTC 2012
[aur-mirror.git] / cltotiny2 / cltotiny
bloba8ac304f408bd92a4b9c5186d86157bc57584bbc
1 #!/bin/bash
3 i=1
5 if [ -n "`echo "$@"|grep "\-\-silent"`" ]; then
6 nieloguj=1
7 else
8 nieloguj=0
9 fi
11 if [ -a /tmp/.cltotiny-lock ]; then
12 pid=`cat /tmp/.cltotiny-lock`
13 if [ -z "`ps $pid|grep "$pid "`" ]; then
14 `rm /tmp/.cltotiny-lock`
15 fi
18 if [ -n "`echo "$@"|grep "\-\-kill"`" ]; then
19 if [ -a /tmp/.cltotiny-lock ]; then
20 pid="`cat /tmp/.cltotiny-lock`"
21 echo "Wyslanie polecenia zakonczenia"
22 `kill $pid`
23 if [ -n "`ps $pid|grep "$pid "`" ]; then
24 `kill -9 $pid`
26 else
27 echo "cltotiny nie jest uruchomiony"
29 i=0
30 fi
32 if [ -n "`echo "$@"|grep "\-\-help"`" ]; then
33 echo "Use --silent if you dont want see logs"
34 echo "Use --kill to stop active copy"
35 i=0
38 #ctrl+c
39 trap 'echo "Zamykanie (bezpieczne)"; rm /tmp/.cltotiny-lock; exit' SIGINT
40 #close window/...
41 trap 'echo "Zamykanie (bezpieczne)"; rm /tmp/.cltotiny-lock; exit' SIGHUP
42 #kill
43 trap 'echo "Zamykanie (bezpieczne)"; rm /tmp/.cltotiny-lock; exit' SIGTERM
45 if [ -a /tmp/.cltotiny-lock ] && [ $i != 0 ]; then
46 echo "Cltotiny is already active (/tmp/.cltotiny-lock exist). PID `cat /tmp/.cltotiny-lock`"
47 echo "Use --kill to stop active copy"
48 else
50 if [ $i = 1 ]; then
51 echo $$ > /tmp/.cltotiny-lock
54 zapytanie=0
55 while [ $i != 0 ]; do
57 if [ $i = 1 ]; then
58 staryschowek1="`xsel -p`"
59 if [ $? -gt 0 ]; then
60 rm /tmp/.cltotiny-lock
61 if [ $nieloguj != 1 ]; then
62 echo "`date +%H:%M:%S` BLAD: xsel: Prawdopodobnie X serwer niejest wlaczony"
64 exit
66 staryschowek2="`xsel -b`"
67 if [ $? -gt 0 ]; then
68 rm /tmp/.cltotiny-lock
69 if [ $nieloguj != 1 ]; then
70 echo "`date +%H:%M:%S` BLAD: xsel: Prawdopodobnie X serwer niejest wlaczony"
72 exit
75 nowyschowek1="`xsel -p`"
76 if [ $? -gt 0 ]; then
77 rm /tmp/.cltotiny-lock
78 if [ $nieloguj != 1 ]; then
79 echo "`date +%H:%M:%S` BLAD: xsel: Prawdopodobnie X serwer zostal wylaczony"
81 exit
82 fi
83 nowyschowek2="`xsel -b`"
84 if [ $? -gt 0 ]; then
85 rm /tmp/.cltotiny-lock
86 if [ $nieloguj != 1 ]; then
87 echo "`date +%H:%M:%S` BLAD: xsel: Prawdopodobnie X serwer zostal wylaczony"
89 exit
91 #Czy to moze byc link
92 if [ -z "`echo $nowyschowek1|grep ";"`" ] && [ -z "`echo $nowyschowek1|grep "\ "`" ] && [ "${nowyschowek1:0:1}" != " " ] && [ -n "`echo $nowyschowek1|grep "\."`" ] && [ -n "`echo $nowyschowek1|grep "\/"`" ] && [ -n "`echo $nowyschowek1|grep "^http\:\/\/"`" ] && [ -z "`echo $nowyschowek1|grep "^\/"`" ] && [ -z "`echo $nowyschowek1|grep "^\~"`" ] && [ -z "`echo $nowyschowek1|grep "^\."`" ] && [ "$staryschowek1" != "$nowyschowek1" ] && [ -z "`echo $nowyschowek1|grep rapidshare.com`" ]; then
93 if [ -z "`echo $nowyschowek1|grep tiny.pl/`" ]; then
94 z=`lynx http://tiny.pl/?adres=$nowyschowek1 --dump | grep "\[6\]"`
95 if [ $? -gt 0 ]; then
96 if [ $nieloguj != 1 ]; then
97 zapytanie=$[10#$zapytanie+10#1]
98 echo "$zapytanie) `date +%H:%M:%S` BLAD: Wyslanie zapytania (sch1) $nowyschowek1 NIEUDALO SIE uzyskac odpowiedzi od tiny.pl!"
100 staryschowek1=$nowyschowek1
101 else
102 if [ $nieloguj != 1 ]; then
103 zapytanie=$[10#$zapytanie+10#1]
104 echo "$zapytanie) `date +%H:%M:%S` Wyslanie zapytania (sch1) $nowyschowek1"
106 z=${z:6}
107 staryschowek1="$z"
108 echo -n "$z" | xsel -p
110 else
111 `firefox "$nowyschowek1"`&
112 if [ $nieloguj != 1 ]; then
113 zapytanie=$[10#$zapytanie+10#1]
114 echo "$zapytanie) `date +%H:%M:%S` Otwarcie $nowyschowek1"
116 staryschowek1=" "
117 nowyschowek1=" "
118 echo -n " " | xsel -p
122 #Czy to moze byc link
123 if [ -z "`echo $nowyschowek2|grep ";"`" ] && [ -z "`echo $nowyschowek2|grep "\ "`" ] && [ "${nowyschowek2:0:1}" != " " ] && [ -n "`echo $nowyschowek2|grep "\."`" ] && [ -n "`echo $nowyschowek2|grep "\/"`" ] && [ -n "`echo $nowyschowek1|grep "^http\:\/\/"`" ] && [ -z "`echo $nowyschowek2|grep "^\/"`" ] && [ -z "`echo $nowyschowek2|grep "^\~"`" ] && [ -z "`echo $nowyschowek2|grep "^\."`" ] && [ "$staryschowek2" != "$nowyschowek2" ] && [ -z "`echo $nowyschowek2|grep rapidshare.com`" ]; then
124 if [ -z "`echo $nowyschowek2|grep tiny.pl/`" ]; then
125 z=`lynx http://tiny.pl/?adres=$nowyschowek2 --dump | grep "\[6\]"`
126 if [ $? -gt 0 ]; then
127 if [ $nieloguj != 1 ]; then
128 zapytanie=$[10#$zapytanie+10#1]
129 echo "$zapytanie) `date +%H:%M:%S` BLAD: Wyslanie zapytania ze (sch2) $nowyschowek2 NIEUDALO SIE uzyskac odpowiedzi od tiny.pl!"
131 staryschowek2=$nowyschowek2
132 else
133 if [ $nieloguj != 1 ]; then
134 zapytanie=$[10#$zapytanie+10#1]
135 echo "$zapytanie) `date +%H:%M:%S` Wyslanie zapytania ze (sch2) $nowyschowek2"
137 z=${z:6}
138 staryschowek2="$z"
139 echo -n "$z" | xsel -b
144 sleep 1
145 i=$[10#$i+10#1]
146 done