-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtweet.sh
executable file
·104 lines (94 loc) · 2.28 KB
/
tweet.sh
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
104
#!/bin/bash
# -------------------------------------------------------------------------
# siap-siap
CURL_CA_BUNDLE=/root/cacert.pem
certificate="/root/cacert.pem"
ua="Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36"
# change directory to script's directory
DIR="$( cd "$( dirname "$0" )" && pwd )"
cd "$DIR"
setup() {
mkdir -p temp
hari=$(date +%u)
tanggal=$(date +%d)
bulan=$(date +%m)
tahun=$(date +%Y)
jam=$(date +%H)
menit=$(date +%M)
aksi_array=()
# check if twit command exists
if [ ! -f /usr/bin/twit ]; then
echo "[tweet.sh] command 'twit' tidak ditemukan! buat link di '/usr/bin/twit'"
ln -s "$DIR/twit.py" "/usr/bin/twit" > /dev/null 2>&1
# success?
if [ ! -f /usr/bin/twit ]; then
echo "[tweet.sh] ERROR: gagal membuat link ke '/usr/bin/twit' !"
echo "[tweet.sh] periksa permission atau buat link secara manual"
exit
else
echo "[tweet.sh] SUKSES: link command 'twit' berhasil dibuat"
echo ""
fi
fi
# load plugin
for f in plugin/*; do
. $f
# echo "$f"
done
if [[ -z "$1" ]]; then
aksi_num=${#aksi_array[*]}
aksi=${aksi_array[$((RANDOM%aksi_num))]}
# make sure aksi not same like before
if [[ -f "temp/$aksi.last" ]]; then
setup
else
rm temp/*.last
touch "temp/$aksi.last"
fi
else
aksi="$1"
if [[ "$aksi_nolog" != "1" ]]; then
rm temp/*.last
touch "temp/$aksi.last"
fi
fi
}
getJam() {
# getjam=$(date +'%H:%M:%S')
getjam=$(date +'%H:%M')
}
cekonline() {
if ! eval "ping -c 1 8.8.4.4 -w 2 > /dev/null 2>&1"; then
echo "ERROR: Nggak online!"
exit 1
fi
}
post_tweet() {
# persiapan:
# sebelumnya script twit.py sudah di link ke /usr/bin/twit , chmod +x
if [[ ! -z "$tweet_status" ]]; then
getJam
echo "[twit][$getjam] : $tweet_status"
twit -s "$tweet_status"
# echo "$tweet_status" | ttytter -status=-
#cekposting
else
echo "ERROR_STATUS_KOSONG: $aksi"
fi
}
cekonline
if [[ -z "$1" ]]; then
setup
"$aksi"_main
post_tweet
# once more when action is greeting
if [[ $aksi = "twit_greeting" || $aksi = "twit_ramadhan_greet" ]]; then
setup
"$aksi"_main
post_tweet
fi
else
setup "$1"
"$aksi"_main "${@:2}"
post_tweet
fi