├── README.md └── jam.sh /README.md: -------------------------------------------------------------------------------- 1 | ## Sync Date OpenWrt with Domain Bug 2 | - Sync date openwrt by picking date from selected domain. 3 | - Sinkronisasi waktu pada OpenWrt dengan mengambil data waktu dari domain terpilih. 4 | - Mendukung sinkronisasi waktu setelah modem/koneksi internet tersedia. 5 | - Pemeriksa koneksi (jika menggunakan mode **``cron``**, maka script akan memeriksa koneksi, lalu merestart aplikasi VPN jika koneksi internet tidak tersedia) 6 | - Pengaturan timezone (zona waktu) secara otomatis mengikuti pengaturan **``LuCI - System - System - Timezone``**. 7 | - Mendukung autorestart VPN tunnels: 8 | - OpenClash 9 | - Passwall 10 | - ShadowsocksR 11 | - ShadowsocksR++ 12 | - v2ray 13 | - v2rayA 14 | - xray 15 | - Libernet 16 | - Xderm Mini 17 | - Wegare STL 18 | 19 | ### Default Usage - Pemakaian Dasar 20 | - Install **``paket yang dibutuhkan``** terlebih dahulu dengan membuka terminal/putty/dsb: 21 | 22 | ``` 23 | opkg update && opkg install curl wget 24 | ``` 25 | 26 | - Paste command dibawah untuk memasang script ``jam.sh`` 27 | 28 | Menggunakan **`wget`** 29 | ``` 30 | wget --no-check-certificate "https://raw.githubusercontent.com/vitoharhari/sync-date-openwrt-with-bug/main/jam.sh" -O /usr/bin/jam.sh && chmod +x /usr/bin/jam.sh 31 | ``` 32 | Menggunakan **`curl`** 33 | ``` 34 | curl -sL raw.githubusercontent.com/vitoharhari/sync-date-openwrt-with-bug/main/jam.sh > /usr/bin/jam.sh && chmod +x /usr/bin/jam.sh 35 | ``` 36 | - Masukkan command dibawah ke **``LuCI -> System -> Startup -> Local Startup``** atau di **``rc.local``** jika di terminal 37 | 38 | ``` 39 | /usr/bin/jam.sh www.site.com 40 | ``` 41 | 42 | - Jika menggunakan crontab ( cek koneksi setiap 1 jam, lalu me-restart vpn jika koneksi tidak tersedia ), salin perintah dibawah ini ke **``LuCI -> System -> Schedule Tasks``** Contoh: 43 | 44 | ``` 45 | 0 * * * * /usr/bin/jam.sh www.site.com cron 46 | ``` 47 | 48 | - Perintah diatas juga dapat dimasukkan ke file **``/etc/crontabs/root``** 49 | - Untuk kustomisasi waktu cron lainnya dapat dilihat di [crontab.guru](https://crontab.guru/#0_*_*_*_*) 50 | 51 | ### Advanced Usage - Pemakaian Lanjutan 52 | 53 | - Ganti **``www.site.com ``** dengan **``bug/domain``** kesayangan anda. Contoh: 54 | 55 | ``` 56 | /usr/bin/jam.sh m.youtu.be 57 | ``` 58 | 59 | - Jika menggunakan **``0p0k Telkomsel``** silahkan tambahkan **``:443``** dibelakang bug. Contoh: 60 | 61 | ``` 62 | /usr/bin/jam.sh www.site.com:443 63 | ``` 64 | 65 | - Jika ingin melakukan **``update/pembaruan script``**, silahkan lakukan perintah dibawah ini. 66 | 67 | ``` 68 | /usr/bin/jam.sh update 69 | ``` 70 | Tanda update berhasil adalah seperti ini: 71 | ``` 72 | jam.sh: Updating script... 73 | jam.sh: Downloading script update... 74 | jam.sh: Update done... 75 | jam.sh: update file cleaned up! 76 | Usage: add domain/bug after script!. 77 | jam.sh: Missing URL/Bug/Domain!. Read https://github.com/vitoharhari/sync-date-openwrt-with-bug/blob/main/README.md for details. 78 | ``` 79 | 80 | ### How This Script Work - Cara Kerja Script Ini 81 | - Setelah script dimasukkan ke **``Local Startup``** atau di **``rc.local``** dengan menambahkan domain/bug/URL (maupun port) 82 | - Device OpenWrt restart, lalu script **``memeriksa koneksi internet``** terlebih dahulu. 83 | - Jika internet belum tersedia, script akan **``mengulangi pemeriksaan koneksi sampai koneksi terhubung``**. 84 | - Ketika koneksi sudah terhubung, script akan **``melakukan sinkronisasi waktu``**. 85 | - Jika ada **``aplikasi VPN/Tunneling yang berjalan``**, script akan **``merestart aplikasi VPN yang digunakan``** sebelum melakukan sinkronisasi waktu. 86 | 87 | ### Developer - Pengembang 88 | - Base script and more enhancement codes from AlkhaNet by [Teguh Surya Mungaran](https://github.com/alkhanet26) 89 | - GMT codes and more enhancement codes by [Vito H.S](https://github.com/vitoharhari) 90 | - opkg checker and installer, internet checker, vpn manager, gmt selection codes by [Helmi Amirudin](https://helmiau.com) 91 | -------------------------------------------------------------------------------- /jam.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Sync Jam otomatis berdasarkan bug isp by AlkhaNET 3 | # Extended GMT+7 by vitoharhari 4 | # Simplify usage and improved codes by helmiau 5 | # Supported VPN Tunnels: OpenClash, Passwall, ShadowsocksR, ShadowsocksR++, v2ray, v2rayA, xray, Libernet, Xderm Mini, Wegare 6 | 7 | dtdir="/root/date" 8 | initd="/etc/init.d" 9 | logp="/root/logp" 10 | jamup2="/root/jam2_up.sh" 11 | jamup="/root/jamup.sh" 12 | nmfl="$(basename "$0")" 13 | scver="3.5" 14 | 15 | function nyetop() { 16 | stopvpn="${nmfl}: Stopping" 17 | echo -e "${stopvpn} VPN tunnels if available." 18 | logger "${stopvpn} VPN tunnels if available." 19 | if [[ -f "$initd"/openclash ]] && [[ $(uci -q get openclash.config.enable) == "1" ]]; then "$initd"/openclash stop && echo -e "${stopvpn} OpenClash"; fi 20 | if [[ -f "$initd"/passwall ]] && [[ $(uci -q get passwall.enabled) == "1" ]]; then "$initd"/passwall stop && echo -e "${stopvpn} Passwall"; fi 21 | if [[ -f "$initd"/shadowsocksr ]] && [[ $(uci -q get shadowsocksr.@global[0].global_server) != "nil" ]]; then "$initd"/shadowsocksr stop && echo -e "${stopvpn} SSR++"; fi 22 | if [[ -f "$initd"/v2ray ]] && [[ $(uci -q get v2ray.enabled.enabled) == "1" ]]; then "$initd"/v2ray stop && echo -e "${stopvpn} v2ray"; fi 23 | if [[ -f "$initd"/v2raya ]] && [[ $(uci -q get v2raya.config.enabled) == "1" ]]; then "$initd"/v2raya stop && echo -e "${stopvpn} v2rayA"; fi 24 | if [[ -f "$initd"/xray ]] && [[ $(uci -q get xray.enabled.enabled) == "1" ]]; then "$initd"/xray stop && echo -e "${stopvpn} Xray"; fi 25 | if grep -q "screen -AmdS libernet" /etc/rc.local; then ./root/libernet/bin/service.sh -ds && echo -e "${stopvpn} Libernet"; fi 26 | if grep -q "/www/xderm/log/st" /etc/rc.local; then ./www/xderm/xderm-mini stop && echo -e "${stopvpn} Xderm"; fi 27 | if grep -q "autorekonek-stl" /etc/crontabs/root; then echo "3" | stl && echo -e "${stopvpn} Wegare STL"; fi 28 | if [[ -f "$initd"/zerotier ]] && [[ $(uci -q get zerotier.sample_config.enabled) == "1" ]]; then "$initd"/zerotier stop && echo -e "${stopvpn} Zerotier"; fi 29 | } 30 | 31 | function nyetart() { 32 | startvpn="${nmfl}: Restarting" 33 | echo -e "${startvpn} VPN tunnels if available." 34 | logger "${startvpn} VPN tunnels if available." 35 | if [[ -f "$initd"/openclash ]] && [[ $(uci -q get openclash.config.enable) == "1" ]]; then "$initd"/openclash restart && echo -e "${startvpn} OpenClash"; fi 36 | if [[ -f "$initd"/passwall ]] && [[ $(uci -q get passwall.enabled) == "1" ]]; then "$initd"/passwall restart && echo -e "${startvpn} Passwall"; fi 37 | if [[ -f "$initd"/shadowsocksr ]] && [[ $(uci -q get shadowsocksr.@global[0].global_server) != "nil" ]]; then "$initd"/shadowsocksr restart && echo -e "${startvpn} SSR++"; fi 38 | if [[ -f "$initd"/v2ray ]] && [[ $(uci -q get v2ray.enabled.enabled) == "1" ]]; then "$initd"/v2ray restart && echo -e "${startvpn} v2ray"; fi 39 | if [[ -f "$initd"/v2raya ]] && [[ $(uci -q get v2raya.config.enabled) == "1" ]]; then "$initd"/v2raya restart && echo -e "${startvpn} v2rayA"; fi 40 | if [[ -f "$initd"/xray ]] && [[ $(uci -q get xray.enabled.enabled) == "1" ]]; then "$initd"/xray restart && echo -e "${startvpn} Xray"; fi 41 | if grep -q "screen -AmdS libernet" /etc/rc.local; then ./root/libernet/bin/service.sh -sl && echo -e "${startvpn} Libernet"; fi 42 | if grep -q "/www/xderm/log/st" /etc/rc.local; then ./www/xderm/xderm-mini start && echo -e "${startvpn} Xderm"; fi 43 | if grep -q "autorekonek-stl" /etc/crontabs/root; then echo "2" | stl && echo -e "${startvpn} Wegare STL"; fi 44 | if [[ -f "$initd"/zerotier ]] && [[ $(uci -q get zerotier.sample_config.enabled) == "1" ]]; then 45 | echo -e "${startvpn} Zerotier in 5 secs..." 46 | logger "${startvpn} Zerotier in 5 secs..." 47 | sleep 5 48 | "$initd"/zerotier restart 49 | echo -e "${startvpn} Zerotier DONE!" 50 | else 51 | echo -e "${startvpn} Zerotier unavailable, because unused..." 52 | logger "${startvpn} Zerotier unavailable, because unused..." 53 | fi 54 | } 55 | 56 | function ngecurl() { 57 | curl -si "$cv_type" | grep Date > "$dtdir" 58 | echo -e "${nmfl}: Executed $cv_type as time server." 59 | logger "${nmfl}: Executed $cv_type as time server." 60 | } 61 | 62 | function sandal() { 63 | hari=$(cat "$dtdir" | cut -b 12-13) 64 | bulan=$(cat "$dtdir" | cut -b 15-17) 65 | tahun=$(cat "$dtdir" | cut -b 19-22) 66 | jam=$(cat "$dtdir" | cut -b 24-25) 67 | menit=$(cat "$dtdir" | cut -b 26-31) 68 | 69 | case $bulan in 70 | "Jan") 71 | bulan="01" 72 | ;; 73 | "Feb") 74 | bulan="02" 75 | ;; 76 | "Mar") 77 | bulan="03" 78 | ;; 79 | "Apr") 80 | bulan="04" 81 | ;; 82 | "May") 83 | bulan="05" 84 | ;; 85 | "Jun") 86 | bulan="06" 87 | ;; 88 | "Jul") 89 | bulan="07" 90 | ;; 91 | "Aug") 92 | bulan="08" 93 | ;; 94 | "Sep") 95 | bulan="09" 96 | ;; 97 | "Oct") 98 | bulan="10" 99 | ;; 100 | "Nov") 101 | bulan="11" 102 | ;; 103 | "Dec") 104 | bulan="12" 105 | ;; 106 | *) 107 | return 108 | 109 | esac 110 | 111 | date -u -s "$tahun"."$bulan"."$hari"-"$jam""$menit" > /dev/null 2>&1 112 | echo -e "${nmfl}: Set time to [ $(date) ]" 113 | logger "${nmfl}: Set time to [ $(date) ]" 114 | } 115 | 116 | if [[ "$1" == "update" ]]; then 117 | echo -e "${nmfl}: Updating script..." 118 | echo -e "${nmfl}: Downloading script update..." 119 | curl -sL raw.githubusercontent.com/vitoharhari/sync-date-openwrt-with-bug/main/jam.sh > "$jamup" 120 | chmod +x "$jamup" 121 | sed -i 's/\r$//' "$jamup" 122 | cat << "EOF" > "$jamup2" 123 | #!/bin/bash 124 | # Updater script sync jam otomatis berdasarkan bug/domain/url isp 125 | jamsh='/usr/bin/jam.sh' 126 | jamup='/root/jamup.sh' 127 | [[ -e "$jamup" ]] && [[ -f "$jamsh" ]] && rm -f "$jamsh" && mv "$jamup" "$jamsh" 128 | [[ -e "$jamup" ]] && [[ ! -f "$jamsh" ]] && mv "$jamup" "$jamsh" 129 | echo -e 'jam.sh: Update done...' 130 | chmod +x "$jamsh" 131 | EOF 132 | sed -i 's/\r$//' "$jamup2" 133 | chmod +x "$jamup2" 134 | bash "$jamup2" 135 | [[ -f "$jamup2" ]] && rm -f "$jamup2" && echo -e "${nmfl}: update file cleaned up!" && logger "${nmfl}: update file cleaned up!" 136 | elif [[ "$1" =~ "http://" ]]; then 137 | cv_type="$1" 138 | elif [[ "$1" =~ "https://" ]]; then 139 | cv_type=$(echo -e "$1" | sed 's|https|http|g') 140 | elif [[ "$1" =~ [.] ]]; then 141 | cv_type=http://"$1" 142 | else 143 | echo -e "Usage: add domain/bug after script!." 144 | echo -e "${nmfl}: Missing URL/Bug/Domain!. Read https://github.com/vitoharhari/sync-date-openwrt-with-bug/blob/main/README.md for details." 145 | logger "${nmfl}: Missing URL/Bug/Domain!. Read https://github.com/vitoharhari/sync-date-openwrt-with-bug/blob/main/README.md for details." 146 | fi 147 | 148 | function ngepink() { 149 | if [[ $(curl -si ${cv_type} | grep -c 'Date:') == "1" ]]; then 150 | echo -e "${nmfl}: Connection to ${cv_type} is available, resuming task..." 151 | logger "${nmfl}: Connection to ${cv_type} is available, resuming task..." 152 | else 153 | if [[ "$2" == "cron" ]]; then 154 | echo -e "${nmfl}: cron mode detected and connection to ${cv_type} is unavailable, restarting VPN..." 155 | logger "${nmfl}: cron mode detected and connection to ${cv_type} is unavailable, restarting VPN..." 156 | nyetop 157 | nyetart 158 | else 159 | echo -e "${nmfl}: Connection to ${cv_type} is unavailable, pinging again..." 160 | logger "${nmfl}: Connection to ${cv_type} is unavailable, pinging again..." 161 | sleep 3 162 | ngepink 163 | fi 164 | fi 165 | } 166 | 167 | if [[ ! -z "$cv_type" ]]; then 168 | # Script Version 169 | echo -e "${nmfl}: Script v${scver}" 170 | logger "${nmfl}: Script v${scver}" 171 | 172 | # Runner 173 | if [[ "$2" == "cron" ]]; then 174 | ngepink 175 | else 176 | nyetop 177 | ngepink 178 | ngecurl 179 | sandal 180 | nyetart 181 | fi 182 | 183 | # Cleaning files 184 | [[ -f "$logp" ]] && rm -f "$logp" && echo -e "${nmfl}: logp cleaned up!" && logger "${nmfl}: logp cleaned up!" 185 | [[ -f "$dtdir" ]] && rm -f "$dtdir" && echo -e "${nmfl}: tmp dir cleaned up!" && logger "${nmfl}: tmp dir cleaned up!" 186 | [[ -f "$jamup2" ]] && rm -f "$jamup2" && echo -e "${nmfl}: update file cleaned up!" && logger "${nmfl}: update file cleaned up!" 187 | else 188 | echo -e "Usage: add domain/bug after script!." 189 | echo -e "${nmfl}: Missing URL/Bug/Domain!. Read https://github.com/vitoharhari/sync-date-openwrt-with-bug/blob/main/README.md for details." 190 | logger "${nmfl}: Missing URL/Bug/Domain!. Read https://github.com/vitoharhari/sync-date-openwrt-with-bug/blob/main/README.md for details." 191 | fi 192 | 193 | # Sync Jam otomatis berdasarkan bug isp by AlkhaNET 194 | # Extended GMT+7 by vitoharhari 195 | # Simplify usage and improved codes by helmiau 196 | # Supported VPN Tunnels: OpenClash, Passwall, ShadowsocksR, ShadowsocksR++, v2ray, v2rayA, xray, Libernet, Xderm Mini, Wegare 197 | --------------------------------------------------------------------------------