dotfiles

Dash Eclipse's dotfiles
git clone git://ezup.dev/dotfiles.git
Log | Files | Refs | README | LICENSE

commit 2e74aecb847e36032aaa70185811140a6637c978
parent 81b28277bb5fa2149795c83b328930dcdae26552
Author: Dash Eclipse <dashezup@disroot.org>
Date:   Tue, 22 Mar 2022 12:17:17 +0000

refactor: remove various shell scripts

moved to "scripts" repo

Diffstat:
D.local/bin/archlinux-installer-base.sh | 96-------------------------------------------------------------------------------
D.local/bin/dwm-helper.sh | 19-------------------
D.local/bin/dwm_update_status.sh | 183-------------------------------------------------------------------------------
D.local/bin/eztmp | 36------------------------------------
D.local/bin/fv | 71-----------------------------------------------------------------------
D.local/bin/getpkginfo | 42------------------------------------------
D.local/bin/lemon2bstatus.sh | 50--------------------------------------------------
D.local/bin/play-radio | 62--------------------------------------------------------------
D.local/bin/stagit-viewer.sh | 49-------------------------------------------------
D.local/bin/tg-noworg.sh | 118-------------------------------------------------------------------------------
D.local/bin/totp.sh | 20--------------------
D.local/bin/trt | 2--
D.local/bin/trt-fzf.sh | 227-------------------------------------------------------------------------------
D.local/bin/trt-json.sh | 316-------------------------------------------------------------------------------
D.local/bin/voidlinux-installer-base.sh | 134-------------------------------------------------------------------------------
D.local/bin/voidlinux-mirror-speedtest.sh | 81-------------------------------------------------------------------------------
D.local/bin/vpngate-dialog.sh | 103-------------------------------------------------------------------------------
D.local/bin/vpngate-fzf.sh | 63---------------------------------------------------------------
D.local/bin/vpngate-prompt.sh | 91-------------------------------------------------------------------------------
D.local/bin/webdav-curl-sync.sh | 68--------------------------------------------------------------------
D.local/bin/x | 24------------------------
21 files changed, 0 insertions(+), 1855 deletions(-)

diff --git a/.local/bin/archlinux-installer-base.sh b/.local/bin/archlinux-installer-base.sh @@ -1,96 +0,0 @@ -#!/bin/sh - -# a shell script to perform to a very basic installation of Arch Linux - -[ "$(id -u)" -ne 0 ] && { echo "This script must be run as root"; exit 1; } - -: "${progname:="${0##*/}"}" -usage() { - cat <<_EOF -Usage: $progname [glibc] -_EOF -} - -step1_partition() { - umount /dev/sda* - umount -R /mnt - wipefs -a /dev/sda - dd if=/dev/zero of=/dev/sda bs=8M count=80 status=progress - ( - echo o # create a new empty DOS partition table - echo n # partition 1, primary, 200M - echo p - echo 1 - echo - echo +200M - echo n # partition 2, primary - echo p - echo 2 - echo - echo - echo a # bootable: partition 1 - echo 1 - echo w - ) | fdisk /dev/sda - sync - mkfs.vfat -F32 /dev/sda1 - mkfs.xfs -f /dev/sda2 - sync -} - -step2_bootstrap() { - mount /dev/sda2 /mnt - mkdir /mnt/boot - mount /dev/sda1 /mnt/boot - echo "Server = https://mirrors.kernel.org/archlinux/\$repo/os/\$arch" >/etc/pacman.d/mirrorlist - pacstrap /mnt base linux linux-firmware xfsprogs syslinux - genfstab -U /mnt >>/mnt/etc/fstab -} - -step3_chroot() { - cat >/mnt/home/chroot_script.sh <<- _CHROOT_SCRIPT_EOF -# configuration -ln -sf /usr/share/zoneinfo/UTC /etc/localtime -hwclock --systohc -locale-gen -echo "LANG=en_US.UTF-8" >/etc/locale.conf -echo "KEYMAP=dvorak-programmer" >/etc/vconsole.conf -echo "arch-basic" >/etc/hostname -cat <<_END_OF_HOSTS >>/etc/hosts -127.0.0.1 localhost -::1 localhost -_END_OF_HOSTS - -# tty1 autologin -mkdir /etc/systemd/system/getty\@tty1.service.d -cat <<_END_OF_GETTY_TTY1_CONF >/etc/systemd/system/getty\@tty1.service.d/override.conf -[Service] -ExecStart= -ExecStart=-/usr/bin/agetty --autologin root --noclear %I \\\$TERM -_END_OF_GETTY_TTY1_CONF -echo 'cat /proc/uptime >/tmp/uptime' >>/root/.bash_profile - -# syslinux -mkinitcpio -P -echo 'root:password' | chpasswd -syslinux-install_update -i -m -sed -i 's#APPEND root=/dev/sda3 rw\$#APPEND root=/dev/sda2 rw#' /boot/syslinux/syslinux.cfg -_CHROOT_SCRIPT_EOF - arch-chroot /mnt /bin/sh /home/chroot_script.sh - rm /mnt/home/chroot_script.sh -} - -read -p "Press Enter to continue... " reply -[ "$reply" != "" ] && { echo "Stopped."; exit 0; } - -timedatectl set-ntp true -step1_partition -step2_bootstrap -step3_chroot -umount -R /mnt - -# get uptime/memory_usage/systemd_analyze -#BT=$(cut -d' ' -f1 /tmp/uptime) -#MEM=$(free -h | grep '^Mem:' | awk '{print $3}') -#SA=$(systemd-analyze | cut -d' ' -f4,7,10 | paste -d' ' -s) -#echo -e "$BT\n$MEM\n$SA" >$(date -u +%s).txt diff --git a/.local/bin/dwm-helper.sh b/.local/bin/dwm-helper.sh @@ -1,19 +0,0 @@ -#!/bin/sh - -: "${progname:="${0##*/}"}" - -screenshot() { - sleep 0.2 && scrot -s -e 'xclip -selection clipboard -t "image/png" < $f' "$HOME/Pictures/Screenshot/%Y-%m-%d-\$p_\$wx\$h_scrot.png" -} - -usage() { - echo "Usage: $progname screenshot" -} - -case "$1" in - screenshot) screenshot ;; - * ) usage ;; -esac - -exit 0 - diff --git a/.local/bin/dwm_update_status.sh b/.local/bin/dwm_update_status.sh @@ -1,183 +0,0 @@ -#!/bin/bash - -### Constants -PROC_UPTIME='/proc/uptime' -PROC_STAT='/proc/stat' -PROC_MEMINFO='/proc/meminfo' -#SYS_BAT_CAPACITY='/sys/class/power_supply/sbs-20-000b/capacity' -#SYS_BAT_STATUS='/sys/class/power_supply/sbs-20-000b/status' -#SYS_BAT_2EMPTY='/sys/class/power_supply/sbs-20-000b/time_to_empty_avg' -#SYS_BAT_2FULL='/sys/class/power_supply/sbs-20-000b/time_to_full_avg' -SYS_BRIGHTNESS='/sys/class/backlight/backlight/brightness' -SYS_MAX_BRIGHTNESS='/sys/class/backlight/backlight/max_brightness' -SYS_TEMPERATURE='/sys/class/thermal/thermal_zone3/temp' -PROC_WIRELESS='/proc/net/wireless' -#PROC_DPMS='/sys/devices/platform/display-subsystem/drm/card0/card0-eDP-1/dpms' -PROC_DPMS='/sys/devices/pci0000:00/0000:00:02.0/drm/card0/card0-HDMI-A-1/dpms' -PREV_TOTAL=0 -PREV_IDLE=0 - -### Functions -function sec2time () { - local T=$1 - local D=$((T/60/60/24)) - local H=$((T/60/60%24)) - local M=$((T/60%60)) - local S=$((T%60)) - #[[ $D > 0 ]] && printf '%d days ' $D - #[[ $H > 0 ]] && printf '%d hours ' $H - #[[ $M > 0 ]] && printf '%d minutes ' $M - #![[ $D > 0 || $H > 0 || $M > 0 ]] && printf 'and ' - #printf '%d second\n' $S - - [[ $D > 0 ]] && printf '%d days ' $D - [[ $H > 0 ]] && printf '%02d:' $H - [[ $M > 0 ]] && printf '%02d:' $M - #[[ $D > 0 || $H > 0 || $M > 0 ]] && printf 'and ' - #printf '%d second\n' $S - printf '%02d\n' $S -} -function get-date () { - printf " $(date +'%F  %T')" -} -function get-uptime () { - printf " [$(sec2time $(cat $PROC_UPTIME | cut -d'.' -f1))]" -} -#function get-kbd () { - #printf " $(setxkbmap -query | grep variant | colrm 1 12)" -#} -function get-cpu-average () { - printf " $(grep 'cpu ' $PROC_STAT | awk '{usage=(1000*($2+$4)/($2+$4+$5)+5)/10} END {print int(usage) "%%"}')" -} -function get-cpu-current () { - # Get the total CPU statistics, discarding the 'cpu ' prefix. - #CPU=(`sed -n 's/^cpu\s//p' /proc/stat`) - CPU=(`grep -oP '(?<=cpu ).*' $PROC_STAT`) - IDLE=${CPU[3]} # Just the idle CPU time. - # Calculate the total CPU time. - TOTAL=0 - for VALUE in "${CPU[@]}"; do - let "TOTAL=$TOTAL+$VALUE" - done - # Calculate the CPU usage since we last checked. - let "DIFF_IDLE=$IDLE-$PREV_IDLE" - let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL" - let "DIFF_USAGE=(100000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10" - #printf "%0.2f%%\\n" "${DIFF_USAGE}e-2" - # Remember the total and idle CPU times for the next check. - PREV_TOTAL="$TOTAL" - PREV_IDLE="$IDLE" - - printf "%0.2f%%" "${DIFF_USAGE}e-2" -} -function get-ram () { - while IFS=":" read -r a b; do - case "$a" in - "MemTotal") mem_used="$((mem_used+=${b/kB}))"; mem_total="${b/kB}" ;; - "Shmem") mem_used="$((mem_used+=${b/kB}))" ;; - "MemFree" | "Buffers" | "Cached" | "SReclaimable") - mem_used="$((mem_used-=${b/kB}))" - ;; - esac - done < $PROC_MEMINFO - mem_used="$((mem_used / 1024))" - mem_total="$((mem_total / 1024))" - memory="${mem_used}${mem_label:-MiB} / ${mem_total}${mem_label:-MiB}" - #printf " $(bc <<<"scale=1;$mem_used/$mem_total*100" | sed -e 's/^\./0./')%%" - let "mem_usage=(100000*$mem_used/$mem_total+5)/10" - printf " %0.2f%%" "${mem_usage}e-2" -} -function get-storage () { - printf " $(df / | grep -v '^Filesystem' | awk '{ print $5 }')%" -} -function get-battery () { - BAT_PERCENT="$(<$SYS_BAT_CAPACITY)%%" - - if [[ $(<$SYS_BAT_STATUS) == Discharging ]]; then - printf " $BAT_PERCENT [$(sec2time $(<$SYS_BAT_2EMPTY))]" - elif [[ $(<$SYS_BAT_STATUS) == Charging ]]; then - printf " $BAT_PERCENT $(sec2time $(<$SYS_BAT_2FULL))" - elif [[ $(<$SYS_BAT_STATUS) == Full ]]; then - printf "$BAT_PERCENT Full" - else - printf '[?]' - fi -} -function get-brightness () { - printf " $(( $(<$SYS_BRIGHTNESS)*100/$(<$SYS_MAX_BRIGHTNESS) ))%%" -} -function get-temperature () { - #printf "  $(sensors | grep temp1 | awk '{print $2}' | sed 's/+//')" - printf " %.1f°C" "$(<$SYS_TEMPERATURE)e-3" -} -function get-ip () { - printf " $(ip route get 1 2>&1 | awk '{print $7}')" -} -function get-wifi () { - if [[ $(grep wlan0 $PROC_WIRELESS) ]]; then - printf " $(grep wlan0 $PROC_WIRELESS | awk '{ print int($3 * 100 / 70) }')%%" - else - echo -n ' [?]' - fi -} -function update-status () { - #xsetroot -name " $info_date $info_uptime $info_kbd $info_cpu_average $info_cpu_current $info_ram $info_storage $info_battery $info_brightness $info_temperature $info_ip $info_wifi " - #xsetroot -name " $info_date $info_uptime $info_cpu_average $info_cpu_current $info_ram $info_storage $info_battery $info_brightness $info_temperature $info_ip $info_wifi " - #echo " $info_date $info_uptime $info_cpu_average $info_cpu_current $info_ram $info_storage $info_battery $info_brightness $info_temperature $info_ip $info_wifi " - xsetroot -name " $info_date $info_uptime $info_cpu_average $info_cpu_current $info_ram $info_storage $info_ip" - -} - -### start from here -info_date=$(get-date) -info_uptime=$(get-uptime) -#info_kbd=$(get-kbd) -info_cpu_average=$(get-cpu-average) -info_cpu_current=$(get-cpu-current) -info_ram=$(get-ram) -info_storage=$(get-storage) -#info_battery=$(get-battery) -#info_brightness=$(get-brightness) -#info_temperature=$(get-temperature) -info_ip=$(get-ip) -info_wifi=$(get-wifi) -update-status -sec=0 -while true; do - if [[ $(<$PROC_DPMS) == On ]] - then - # run commands when it's on - #echo On $(get-uptime) && sleep 1 - if [ "$(($sec % 4))" == "0" ]; then - #echo "$(date +%M:%S) 2" - info_date=$(get-date) - info_uptime=$(get-uptime) - info_cpu_current=$(get-cpu-current) - info_ram=$(get-ram) - info_storage=$(get-storage) - #info_battery=$(get-battery) - #info_brightness=$(get-brightness) - #info_temperature=$(get-temperature) - #info_wifi=$(get-wifi) - update-status - fi - - if [ "$(($sec % 40))" == "0" ]; then - info_cpu_average=$(get-cpu-average) - info_ip=$(get-ip) - update-status - - fi - - #if [ "$(($sec % 32))" == "0" ]; then - #info_kbd=$(get-kbd) - #update-status - #fi - - sleep 2; - sec=$(( $sec + 2 )) - else - echo Off - sleep 4 - fi -done diff --git a/.local/bin/eztmp b/.local/bin/eztmp @@ -1,36 +0,0 @@ -#!/bin/sh - -# https://stackoverflow.com/a/38021063 -urlencodepipe() { - local LANG=C; local c; while IFS= read -r c; do - case $c in [a-zA-Z0-9.~_-]) printf "$c"; continue ;; esac - printf "$c" | od -An -tx1 | tr ' ' % | tr -d '\n' - done <<EOF -$(fold -w1) -EOF - echo -} -urlencode() { printf "$*" | urlencodepipe ;} - -RAND=$(cat /dev/urandom | tr -dc 'a-z0-9' | head --bytes 8) -#URL="https://$USER:$PASSWORD@$DOMAIN:$PORT/path" - -# upload image from clipboard -[ "$1" = "-c" ] \ - && { xclip -selection clipboard -t image/png -o \ - | curl -o /dev/null --progress-bar -T - "$URL/$RAND.png" \ - && TMPURL="https://ezup.dev/tmp/$RAND.png" \ - && notify-send.sh --icon=terminal "Clipboard Image Uploaded\n$TMPURL"; \ - echo "$TMPURL" | xclip -selection clipboard; \ - exit 0; } - -# upload from file or stdin -[ ! -z "$1" ] && [ -f "$1" ] \ - && FILE="$1" NAME=${RAND}_$(basename "$1") \ - || { [ ! -t 0 ] && FILE="-" NAME="${RAND}.txt"; } -#&& FILE="$1" NAME=$(urlencode ${RAND}_$(basename "$1")) \ -[ ! -z "$FILE" ] \ - && { curl -o /dev/null --progress-bar -T "$FILE" "$URL/$NAME" \ - && TMPURL="https://ezup.dev/tmp/$(urlencode $NAME)"; echo $TMPURL; \ - echo "$TMPURL" | xclip -selection clipboard; } \ - || exit 1 diff --git a/.local/bin/fv b/.local/bin/fv @@ -1,71 +0,0 @@ -#!/bin/env sh -# -# fuzzy finder based File Viewer -# -: "${progname:="${0##*/}"}" -: "${WRKDIR:=./}" - -which sk bat fd >/dev/null || exit 1 - -fuzzy_git() { - local HEADER="[ENTER] Print [TAB] Toggle [ALT-F] View [ALT-H] Log [ALT-L] Log 1L" - local REPO=$(git -C "$WRKDIR" rev-parse --show-toplevel 2>/dev/null) #|| { echo "${WRKDIR} is not a git repo"; exit 1; } - git -C "$REPO" ls-tree --full-tree -r --name-only HEAD \ - | GREP_COLORS="sl=0;34;49:ms=0;37;49" grep --color=always '^\|[^/]*$' \ - | sk --ansi \ - --header="${HEADER} | $REPO" \ - --prompt "[git] > " \ - --layout=reverse-list \ - --preview="git -C \"${WRKDIR}\" show master:{1} | bat --color=always -p" \ - --preview-window=up:40% \ - -m \ - --bind "alt-f:execute[ git -C \"${REPO}\" show master:{} | bat -p --color=always --paging=always ]" \ - --bind "alt-l:execute[ git -C \"${REPO}\" log --oneline -- {} ]" \ - --bind "alt-h:execute[ git -C \"${REPO}\" log -p -- {} ]" \ - ${1:+--query "$@"} -} - -fuzzy_find() { - [ -d "$WRKDIR" ] || exit 0 - fd --type file --color=always . "$WRKDIR" \ - | sk \ - --ansi \ - --layout=reverse-list \ - --preview="bat --color=always --paging=always {}" \ - --preview-window=up \ - --prompt "$WRKDIR > " \ - --bind "alt-f:execute[ bat --color=always --paging=always {} ]" \ - ${1:+--query "$@"} -} - -usage() { - cat <<_EOF -Usage: $progname [options] - -Options: - -d <repo-dir> Set git repository to this directory - -f Force to use find instead of git - -h Show this page -_EOF - exit 0 -} - -while getopts "d:fh" opt; do - case $opt in - d) WRKDIR="$OPTARG";; - f) readonly FORCE_DIR=1;; - h) usage;; - *) usage;; - esac -done -shift $((OPTIND - 1)) - - -[ -d "$WRKDIR" ] || { echo "$WRKDIR: no such directory"; return 0; } -if [ "$FORCE_DIR" = 1 ]; then - fuzzy_find -elif git -C "$WRKDIR" rev-parse 2>/dev/null; then - fuzzy_git "$@" -else - fuzzy_find -fi diff --git a/.local/bin/getpkginfo b/.local/bin/getpkginfo @@ -1,42 +0,0 @@ -#!/bin/sh - -which xbps-query xmllint >/dev/null || exit 1 -: "${progname:="${0##*/}"}" - -get_pkgsize() { - xmllint --xpath "/plist/dict/key[text()='$1']/following-sibling::dict[1]/key[text()='installed_size']/following-sibling::integer[1]/text()" /var/db/xbps/pkgdb-0.38.plist 2>/dev/null -} - -get_depsize() { - #for pkg in $(xbps-query -Rx $1 | sed 's/\(>\|<\|=\).*$//'); do - for pkg in $(xbps-query --fulldeptree -Rx $1 | xargs -L1 xbps-uhelper getpkgname); do - get_pkgsize $pkg - done | paste -d+ -s | bc | numfmt --to=iec-i -} - -usage() { - cat <<_EOF -Usage: $progname [pkg] show package info -_EOF - exit 1 -} - -show_pkginfo() { - local pkgver=$(xbps-query -p pkgver -R $1) - local pkgsize=$(xbps-query -p installed_size -R $1) - local depsize=$(get_depsize $1) - local numfile=$(xbps-query -Rf $1 | wc -l) - local numdep=$(xbps-query --fulldeptree -Rx $1 | wc -l) - cat <<_EOF -pkg: $pkgver -size: $pkgsize -depsize: $depsize -numfile: $numfile -numdep: $numdep -_EOF -} - -[ -z "$1" ] && usage -xbps-query -R $1 >/dev/null || { echo "invalid package"; exit 1; } - -show_pkginfo $1 | sed "s/^/$(tput bold)/; s/:/$(tput sgr0):/" | column -t diff --git a/.local/bin/lemon2bstatus.sh b/.local/bin/lemon2bstatus.sh @@ -1,50 +0,0 @@ -#!/bin/sh - -# xlsfonts | grep terminus-bold | grep iso10646 -FONT="-xos4-terminus-bold-r-normal--16-160-72-72-c-80-iso10646-1" - -get_time() { date -u +%FT%TZ ; } - -get_workspace() { - # current workspace - CURRENT_WS=$(xprop -root _NET_CURRENT_DESKTOP | sed -e 's/.* = //') - # window name - CURRENT_WINDOW_ID=$(xprop -root _NET_ACTIVE_WINDOW | sed 's/.* window id # //') - [ "$CURRENT_WINDOW_ID" != "0x0" ] && CURRENT_WINDOW_NAME=$(xprop -id "$CURRENT_WINDOW_ID)" WM_NAME | sed 's/.* = "\(.*\)"/\1/') - # all workspaces - CLIENT_LIST=$(xprop -root _NET_CLIENT_LIST | sed 's/.*: window id # //; s/, / /g') - WS=$(for id in $CLIENT_LIST; do - xprop -id "$id" _NET_WM_DESKTOP | sed 's/.* = //;' - done | sort -hu | sed "s/^/ /; s/$/ /; s/ $CURRENT_WS /%{F#3498db}[$CURRENT_WS]%{F-}%{B-}/" | tr -d '\n') - echo "$WS" | grep $CURRENT_WS >/dev/null 2>&1 - [ "$?" -ne 0 ] && WS="$WS($CURRENT_WS)" - echo "$WS - %{F#ecf0f1}$CURRENT_WINDOW_NAME%{B-}" - -} - -get_kbd() { xprop -root _XKB_RULES_NAMES | awk -F\" '{print $6, "("$8")" }' ; } - -get_tray() { - CLIENT_LIST=$(xprop -root _NET_CLIENT_LIST | sed 's/.*: window id # //; s/, / /g') - for id in $CLIENT_LIST; do - xprop -id "$id" _NET_WM_STATE | grep '^_NET_WM_STATE(_NET_WM_STATE) = 0x3,' >/dev/null - if [ "$?" -eq 0 ]; then - local CLASS=$([ "$?" -eq 0 ] && xprop -id "$id" WM_CLASS | cut -d\" -f4) - if [ -z "$CLASS" ]; then local NAME=$id; else local NAME=$CLASS; fi - echo "%{A:xdotool windowactivate $id windowraise $id:}($NAME)%{A}" - fi - done | paste -s -d' ' -} - -#hidden -c xargs 9menu -popup -label Iconics -font "$FONT" #-geometry '0x0+1440+1020' -# 1440x22+0+0 -# 1430x24+5+5 -# 1080x27+1440+0 -showbar() { - while true; do - echo " $(get_workspace) %{r}$(get_tray) %{F#b2babb}%{B#212f3d} $(get_kbd) $(get_time) %{F-}%{B-}" - sleep 0.2 - done | lemonbar -p -f "$FONT" -g '1430x24+5+5' -n 'leftbar' -B '#1c2833' -F '#eeeeee' | sh -} - -showbar diff --git a/.local/bin/play-radio b/.local/bin/play-radio @@ -1,62 +0,0 @@ -#!/bin/sh - -: "${progname:="${0##*/}"}" - -play_alt987() { - # https://alt987fm.iheart.com/ - local STREAM_HLS='https://stream.revma.ihrhls.com/zc201/hls.m3u8' - #local STREAM_SHOUTCAST='https://stream.revma.ihrhls.com/zc201' - local COVER_ART='http://i.iheart.com/v3/re/assets/images/08e927dc-5949-41d6-972b-b5581a0850f3.png' - proxychains4 mpv \ - --volume=60 \ - --vid=1 \ - --external-file="$COVER_ART" \ - "$STREAM_HLS" -} - -play_ezup() { - # ezup.dev - proxychains4 mpv \ - --volume=60 \ - --window-scale=0.5 \ - 'http://45.32.163.153:10100' -} - -play_synthwave() { - proxychains4 mpv \ - --vid=1 \ - --volume=60 \ - --image-display-duration=inf \ - 'https://nightride.fm/stream/nightride.m4a' -} - -usage() { - cat <<_EOF -Usage: $progname alt|ezup|synthwave play radio - $progname -k stop playing - -_EOF - exit 1 -} - -stop_playing() { - local ALL_PID=$(pidof -x $progname) - local SELF_PID=$(cut -d' ' -f4 /proc/self/stat) - local OTHER_PID=$(echo "$ALL_PID" | sed "s/$SELF_PID//") - echo "Killing: $OTHER_PID" - pkill -P $OTHER_PID - exit 0 -} - -[ "$1" = "-k" ] && stop_playing - -pidof mpv >/dev/null 2>&1 && { printf "Found running process of mpv!\n\n"; usage; } -test "$(pidof -x $progname)" != "$(cut -d' ' -f4 /proc/self/stat)" && { printf "Found running process of ${progname}!\n\n"; usage; } - -[ -z $1 ] && usage -case "$1" in - alt ) play_alt987 ;; - ezup ) play_ezup ;; - synthwave ) play_synthwave ;; - * ) usage ;; -esac diff --git a/.local/bin/stagit-viewer.sh b/.local/bin/stagit-viewer.sh @@ -1,49 +0,0 @@ -#!/bin/sh - -which fzf bat curl >/dev/null || exit 0 - -view_raw_file() { - echo "Fetching $(basename ${1})..." - local HTML_RAW=$(curl --progress-bar "$1") - echo "$HTML_RAW" \ - | sed -n 's|^<a href="#.*" class="line" id=".*">.*</a>||p' \ - | recode HTML_4.0..UTF-8 \ - | bat -n --paging=always -} - -view_file() { - local HTML_FILE=$(curl --progress-bar "$1") - local LIST_FILE=$(echo "$HTML_FILE" | sed -n 's|^<tr><td>.*</td><td><a href=".*">\(.*\)</a></td><td class="num" align="right">.*</td></tr>$|\1|p') - local HOMEPAGE=$(echo "$1" | sed 's/files.html$//') - while true; do - local FILE_PATH=$(echo "$LIST_FILE" | GREP_COLORS="sl=0;34;49:ms=0;37;49" grep --color=always '^\|[^/]*$' | fzf --ansi +s) - [ -z "$FILE_PATH" ] && return 0 - view_raw_file ${HOMEPAGE}file/${FILE_PATH}.html - done -} - -view_raw_commit() { - echo "Fetching $(basename ${1})..." - local TEXT=$(links -dump "$1" | sed 's/^ //' | sed -n '/^commit .*$/,$p') - echo "$TEXT" | bat -nl diff --paging=always -} - -view_log() { - local HOMEPAGE=$(echo "$1" | sed 's/log.html$//') - local HTML_FILE=$(curl --progress-bar "$1") - local LIST_LOG=$(echo "$HTML_FILE" | sed -n 's|^<tr><td>\(.*\)</td><td><a href="commit/\(.*\).html">\(.*\)</a></td><td>.*.*</td><td class="num" align="right">.*|\2 \1 \3|p') - while true; do - local COMMIT=$(echo "$LIST_LOG" | fzf +s | awk '{print $1}') - [ -z "$COMMIT" ] && return 0 - view_raw_commit "${HOMEPAGE}commit/${COMMIT}.html" - done -} - -[ -z "$1" ] && { printf "URL: "; read -r URL; } || URL=$1 - -if $(echo "$URL" | grep '^http.*/log.html$' >/dev/null); then view_log "$URL" -elif $(echo "$URL" | grep '^http.*/files.html$' >/dev/null); then view_file "$URL" -elif $(echo "$URL" | grep 'http.*/commit/.*.html$' >/dev/null); then view_raw_commit "$URL" -elif $(echo "$URL" | grep 'http.*/file/.*.html$' >/dev/null); then view_raw_file "$URL" -else echo "Invald URL"; return 0 -fi diff --git a/.local/bin/tg-noworg.sh b/.local/bin/tg-noworg.sh @@ -1,118 +0,0 @@ -#!/bin/sh - -## $ crontab -l -## * * * * * ~/.local/bin/tg-noworg.sh -u -## 0 * * * * ~/.local/bin/tg-noworg.sh -d - -: "${progname:="${0##*/}"}" - -#CHAT_ID="" # private (message.from.id) -CHAT_ID="" # channel (channel_post.chat.id) -TG_BOT_TOKEN="" -tgbotapi="curl -s -F chat_id=$CHAT_ID https://api.telegram.org/bot${TG_BOT_TOKEN}" - -NOWORG="$HOME/orgmode/now.org" -BASENAME=$(basename $NOWORG) -TEMP="/tmp/tg-noworg" -LAST_CHECKED="${TEMP}/last_checked.txt" -LOG="$HOME/tg-noworg/log.json" - -if [ ! -d "$TEMP" ]; then - mkdir $TEMP && cp $NOWORG $TEMP - date -u +%s >$LAST_CHECKED - echo "make directory: ${TEMP}" - exit 0 -fi - -send_message() { - ${tgbotapi}/sendMessage -F parse_mode="MarkdownV2" --form-string text="$1" | sed -e 's/\(,"text":"\).*/\1"}}\n/' >>$LOG -} - -modify_diff() { - sed -e ' - # remove first two lines, empty address lines - 1,2d - s/^@@ .*$// - - # remove lines which contains orgmode timestamps - /\(SCHEDULED:\|CLOSED:\|:PROPERTIES:\|:LAST_REPEAT:\|:END:\|- State "DONE" from "TODO"\)/d - - # escape for MarkdownV2 - s/\\/\\\\/g - s/\(_\|*\|\[\|\]\|(\|)\|~\|`\|>\|#\|+\|-\|=\||\|{\|}\|\.\|!\)/\\\1/g - - # headlines - /^\(\\\-\|\\+\)\(\\\*\\\* \)/ {s/^\(\\\-\|\\+\)\(\\\*\\\* \)/\1*/; s/$/*/} - /^\(\\-\|\\+\)\\\*\\\*\\\* / {s/^\(\\-\|\\+\)\(\\\*\\\*\\\*\) \(\|TODO\|DONE\)\(\| \)/\1*\\#\3* __*_/; s/$/_*__/} - - # plain lists - /^\(\\\-\|\\+\)\(\|\s\+\)\(\\\-\|\\+\|[0-9]\\\.\|[0-9]\\)\) / {s/^\(\\\-\|\\+\)\(\|\s\+\)\(\\\-\|\\+\|[0-9]\\\.\|[0-9]\\)\)\(\| \)\(\|\\\[ \\\]\|\\\[X\\\]\|\\\[\\\-\\\]\)\(\| \)/\1`\2\3\4\5\6`_/; s/$/_/} - s/\(\\\-\|\\+\)\(\s\+ \)/\1`\2`/ - - # strikethrough for removed lines, remove ^+ for added lines - s/^\\\-/~/; /^~/s/$/~/ - s/^\\+// - ' -} - -update_modified() { - lastcheck=$(cat $LAST_CHECKED) - echo "lastcheck: $(date -u +%FT%TZ -d @${lastcheck})" - lastmod=$(stat -c %Y $NOWORG) - if [ "$lastmod" -gt "$lastcheck" ]; then - TEXT=$(diff -u0 ${TEMP}/$BASENAME $NOWORG | modify_diff) - send_message "$TEXT" - cp $NOWORG ${TEMP}/$BASENAME - date -u +%s >$LAST_CHECKED - echo "update: $BASENAME" - else - echo "skip: $BASENAME" - fi -} - -purge_message() { - sed -i '/^$/d' $LOG - TIME_48H_AGO=$(date -u -d-48hours-5minute +%s) - TIME_40H_AGO=$(date -u -d-40hours +%s) - i=1 - while IFS= read -r json; do - echo "########## Line $i" - json=$(echo "$json" | sed 's/\(,"description":"\).*/\1"}/') - OK=$(echo "$json" | jq .ok) - if [ $OK = true ]; then - MESSAGE_ID=$(echo "$json" | jq .result.message_id) - CHAT_ID=$(echo "$json" | jq .result.chat.id) - JSON_DATE=$(echo "$json" | jq .result.date) - FORMATTED_DATE=$(date -u +%FT%TZ -d@${JSON_DATE}) - DURATION=$(ddiff -i'%s' -f'%H hours %M minutes ago' $JSON_DATE $(date +%s)) - [ $JSON_DATE -lt $TIME_48H_AGO ] && echo "$FORMATTED_DATE ($DURATION) -- CANT BE DELETED" - [ $JSON_DATE -gt $TIME_40H_AGO ] && echo "$FORMATTED_DATE ($DURATION) -- RESERVED" - if [ $JSON_DATE -ge $TIME_48H_AGO ] && [ $JSON_DATE -le $TIME_40H_AGO ]; then - echo "$FORMATTED_DATE ($DURATION) -- WILL BE DELETED" - $tgbotapi/deleteMessage -F message_id=$MESSAGE_ID | sed 's/$/\n/' - sed -i "${i}s/^.*$//" $LOG - sleep 1 - fi - else - ERROR_CODE=$(echo "$json" | jq .error_code) - echo "Contains ERROR CODE: $ERROR_CODE" - fi - i=$(( i + 1 )) - echo - done <$LOG -} - -usage() { - cat <<_EOF -Usage: $progname -u Update modified content to Telegram channel - $progname -d Purge messages which sent between 40 and 48 hours ago -_EOF - exit 1 -} - -case "$1" in - -u) update_modified ;; - -d) purge_message ;; - *) usage ;; -esac -exit 0 diff --git a/.local/bin/totp.sh b/.local/bin/totp.sh @@ -1,20 +0,0 @@ -#!/bin/sh -CONFIGURATION="$HOME/Desktop/totp_key.txt" -if [ -z $1 ]; then - echo "Usage:" - echo " otp google" - echo - echo "Configuration: $CONFIGURATION" - echo "Format: name=key" - echo "Services:" - sed 's/=.*//; s/^/ /' $CONFIGURATION - echo - exit -fi -OTPKEY="$(sed -n "s/${1}=//p" $CONFIGURATION)" -if [ -z "$OTPKEY" ]; then - echo "$(basename $0): Bad Service Name '$1'" - $0 - exit -fi -oathtool --totp -b "$OTPKEY" diff --git a/.local/bin/trt b/.local/bin/trt @@ -1 +0,0 @@ -trt-fzf.sh- \ No newline at end of file diff --git a/.local/bin/trt-fzf.sh b/.local/bin/trt-fzf.sh @@ -1,227 +0,0 @@ -#!/bin/bash - -: "${progname:="${0##*/}"}" -TROJAN_SUBURL="" -CSV="/home/user/.local/share/data/trojan/trojan.csv" # use absolute path - -urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } - -country_zh2code() { - sed -e ' - s/,俄羅斯 /,RU / - s/,印度 /,IN / - s/,土耳其 /,TR / - s/,巴西 /,BR / - s/,德國 /,DE / - s/,新加坡 /,SG / - s/,日本 /,JP / - s/,法國 /,FR / - s/,澳大利亞 /,AU / - s/,美國 /,US / - s/,臺灣 /,TW / - s/,英國 /,GB / - s/,菲律賓 /,PH / - s/,韓國 /,KR / - s/,香港 /,HK / - #s/,阿聯酋 /,AE / - ' -} - -country_code2name() { - sed -e ' - s/AU/Australia/ - s/BR/Brazil/ - s/DE/Germany/ - s/FR/Frace/ - s/GB/United Kingdom/ - s/HK/Hong Kong/ - s/IN/India/ - s/JP/Japan/ - s/KR/South Korea/ - s/PH/Philippines/ - s/RU/Russia/ - s/SG/Singapore/ - s/TR/Turkey/ - s/TW/Taiwan/ - s/US/United States/ - ' -} - -query_ipv4() { - all_servers=$1 - while true; do - servers=$(printf "$all_servers" | grep '[[:alpha:]]') - if [[ -z "$servers" ]]; then - all_servers=$(echo "$all_servers" | sort | uniq | paste -s -d' ') - break - fi - servers_ip=$(dig +short -t A $servers) - all_servers=$(echo "$all_servers" | sed "/[[:alpha:]]/d") - all_servers+=$(echo -e "\n$servers_ip") - done - echo $all_servers -} - -query_ipv6() { - all_servers=$1 - while true; do - servers=$(printf "$all_servers" | grep -v ':' | grep '[[:alpha:]]') - if [[ -z "$servers" ]]; then - all_servers=$(echo "$all_servers" | sort | uniq | paste -s -d' ') - break - fi - servers_ip=$(dig +short -t AAAA $servers) - all_servers=$(echo "$all_servers" | sed "/\./d") - all_servers+=$(echo -e "\n$servers_ip") - done - echo $all_servers -} - -url2csv() { - read -p "Type $(tput bold)Yes$(tput sgr0) to continue... " && [ $REPLY == "Yes" ] || { echo "$(tput bold; tput setaf 1)Canceled$(tput sgr0)"; exit 1; } - : >$CSV - # 1 2 3 4 5 6 7 8 9 10 - #echo "password,remote_addr,remote_port,country_code,country_name,provider,number,time_appconnect,speed_download,ipv4" >>$CSV - BASE64_URLS=$(curl --progress-bar $TROJAN_SUBURL) - total=$(echo "$BASE64_URLS" | base64 -d | wc -l) - local i=0 - while IFS=, read -r password remote_addr remote_port mark; do - local i=$(($i + 1)) - mark=${mark//,} - #mark=${mark/ /,} - #country=${mark%% *}; mark=${mark#*$country}; mark=${mark/ /} - #provider=${mark%% *}; mark=${mark#*$provider}; number=${mark/ /} - IFS=" " read -r country_code provider number <<<$(echo "$mark") - country_name=$(echo "$country_code" | country_code2name) - CONFIG=$HOME/.local/service/trojan-client/client.json switch_proxy - local ipv4=$(query_ipv4 $remote_addr) - sv restart $HOME/.local/service/trojan-client >/dev/null - sleep 0.8 - time_appconnect=$(curl --connect-timeout 2 -x socks5h://127.0.0.1:51837 -o/dev/null -sw '%{time_appconnect}' 'https://connectivitycheck.gstatic.com/generate_204') - time_appconnect=$(printf "%.0f ms" "$(bc<<<${time_appconnect}*1000)") - speed_download=$(curl -x socks5h://127.0.0.1:51837 http://speedtest-sgp1.digitalocean.com/10mb.test --progress-bar -o/dev/null --write-out '%{speed_download}' | numfmt --to=iec-i --suffix=B/s) - echo "$i/$total | $country_code $provider $number | $time_appconnect $speed_download | $ipv4" - echo "$password,$remote_addr,$remote_port,$country_code,$country_name,$provider,$number,$time_appconnect,$speed_download,$ipv4" >>$CSV - sleep 2 - done < <(urldecode "$(echo "$BASE64_URLS" | base64 -d | sed 's#^trojan://##' | sed 's/?allowInsecure=1&tfo=1//' | sed 's/@/,/; s/:/,/; s/#/,/')" | country_zh2code) -} - -switch_proxy() { - #jo run_type=client local_addr=0.0.0.0 local_port=51837 remote_addr=$remote_addr remote_port=$remote_port password=$(jo -a $password) log_level=0 ssl=$(jo verify=false verify_hostname=true cert= cipher="ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA" sni= alpn=$(jo -a h2 "http/1.1") reuse_session=true session_ticket=false curse=) tcp=$(jo no_delay=true keep_alive=true reuse_port=false fast_open=false fast_open_qlen=20) >$CONFIG - #jo run_type=nat local_addr=127.0.0.1 local_port=16280 remote_addr=$remote_addr remote_port=$remote_port password=$(jo -a $password) log_level=0 ssl=$(jo verify=false verify_hostname=true cert= cipher="ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA" sni= alpn=$(jo -a h2 "http/1.1") reuse_session=true session_ticket=false curse=) tcp=$(jo no_delay=true keep_alive=true reuse_port=false fast_open=false fast_open_qlen=20) >$CONFIG - jj -v "$remote_addr" -p -i $CONFIG -o $CONFIG 'remote_addr' - jj -v "$remote_port" -p -i $CONFIG -o $CONFIG 'remote_port' - jj -v "$password" -p -i $CONFIG -o $CONFIG 'password.0' -} - -select_srv() { - while true; do - local SORTED_CSV=$(cat $CSV | awk 'BEGIN{FS=OFS=","}{print $9,$0}' | sort -hr) - local NUM=$(while IFS=, read -r speed password remote_addr remote_port country_code country_name provider number time_appconnect speed_download ipv4; do - echo "$speed_download,$time_appconnect,$country_code,$provider,$number,$remote_addr,$remote_port,$country_name" - done < <(echo "$SORTED_CSV") | sed '1iSpeed,Time,Country code,Provider,Number,Address,Port,Country name' | awk 'BEGIN{FS=OFS=","}{print i++","$0}' | column -s, -t | fzf | cut -d' ' -f1) - [ -z "$NUM" ] && exit 0 - if [ "$NUM" -ne 0 ]; then - IFS=, read speed password remote_addr remote_port country_code country_name provider number time_appconnect speed_download ipv4 <<<$(echo "$SORTED_CSV" | sed "${NUM}q;d") - break - fi - done -} - -reset_iptables_rules() { - #[ "$EUID" -ne 0 ] && { echo "Please run as root" && exit 1; } - ## https://gist.github.com/jarek-przygodzki/29830f868e0c29e1dccb09beafbc4f72 - iptables -P INPUT ACCEPT - iptables -P FORWARD ACCEPT - iptables -P OUTPUT ACCEPT - iptables -F INPUT - iptables -F OUTPUT - iptables -F FORWARD - iptables -F - iptables -t nat -F - iptables -t mangle -F - iptables -X - iptables -t nat -X - iptables -t mangle -X - echo "Resetted iptables rules" -} -add_iptables_rules() { - reset_iptables_rules - ## https://github.com/shadowsocks/shadowsocks-libev#transparent-proxy - iptables -t nat -N TROJAN - for ip in $ipv4; do - iptables -t nat -A TROJAN -d $ip -j RETURN - done - iptables -t nat -A TROJAN -d 0.0.0.0/8 -j RETURN - iptables -t nat -A TROJAN -d 10.0.0.0/8 -j RETURN - iptables -t nat -A TROJAN -d 127.0.0.0/8 -j RETURN - iptables -t nat -A TROJAN -d 169.254.0.0/16 -j RETURN - iptables -t nat -A TROJAN -d 172.16.0.0/12 -j RETURN - iptables -t nat -A TROJAN -d 192.168.0.0/16 -j RETURN - iptables -t nat -A TROJAN -d 224.0.0.0/4 -j RETURN - iptables -t nat -A TROJAN -d 240.0.0.0/4 -j RETURN - iptables -t nat -A TROJAN -p tcp -j REDIRECT --to-ports 16280 - iptables -t nat -A OUTPUT -j TROJAN - echo "Added iptables rules" -} - -get_info() { - printf 'Clint: ' - grep "^$(jq -r '.password[0] + "," + .remote_addr + "," + (.remote_port|tostring)' ~/.local/service/trojan-client/client.json)," $CSV | cut -d',' -f4,6,7 --output-delimiter=' ' - printf 'Nat: ' - grep "^$(jq -r '.password[0] + "," + .remote_addr + "," + (.remote_port|tostring)' /etc/trojan/config.json)," $CSV | cut -d',' -f4,6,7 --output-delimiter=' ' -} - -usage() { - cat <<_EOF | GREP_COLORS='ms=1' egrep --color "$progname|$" -Usage: $progname -f get csv - $progname s select node - $progname c switch node for trojan client - $progname n switch node for trojan NAT - - $progname r reset iptables rules - $progname a add iptables rules - -_EOF - exit 1 -} - - -case $1 in - -f) url2csv;; - s) - select_srv - echo "$country_code $provider $number ($remote_addr)" - ;; - c) - CONFIG=$HOME/.local/service/trojan-client/client.json - select_srv - echo "Cient: $country_code $provider $number ($remote_addr)" - switch_proxy - sv restart $HOME/.local/service/trojan-client >/dev/null - ;; - n) - [ "$EUID" -ne 0 ] && { echo "Please run as root" && exit 1; } - CONFIG=/etc/trojan/config.json - select_srv - echo "NAT: $country_code $provider $number ($remote_addr)" - echo "IPv4: $ipv4" - switch_proxy - sv restart trojan - add_iptables_rules - ;; - r) - [ "$EUID" -ne 0 ] && { echo "Please run as root" && exit 1; } - reset_iptables_rules - ;; - a) - [ "$EUID" -ne 0 ] && { echo "Please run as root" && exit 1; } - ipv4=$(grep "^$(jq -r '.password[0] + "," + .remote_addr + "," + (.remote_port|tostring)' /etc/trojan/config.json)," $CSV | cut -d',' -f10 --output-delimiter=' ') - add_iptables_rules - ;; - i) - get_info - ;; - *) usage;; -esac -exit 0 diff --git a/.local/bin/trt-json.sh b/.local/bin/trt-json.sh @@ -1,316 +0,0 @@ -#!/bin/bash - -# trt (transparent proxy for Trojan) - -INFO=~/.local/share/data/trojan/srvinfo.json -CONFIG="/etc/trojan/config.json" -SUBURL="" -# the value of IPV4_SERVERS_LIST and IPV6_SERVERS_LIST should be generated by the script itself -IPV4_SERVERS_LIST="" -IPV6_SERVERS_LIST="" -: "${progname:="${0##*/}"}" - -## Part 1: iptables - -query_ipv4() { - all_servers=$1 - while true; do - servers=$(printf "$all_servers" | grep '[[:alpha:]]') - if [[ -z "$servers" ]]; then - all_servers=$(echo "$all_servers" | sort | uniq | paste -s -d' ') - break - fi - servers_ip=$(dig +short -t A $servers) - all_servers=$(echo "$all_servers" | sed "/[[:alpha:]]/d") - all_servers+=$(echo -e "\n$servers_ip") - done - echo $all_servers -} -query_ipv6() { - all_servers=$1 - while true; do - servers=$(printf "$all_servers" | grep -v ':' | grep '[[:alpha:]]') - if [[ -z "$servers" ]]; then - all_servers=$(echo "$all_servers" | sort | uniq | paste -s -d' ') - break - fi - servers_ip=$(dig +short -t AAAA $servers) - all_servers=$(echo "$all_servers" | sed "/\./d") - all_servers+=$(echo -e "\n$servers_ip") - done - echo $all_servers -} -clear_iptables_rules() { - [ "$EUID" -ne 0 ] && { echo "Please run as root" && exit 1; } - ## https://gist.github.com/jarek-przygodzki/29830f868e0c29e1dccb09beafbc4f72 - iptables -P INPUT ACCEPT - iptables -P FORWARD ACCEPT - iptables -P OUTPUT ACCEPT - iptables -F INPUT - iptables -F OUTPUT - iptables -F FORWARD - iptables -F - iptables -t nat -F - iptables -t mangle -F - iptables -X - iptables -t nat -X - iptables -t mangle -X - echo "Cleared iptables rules" -} -add_iptables_rules() { - clear_iptables_rules - ## https://github.com/shadowsocks/shadowsocks-libev#transparent-proxy - iptables -t nat -N TROJAN - for ip in $IPV4_SERVERS_LIST; do - iptables -t nat -A TROJAN -d $ip -j RETURN - done - iptables -t nat -A TROJAN -d 0.0.0.0/8 -j RETURN - iptables -t nat -A TROJAN -d 10.0.0.0/8 -j RETURN - iptables -t nat -A TROJAN -d 127.0.0.0/8 -j RETURN - iptables -t nat -A TROJAN -d 169.254.0.0/16 -j RETURN - iptables -t nat -A TROJAN -d 172.16.0.0/12 -j RETURN - iptables -t nat -A TROJAN -d 192.168.0.0/16 -j RETURN - iptables -t nat -A TROJAN -d 224.0.0.0/4 -j RETURN - iptables -t nat -A TROJAN -d 240.0.0.0/4 -j RETURN - iptables -t nat -A TROJAN -p tcp -j REDIRECT --to-ports 16280 - iptables -t nat -A OUTPUT -j TROJAN - echo "Added iptables rules" -} - -## Part 2: Update servers - -update_srv() { - read -p "Type $(tput bold)Yes$(tput sgr0) to continue... " && [ $REPLY == "Yes" ] || { echo "$(tput bold; tput setaf 1)Canceled$(tput sgr0)"; exit 1; } - TROJAN_URLS=$(curl -s "${SUBURL}" | base64 -d) - ## IPv4 list - SERVERS_LIST=$(echo "$TROJAN_URLS" | cut -d'@' -f2 | cut -d':' -f1 | sort | uniq) - ipv4_list=$(query_ipv4 "$SERVERS_LIST") - sed -i "s/^IPV4_SERVERS_LIST=.*$/IPV4_SERVERS_LIST=\"$ipv4_list\"/" $(realpath $0) && echo "Successfully updated $(tput bold)$(echo "$ipv4_list" | wc -w)$(tput sgr0) IPv4 addresses" - ## IPv6 list - ipv6_list=$(query_ipv6 "$SERVERS_LIST") - sed -i "s/^IPV6_SERVERS_LIST=.*$/IPV6_SERVERS_LIST=\"$ipv6_list\"/" $(realpath $0) && echo "Successfully updated $(tput bold)$(echo "$ipv6_list" | wc -w)$(tput sgr0) IPv6 addresses" - ## JSON - : >"$INFO" - while read -r node; do - ## mark - mark=$(urldecode ${node#*\#}) - mark=$(echo $mark | edit_mark) - mark_lower=$(echo $mark | tr '[:upper:]' '[:lower:]' | tr ' ' '_') - country=$(echo $mark | cut -d' ' -f1) - flag=$(echo $country | name2flag) - provider=$(echo $mark | cut -d' ' -f2) - order=$(echo $mark | cut -d' ' -f3) - ## info - node=${node#trojan://} && node=${node%\#*} - password=${node%\@*} && node=${node#*@} - remote_addr=${node%\:*} - remote_port=${node#*:} - case $provider in GIA|RT|AWS|Azure|CHT|TFN|TTNet|KDDI|GTT|Cogent|ETPI|KT|NTT|PCCW|WTT) level=global ratio="1";; esac - case $provider in BGP) level=bgp ratio="1";; esac - case $provider in IPLC) level=iplc ratio="2";; esac - case $provider in IEPL) level=iepl ratio="2";; esac - case $provider in Gamer) level=advanced ratio="10";; esac - ## json - jo remote_addr=$remote_addr remote_port=$remote_port password="[\"$password\"]" mark="$(jo -- level=$level ratio=$ratio name="$mark" id="$mark_lower" flag="$flag" country="$country" provider="$provider" -s order="$order")" - unset level ratio - done < <(echo "$TROJAN_URLS" | sed 's/?allowInsecure=1&tfo=1//') | jo -p -a >"$INFO" && echo "Successfully updated $(tput bold)$(jq -r '.[].remote_addr' "$INFO"| wc -l)$(tput sgr0) servers" -} - -gen_hosts() { - DOMAINS=$(jq -r '.[].remote_addr' srvinfo.json | grep '[[:alpha:]]') - while IFS= read -r domain; do - query_ipv4 $domain | tr ' ' '\n' | sed "s/$/ $domain/" - done <<< "$DOMAINS" | column -t -} - -## Part 2: JSON - -urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } -name2flag() { - sed -e ' - s/AE/🇦🇪/ - s/AU/🇦🇺/ - s/BR/🇧🇷/ - s/DE/🇩🇪/ - s/FR/🇫🇷/ - s/GB/🇬🇧/ - s/HK/🇭🇰/ - s/IN/🇮🇳/ - s/JP/🇯🇵/ - s/KR/🇰🇷/ - s/PH/🇵🇭/ - s/RU/🇷🇺/ - s/SG/🇸🇬/ - s/TR/🇹🇷/ - s/TW/🇹🇼/ - s/US/🇺🇸/ - ' -} -edit_mark() { - sed -e ' - s/^俄羅斯/RU/ - s/^印度/IN/ - s/^土耳其/TR/ - s/^巴西/BR/ - s/^德國/DE/ - s/^新加坡/SG/ - s/^日本/JP/ - s/^法國/FR/ - s/^澳大利亞/AU/ - s/^美國/US/ - s/^臺灣/TW/ - s/^英國/GB/ - s/^菲律賓/PH/ - s/^韓國/KR/ - s/^香港/HK/ - s/^阿聯酋/AE/ - ' -} -query_nodes() { - case "$LEVEL" in - global|bgp|iplc|iepl|advanced) - # summary - ratio=$(jq -r --arg v "$LEVEL" '[.[].mark | select(.level==$v)][0].ratio' "$INFO") - countries=$(jq -r --arg v "$LEVEL" '.[].mark | select(.level==$v) | .country' "$INFO" | sort | uniq | tr '[:upper:]' '[:lower:]' | tr '\n' ' ') - providers=$(jq -r --arg v "$LEVEL" '.[].mark | select(.level==$v) | .provider' "$INFO" | sort | uniq | tr '\n' ' ') - # list of servers - #srvlist=$(jq -r --arg v "$LEVEL" '.[].mark | select(.level==$v) | .id + "\t" + .time_appconnect' "$INFO" | sed 's/^/ /' | sort) - #num_srv=$(echo "$srvlist" | wc -l) - # print - srvlist=$(jq -r --arg v "$LEVEL" '.[].mark | select(.level==$v) | .time_appconnect + "|" + .speed_download + "|" + .id' "$INFO" | sed 's/^/ /' | sort -hr | column -s'|' -t) - echo -e "\n$srvlist\n" - echo -e "Level:|${LEVEL^}\nRatio:|$ratio\nCountries:|$countries\nNodes:|${num_srv}\nProviders:|$providers" | column -s'|' -t | sed 's/^/ /' && echo - ;; - time) jq -r '.[].mark | .time_appconnect + "|" + .speed_download + "|" + .id' $INFO | sed 's/^/ /' | column -s'|' -t | sort -hr | sed '/^ /d' | grep 'MiB/s\|0B/s' | GREP_COLORS='ms=01;32' egrep --color 'hk_|kr_|jp_|tw_|$';; - speed) jq -r '.[].mark | .speed_download + "|" + .time_appconnect + "|" + .id' $INFO | sed 's/^/ /' | column -s'|' -t | sort -h | sed '/^ /d' | grep 'MiB/s\|0B/s' | GREP_COLORS='ms=01;32' egrep --color 'hk_|kr_|jp_|tw_|$';; - country) jq -r '.[].mark | .id + "|" + .time_appconnect + "|" + .speed_download' $INFO | sed 's/^/ /' | column -s'|' -t | sort -h | GREP_COLORS='ms=01;32' egrep --color 'hk_|kr_|jp_|tw_|$';; - - *) usage ;; - esac -} -switch_node() { - # info - if [[ ! -z "$NODE" ]] && [[ $(jq -r --arg v "$NODE" '.[].mark | select(.id==$v) | .id' $INFO) == "$NODE" ]]; then - id="$NODE" - else - echo "No such node" && exit 1 - fi - # variables - remote_addr=$(jq -r --arg v "$id" '.[] | select(.mark.id==$v) | .remote_addr' "$INFO") - remote_port=$(jq -r --arg v "$id" '.[] | select(.mark.id==$v) | .remote_port' "$INFO") - password=$(jq -r --arg v "$id" '.[] | select(.mark.id==$v) | .password | .[0]' "$INFO") - level=$(jq -r --arg v "$id" '.[].mark | select(.id==$v) | .level' "$INFO") - ratio=$(jq -r --arg v "$id" '.[].mark | select(.id==$v) | .ratio' "$INFO") - flag=$(jq -r --arg v "$id" '.[].mark | select(.id==$v) | .flag' "$INFO") - id=$(jq -r --arg v "$id" '.[].mark | select(.id==$v) | .id' "$INFO") - name=$(jq -r --arg v "$id" '.[].mark | select(.id==$v) | .name' "$INFO") - provider=$(jq -r --arg v "$id" '.[].mark | select(.id==$v) | .provider' "$INFO") - # edit config - jj -v "$remote_addr" -p -i $CONFIG -o $CONFIG 'remote_addr' - jj -v "$remote_port" -p -i $CONFIG -o $CONFIG 'remote_port' - jj -v "$password" -p -i $CONFIG -o $CONFIG 'password.0' - jj -v "$level" -p -i $CONFIG -o $CONFIG 'info.level' - jj -v "$ratio" -p -i $CONFIG -o $CONFIG 'info.ratio' - jj -v "$flag" -p -i $CONFIG -o $CONFIG 'info.flag' - jj -v "$id" -p -i $CONFIG -o $CONFIG 'info.id' - jj -v "$name" -p -i $CONFIG -o $CONFIG 'info.name' - jj -v "$provider" -p -i $CONFIG -o $CONFIG 'info.provider' - #echo -e "Level:|$level\nRatio:|$ratio\nNode:|$NODE\nServer:|$remote_addr\nPort:|$remote_port\nPassword:|$password" | column -s'|' -t - echo -e "$id\t${remote_addr}:${remote_port}" -} - -get_info() { - echo "Servers: $(tput bold)$(jq -r '.[].remote_addr' $INFO | wc -l)$(tput sgr0)" - echo "IPv4: $(tput bold)$(echo $IPV4_SERVERS_LIST | wc -w)$(tput sgr0)" - echo "IPv6: $(tput bold)$(echo $IPV6_SERVERS_LIST | wc -w)$(tput sgr0)" - echo - [ -s /var/service/trojan/supervise/pid ] && jq -r '.info | "NAT: " + .name + " (" + .level + " *" + (.ratio|tostring) + ")"' /etc/trojan/config.json - [ -s $HOME/.local/service/trojan-client/supervise/pid ] && jq -r '.info | "Client: " + .name + " (" + .level + " *" + (.ratio|tostring) + ")"' $HOME/.local/service/trojan-client/client.json - -} - -speedtest() { - case "$LEVEL" in - global|bgp|iplc|iepl|advanced) - read -p "Type $(tput bold)Yes$(tput sgr0) to continue... " && [ $REPLY == "Yes" ] || { echo "$(tput bold; tput setaf 1)Canceled$(tput sgr0)"; exit 1; } - #echo "$INFO $CONFIG" - SERVERS=$(jq -r --arg v "$LEVEL" '.[].mark | select(.level==$v) | .id' $INFO) - #echo "$SERVERS" - for id in $SERVERS; do - #id=$(jq -r --arg v "$sid" '.[] | select(.id==$v) | .mark | .id' $INFO) - index=$(jq -r --arg v "$id" 'map(.mark.id==$v) | index(true)' $INFO) - NODE=$id switch_node - if sv reload ~/.local/service/trojan-client{,/log} >/dev/null; then - sleep 1 - else - echo "Failed to reload trojan-client service config, exiting..." && exit 1 - fi - time_appconnect=$(curl --connect-timeout 2 -x socks5h://127.0.0.1:51837 -o/dev/null -sw '%{time_appconnect}' 'https://connectivitycheck.gstatic.com/generate_204') - time_appconnect=$(printf "%.0f ms" "$(bc<<<${time_appconnect}*1000)") - if [[ $time_appconnect == "0 ms" ]]; then - time_appconnect="" - speed_download="" - else - speed_download=$(curl -x socks5h://127.0.0.1:51837 http://speedtest-sgp1.digitalocean.com/10mb.test -s -o/dev/null --write-out '%{speed_download}' | numfmt --to=iec-i --suffix=B/s) - fi - echo -e "$time_appconnect\t$speed_download\n" - jj -v "$time_appconnect" -p -i $INFO -o $INFO "$index.mark.time_appconnect" - jj -v "$speed_download" -p -i $INFO -o $INFO "$index.mark.speed_download" - done;; - *) usage ;; - esac -} - -usage() { - cat <<_EOF | GREP_COLORS='ms=1' egrep --color "$progname|$" -Usage: $progname <node_level> query nodes by levels - $progname <time|speed|country> query nodes by types - $progname sn <node_id> switch node (nat) - $progname sc <node_id> switch node (client) - $progname i show info - - $progname -u update IP list and json - $progname -t <node_level> speed test - - sudo $progname -a add iptables rules - sudo $progname -c clear iptables rules - - +------------+-------+-------------+ - | node_level | ratio | provider | - +------------+-------+-------------+ - | global | 1 | *various* | - | bgp | 1.2 | BGP | - | iplc | 2 | IPLC | - | iepl | 2 | IEPL | - | advanced | 10 | *gamer* | - +------------+-------+-------------+ - -_EOF - exit 1 -} - -case "$1" in - global|bgp|iplc|iepl|advanced|time|speed|country) LEVEL=$1 query_nodes | GREP_COLORS='ms=01;32' egrep --color 'hk_|kr_|jp_|tw_|$';; - sn) - NODE=$2 switch_node - sv reload trojan{,/log} - ;; - sc) - NODE=$2 CONFIG=~/.local/service/trojan-client/client.json switch_node - sv reload ~/.local/service/trojan-client - ;; - i) get_info ;; - #-h) gen_hosts ;; - -u) update_srv ;; - -t) CONFIG=~/.local/service/trojan-client/client.json LEVEL=$2 speedtest ;; - -a) add_iptables_rules ;; - -c) clear_iptables_rules ;; - *) usage ;; -esac -exit 0 - - -## extra comands -# jq -r --arg v global '.[].mark | select(.level==$v) | .speed_download + "|" + .time_appconnect + "|" + .id' ~/.local/share/data/trojan/srvinfo.json | sed 's/^/ /' | column -s'|' -t | sort -h -# jq -r '.[].mark | .speed_download + "|" + .time_appconnect + "|" + .id' ~/.local/share/data/trojan/srvinfo.json | sed 's/^/ /' | column -s'|' -t | sort -h | GREP_COLORS='ms=01;32' egrep --color 'hk_|kr_|jp_|tw_|$' -# jq -r '.[].mark | .time_appconnect + "|" + .speed_download + "|" + .id' ~/.local/share/data/trojan/srvinfo.json | sed 's/^/ /' | column -s'|' -t | sort -h | GREP_COLORS='ms=01;32' egrep --color 'hk_|kr_|jp_|tw_|$' diff --git a/.local/bin/voidlinux-installer-base.sh b/.local/bin/voidlinux-installer-base.sh @@ -1,134 +0,0 @@ -#!/bin/sh - -# a shell script to perform a very basic installation of Void Linux - -: "${progname:="${0##*/}"}" -[ "$(id -u)" -ne 0 ] && { echo "This script must be run as root"; exit 1; } - - -usage() { - cat <<_EOF -Usage: $progname [glibc|musl] -_EOF -} - -partition_format() { - umount /dev/sda* - umount -R /mnt - wipefs -a /dev/sda - dd if=/dev/zero of=/dev/sda bs=8M count=80 status=progress - ( - echo o # create a new empty DOS partition table - echo n # partition 1, primary, 200M - echo p - echo 1 - echo - echo +200M - echo n # partition 2, primary - echo p - echo 2 - echo - echo - echo a # bootable: partition 1 - echo 1 - echo w # write table to disk and exit - ) | fdisk /dev/sda - sync - mkfs.vfat -F32 /dev/sda1 - mkfs.xfs -f /dev/sda2 - sync -} - -mount_bootstrap() { - mount /dev/sda2 /mnt - mkdir /mnt/boot - mount /dev/sda1 /mnt/boot - XBPS_ARCH="$XBPS_ARCH" xbps-install -y -S -R "$VOID_REPO" -r /mnt base-system syslinux - for mp in sys dev proc; do - mount --rbind /$mp /mnt/$mp && mount --make-rslave /mnt/$mp - done - cp /etc/resolv.conf /mnt/etc/ - -} - -chroot_script() { - cat >/mnt/home/chroot_script.sh <<- _CHROOT_SCRIPT_EOF -### System configuration -sed -i ' -s/^#HARDWARECLOCK=.*/HARDWARECLOCK="UTC"/ -s/^#TIMEZONE=.*/TIMEZONE="UTC"/ -s/^#KEYMAP=.*/KEYMAP="dvorak-programmer"/ -s/^#FONT=.*/FONT="Lat2-Terminus16"/ -' /etc/rc.conf -if [ "$XBPS_ARCH" = "x86_64" ]; then - sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/default/libc-locales - xbps-reconfigure -f glibc-locales -fi -echo void-basic >/etc/hostname -echo "UUID=$(blkid -o value -s UUID /dev/sda1)\t/boot\tvfat\tdefaults\t0\t0" >>/etc/fstab -echo "UUID=$(blkid -o value -s UUID /dev/sda2)\t/\txfs\trw,noatime,discard\t0\t1" >>/etc/fstab -echo 'hostonly="yes"' >/etc/dracut.conf.d/hostonly.conf - -### User -useradd -m -s /bin/bash baz -echo 'password\npassword' | passwd baz -echo 'password\npassword' | passwd -echo 'cat /proc/uptime >/tmp/uptime' >>/home/baz/.bash_profile - -### tty1 autologin -cp -r /etc/sv/agetty-tty1 /etc/sv/agetty-autologin-tty1 -rm /etc/sv/agetty-autologin-tty1/supervise -sed -i 's/GETTY_ARGS="--noclear"/GETTY_ARGS="--autologin baz --noclear"/' /etc/sv/agetty-autologin-tty1/conf -#rm /etc/runit/runsvdir/current/agetty-tty1 -#ln -s /etc/sv/agetty-autologin-tty1 /etc/runit/runsvdir/current/agetty-tty1 - -### syslinux -mkdir /boot/syslinux -cp /usr/lib/syslinux/ldlinux.c32 /boot/syslinux/ -extlinux --install /boot/syslinux -dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/mbr.bin of=/dev/sda -cat >/etc/kernel.d/post-install/50-syslinux <<- END_OF_50_SYSLINUX -#!/bin/sh -PKGNAME="\\\$1" -VERSION="\\\$2" -cat >/boot/syslinux/syslinux.cfg <<- END_OF_SYSLINUX_CFG -PROMPT 1 -TIMEOUT 50 -DEFAULT void -LABEL void -LINUX /vmlinuz-\\\${VERSION} -APPEND initrd=/initramfs-\\\${VERSION}.img -END_OF_SYSLINUX_CFG -END_OF_50_SYSLINUX -chmod 754 /etc/kernel.d/post-install/50-syslinux -xbps-reconfigure -fa -rm /etc/runit/runsvdir/current/agetty-tty1 -ln -s /etc/sv/agetty-autologin-tty1 /etc/runit/runsvdir/current/agetty-tty1 -_CHROOT_SCRIPT_EOF -chroot /mnt /bin/sh /home/chroot_script.sh -rm /mnt/home/chroot_script.sh -umount -R /mnt -} - -case $1 in - glibc) - read -p "Press Enter to continue... " reply - [ "$reply" != "" ] && { echo "Stopped."; exit 0; } - XBPS_ARCH="x86_64" - VOID_REPO="https://alpha.de.repo.voidlinux.org/current" - partition_format - mount_bootstrap - chroot_script - ;; - musl) - read -p "Press Enter to continue... " reply - [ "$reply" != "" ] && { echo "Stopped."; exit 0; } - XBPS_ARCH="x86_64-musl" - VOID_REPO="https://alpha.de.repo.voidlinux.org/current/musl" - partition_format - mount_bootstrap - chroot_script - ;; - *) usage;; -esac - diff --git a/.local/bin/voidlinux-mirror-speedtest.sh b/.local/bin/voidlinux-mirror-speedtest.sh @@ -1,81 +0,0 @@ -#!/bin/sh - -PKG_PATH="current/glibc-2.32_2.x86_64.xbps" -SPEED_LIMIT="1048576" -# https://docs.voidlinux.org/xbps/repositories/mirrors/index.html -MIRRORLIST="\ -https://alpha.de.repo.voidlinux.org/ T1 EU: Finland -https://mirrors.servercentral.com/voidlinux/ T1 USA: Chicago -https://alpha.us.repo.voidlinux.org/ T1 USA: Kansas City -https://mirror.ps.kz/voidlinux/ T2 Asia: Almaty, KZ -https://mirrors.bfsu.edu.cn/voidlinux/ T2 Asia: China -https://mirrors.cnnic.cn/voidlinux/ T2 Asia: China -https://mirrors.tuna.tsinghua.edu.cn/voidlinux/ T2 Asia: China -https://mirror.sjtu.edu.cn/voidlinux/ T2 Asia: China -https://mirror.maakpain.kro.kr/void/ T2 Asia: Seoul, SK -https://void.webconverger.org/ T2 Asia: Singapore -https://mirror.aarnet.edu.au/pub/voidlinux/ T2 AU: Canberra -https://ftp.swin.edu.au/voidlinux/ T2 AU: Melbourne -https://void.cijber.net/ T2 EU: Amsterdam, NL -https://mirror.easylee.nl/voidlinux/ T2 EU: Amsterdam, NL -http://ftp.dk.xemacs.org/voidlinux/ T2 EU: Denmark -https://mirrors.dotsrc.org/voidlinux/ T2 EU: Denmark -https://quantum-mirror.hu/mirrors/pub/voidlinux/ T2 EU: Hungary -https://voidlinux.qontinuum.space:4443/ T2 EU: Monaco -http://ftp.debian.ru/mirrors/voidlinux/ T2 EU: Russia -https://mirror.yandex.ru/mirrors/voidlinux/ T2 EU: Russia -https://cdimage.debian.org/mirror/voidlinux/ T2 EU: Sweden -https://ftp.acc.umu.se/mirror/voidlinux/ T2 EU: Sweden -https://ftp.lysator.liu.se/pub/voidlinux/ T2 EU: Sweden -https://ftp.sunet.se/mirror/voidlinux/ T2 EU: Sweden -https://mirror.clarkson.edu/voidlinux/ T2 USA: New York" - -show_usage() { - : "${progname:="${0##*/}"}" - cat <<_EOF | GREP_COLORS='ms=1' egrep --color "$progname|$" -Usage: $progname show usage info - $progname -w [file.csv] save speedtest results to file - $progname -r file.csv format speedtest results from file - $progname -f file.csv format speedtest results from file and pass to fzf - -pkg path: ${PKG_PATH} -speed limit: $(echo $SPEED_LIMIT | numfmt --to=iec-i --suffix=B/s) -mirrors for testing: $(echo "$MIRRORLIST" | wc -l) -_EOF -} - -format_speedtest_results() { - cat "$1" | sort -t, -nrk4 | while IFS=, read url info time_appconnect download_speed; do - f_time=$(printf "%.2fs" $time_appconnect) - f_speed=$(echo $download_speed | numfmt --to=iec-i --suffix=B/s) - echo "${url},${info},${f_time},${f_speed}" - done | column -s, -t -} - -time_appconnect() { - curl --connect-timeout 2 -o/dev/null -sw '%{time_appconnect}' -I $1 -} - -download_speed() { - curl -Y $SPEED_LIMIT --progress-bar $1 -o/dev/null --write-out "%{speed_download}" -} - -mirror_speedtest() { - count=1 - echo "$MIRRORLIST" | while read -r mirror etc; do - pkg_url="${mirror}${PKG_PATH}" - info=$(echo $etc | sed 's/,//g') - >&2 echo "${count}. $pkg_url" - echo "${mirror},${info},$(time_appconnect $pkg_url),$(download_speed $pkg_url)" - >&2 echo - count=$((count + 1)) - done -} - -case $1 in - -r) format_speedtest_results $2;; - -f) format_speedtest_results $2 | fzf +s;; - -w) [ -z $2 ] && { mirror_speedtest; exit 0; } || { mirror_speedtest >"$2"; exit 0; };; - *) show_usage;; -esac -exit 0 diff --git a/.local/bin/vpngate-dialog.sh b/.local/bin/vpngate-dialog.sh @@ -1,103 +0,0 @@ -#!/bin/bash - -CSV="/tmp/vpngate.csv" - -# $ sed 's/^#HostName,/HostName,/; 2q;d' /tmp/vpngate.csv | tr ',' '\n' | awk '{print NR " " $0}' | column -t -R1 -# 1 HostName -# 2 IP -# 3 Score -# 4 Ping -# 5 Speed -# 6 CountryLong -# 7 CountryShort -# 8 NumVpnSessions -# 9 Uptime -# 10 TotalUsers -# 11 TotalTraffic -# 12 LogType -# 13 Operator -# 14 Message -# 15 OpenVPN_ConfigData_Base64 - - -# check dependencies -which dialog curl awk sort uniq awk grep column >/dev/null || exit 1 - -# get vpngate.csv -if [ ! -f $CSV ]; then - dialog --yesno "$CSV not found, download it?" 6 28 - if [ $? = 0 ]; then - curl -o "$CSV" "https://www.vpngate.net/api/iphone/" 2>&1 | dialog --progressbox 20 85 - else - clear - exit 0 - fi -fi - -# get server list -SRV_LIST=$(sed -e ' - 1,2d;$d - s/,Korea Republic of,/,South Korea,/ - s/,Russian Federation,/,Russia,/ - s/,Viet Nam,/,Vietnam,/ - ' $CSV -) - -get_ovpn() { - # select country - local C=(ALL ALL) - while read -r line; do - country_short=${line%,*} - country_long=${line#*,} - C+=($country_short "$country_long") - done < <(echo "$SRV_LIST" | awk -F',' -vOFS=',' '{print toupper($7), $6}' | sort | uniq) - - if [ -z "$country" ]; then - country=$(dialog --title "Select country" --menu "Choose server location" 20 40 17 "${C[@]}" 3>&2 2>&1 1>&3) - [ $? -ne 0 ] && { clear; exit 0; } - fi - [ "$country" != ALL ] && local SRV_LIST=$(echo "$SRV_LIST" | grep -i ",${country},") - - # array of list of VPN Gate servers for dialog - local SRV_LIST_FORMATTED=$(echo "$SRV_LIST" \ - | awk -F',' -vOFS=',' '{print $3, $4, $5, $6}' \ - | awk -F',' -vOFS=',' '{ - tmp_score="echo "$1" | numfmt --to=si" - tmp_speed="echo "$3" | numfmt --to=iec-i --suffix=B/s --format=\"%.1f\"" - tmp_score | getline score - tmp_speed | getline speed - $1=score - $3=speed - print - }' - ) - - let i=0 - local W=("N" "Score Ping Speed Country") - while read -r line; do - let i=$i+1 - W+=($i "$line") - done < <(echo "$SRV_LIST_FORMATTED" | column -s',' -t -R1,2,3) - - # select server and save ovpn files - NUM=$(dialog \ - --title "List of VPN Gate servers ($country)" \ - --default-item "$NUM" \ - --menu "Choose to save ovpn file" 40 60 17 "${W[@]}" 3>&2 2>&1 1>&3) - if [ -z "$NUM" ]; then - clear - exit 0 - else - if [ $NUM = "N" ]; then - unset country - else - local SRV_INFO=$(echo "$SRV_LIST" | sed -n "${NUM}p") - IFS=, read HostName IP Score Ping Speed CountryLong CountryShort Other <<<"$(echo $SRV_INFO)" - local OVPN="vpngate_${CountryShort,,}_${HostName}.ovpn" - dialog --yesno "Save file to \"${OVPN}\"?" 6 40 - [ $? = 0 ] && echo "$SRV_INFO" | awk -F',' '{print $15}' | base64 -di >$OVPN - fi - fi -} - -while true; do get_ovpn; done diff --git a/.local/bin/vpngate-fzf.sh b/.local/bin/vpngate-fzf.sh @@ -1,63 +0,0 @@ -#!/bin/sh - -CSV="/tmp/vpngate.csv" - -# check dependencies -which curl fzf tput sed column cut base64 >/dev/null || exit 1 - -# download vpngate.csv - -if [ ! -f $CSV ]; then - echo "$(tput bold; tput setaf 4)$CSV$(tput setaf 1) not found$(tput sgr0), do you want to download it?" - read -p "Press $(tput bold)Enter$(tput sgr0) to continue... " -r ANSWER && [ "$ANSWER" = "" ] || { echo "$(tput bold; tput setaf 1)Canceled$(tput sgr0)"; exit 0; } - curl -o "$CSV" --progress-bar 'https://www.vpngate.net/api/iphone/' -fi - - -# echo "$(seq -s, 1 15)\n$(sed -n 2p vpngate.csv | sed 's/^#HostName,/HostName,/')" | column -s',' -t -# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -# HostName IP Score Ping Speed CountryLong CountryShort NumVpnSessions Uptime TotalUsers TotalTraffic LogType Operator Message OpenVPN_ConfigData_Base64 - -get_csv() { - echo '0,Hostname,Score,Ping,Speed,Country,Code,Sessions,Uptime,Users,Traffic,Log,Operator,Message' - local i=0; sed -e ' - 1,2d;$d - s/weeks,/ weeks,/ - s/^#HostName,/HostName,/ - s/,Korea Republic of,/,South Korea,/ - s/,Russian Federation,/,Russia,/ - s/,Viet Nam,/,Vietnam,/ - ' $CSV \ - | while IFS=, read HostName IP Score Ping Speed CountryLong CountryShort NumVpnSessions Uptime TotalUsers TotalTraffic LogType Operator Message OpenVPN_ConfigData_Base64; do - local i=$(($i + 1)) - Score=$(numfmt --to=si $Score) - Speed=$(numfmt --to=iec-i --suffix=B/s --format="%.1f" $Speed) - UptimeInMilliseconds=$Uptime - Uptime=$(echo "$(($UptimeInMilliseconds/15552000000)) years") # 1000*60*60*12*30*12 - [ "${Uptime%% *}" -eq 0 ] && Uptime="$(($UptimeInMilliseconds/1296000000)) months" # 1000*60*60*12*30 - [ "${Uptime%% *}" -eq 0 ] && Uptime="$(($UptimeInMilliseconds/43200000)) days" # 1000*60*60*12 - [ "${Uptime%% *}" -eq 0 ] && Uptime="$(($UptimeInMilliseconds/3600000)) hours" # 1000*60*60 - [ "${Uptime%% *}" -eq 0 ] && Uptime="$(($UptimeInMilliseconds/60000)) minutes" # 1000*60 - [ "${Uptime%% *}" -eq 0 ] && Uptime="$(($UptimeInMilliseconds/1000)) seconds" # 1000 - [ "${Uptime%% *}" -eq 0 ] && Uptime="${UptimeInMilliseconds} milliseconds" - TotalUsers=$(numfmt --to=si $TotalUsers) - TotalTraffic=$(numfmt --to=iec-i --suffix=B --format="%.1f" $TotalTraffic) - # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 - echo "$i,$HostName,$Score,$Ping,$Speed,$CountryLong,$CountryShort,$NumVpnSessions,$Uptime,$TotalUsers,$TotalTraffic,$LogType,$Operator,$Message" - done -} - -get_srv() { - local NUM=$(get_csv | column -s, -t -R3,4,5,8,10,11 | fzf +s | cut -d' ' -f1) - [ -z "$NUM" ] && exit 0 - if [ "$NUM" -ne 0 ]; then - local SRV=$(sed -n "$(($NUM + 2))p" $CSV) - local CountryCode=$(echo $SRV | awk -F, '{print tolower($7)}') - local Hostname=$(echo $SRV | awk -F, '{print $1}') - local OVPN="vpngate_${CountryCode}_${Hostname}.ovpn" - read -p "Press $(tput bold)Enter$(tput sgr0) to save $(tput bold; tput setaf 4)${OVPN}$(tput sgr0)... " -r ANSWER - [ "$ANSWER" = "" ] && echo $SRV | awk -F, '{print $15}' | base64 -di >$OVPN - fi -} - -while true; do get_srv; done diff --git a/.local/bin/vpngate-prompt.sh b/.local/bin/vpngate-prompt.sh @@ -1,91 +0,0 @@ -#!/bin/sh - -ServerList="https://www.vpngate.net/api/iphone/" -CSV="/tmp/vpngate.csv" - -: "${progname:="${0##*/}"}" - - - -help() { - cat <<_EOF | GREP_COLORS='ms=01;32' egrep --color "^f |^l |^g |^h |^c |^q|$" -f | fetch fetch $FileName -l | list list servers -g | get get OpenVPN ovpn file(s) -h | help show this help -c | clear clear the terminal screen -q | quit quit - -_EOF - if [ -f $CSV ]; then - srv_info - echo - else - echo "$(tput bold)$(tput setaf 1)Can't find $FileName" - echo "Please fetch it at first$(tput sgr0)" - fi -} - -fetch_srv() { - local HTTP_CODE=$(curl -s --write-out %{http_code} -o "$CSV" "$ServerList") - case "$HTTP_CODE" in - 200) echo "$(tput bold)$(tput setaf 2)successfully fetched $FileName$(tput sgr0)";; - 000) echo "failed to fetch $FileName";; - *) echo "HTTP code: ($HTTP_CODE)";; - esac - echo -} - -srv_info() { - local total=$(sed '1,2d;$d' $CSV | wc -l) - echo "total servers: $(tput setaf 4)${total}$(tput sgr0)" -} - -list_srv() { - srv_info - SRV_ALL=$(sed '1,2d;$d' $CSV) - local countries=$(echo "$SRV_ALL" | awk -F',' -vOFS=',' '{print $7}' | sort | uniq | tr '[:upper:]' '[:lower:]' | paste -s -d' ') - local country_list=$(echo $countries | tr ' ' '|') - echo "available countries: $(tput bold)$(tput setaf 2)$countries$(tput sgr0)" - echo "$(tput setaf 3)Input one of the country name above" - echo "or leave it blank to list all servers$(tput sgr0)" - read -p "country: " country - local SRV_LIST=$(echo "$SRV_ALL" | grep -i ",$country," | awk -F',' -vOFS=',' '{print $3, $4, $5, $1, $6}' | awk -F',' -vOFS=',' '{tmp_score="echo "$1" | numfmt --to=si"; tmp_speed="echo "$3" | numfmt --to=iec-i --suffix=B/s"; tmp_score | getline score; tmp_speed | getline speed; $1=score; $3=speed; print}' | sort -h) - if [ ! -z "${SRV_LIST}" ]; then - local SRV_LIST_APPEND=$(sed -n 2p $CSV | sed 's/^#HostName/HostName/' | awk -F',' -vOFS=',' '{print $3, $4, $5, $1, $6}') - echo "${SRV_LIST} -$(tput bold)$(tput setaf 4)${SRV_LIST_APPEND}$(tput sgr0)" | column -s',' -t - fi -} - -get_ovpn() { - echo "$(tput setaf 3) Input the hostname you get from the output of g | get" - echo " You can input multiple hostnames by using space as separator$(tput sgr0)" - read -p "hostname(s): " hostnames - for srv in $hostnames; do - if grep "^${srv}," $CSV >/dev/null; then - echo "$SRV_ALL" | grep "^${srv}," | awk -F',' -vOFS=',' '{print $15}' | base64 -di >${srv}.ovpn - echo "get: ${srv}.ovpn" - else - echo "$(tput bold)$(tput setaf 1)$srv: no such hostname$(tput sgr0)" - fi - done -} - -main_prompt() { - while true; do - read -p "$(basename $progname .sh)> $(tput bold)" cmd - tput sgr0 - case "$cmd" in - f|fetch) fetch_srv;; - l|list) list_srv;; - g|get) get_ovpn;; - h|help) help;; - c|clear) clear >$(tty);; - q|quit) exit 0;; - *) help;; - esac - done -} - -main_prompt diff --git a/.local/bin/webdav-curl-sync.sh b/.local/bin/webdav-curl-sync.sh @@ -1,68 +0,0 @@ -#!/bin/sh - -## $ crontab -l -## @reboot sleep 60 && ~/.local/bin/webdav-curl-sync.sh -d -## 0 */3 * * * ~/.local/bin/webdav-curl-sync.sh -d - -LAST_UPLOADED="" -: "${progname:="${0##*/}"}" - -preview() { - curl -s https://user:password@domain.tld:port/orgmode.org -} - -download() { - for orgmode in file1 file2; do - #HTTPS_PROXY="socks5h://127.0.0.1:1080" - filename="${orgmode}.org" - file="$HOME/orgmode/$filename" - uri="https://user:password@domain.tld:port/${orgmode}.org" - if test -e "$file"; then - zflag="-z $file" - else - zflag= - fi - HTTP_CODE=$(curl -sR --write-out %{http_code} -o "$file" $zflag "$uri") - LAST_MODIFIED=$(date -r $file -u '+%F %T') - echo -n 'Download: ' - case "$HTTP_CODE" in - 304) echo "$LAST_MODIFIED $filename (bypassed)";; - 200) echo "$LAST_MODIFIED $filename (update)";; - 000) echo "$filename (failed)";; - *) echo "$filename ($HTTP_CODE)";; - esac - done -} - -upload() { - dir="$HOME/orgmode" - uri="https://user:password@domain.tld:port/orgmode" - for orgmode in $dir/*.org; do - filename=$(basename $orgmode) - filemod=$(stat -c %Y $orgmode) - if [ "$filemod" -gt "$LAST_UPLOADED" ]; then - HTTP_CODE=$(curl -s -o /dev/null --write-out %{http_code} -T "$orgmode" "$uri/$filename") - if [ "$HTTP_CODE" = "201" ]; then - echo "UPLOAD: $filename" - sed -i "s/^LAST_UPLOADED=.*$/LAST_UPLOADED=\"$(date +%s)\"/" $(realpath $0) - else - echo "UPLOAD: $filename (failed)" - fi - else - echo "UPLOAD: $filename (bypassed)" - fi - done -} - -usage() { - echo "Usage: $progname -p|-u|-d|-a" -} - -case "$1" in - -p) preview ;; - -u) upload ;; - -d) download ;; - -a) download; upload ;; - *) usage ;; -esac -exit 0 diff --git a/.local/bin/x b/.local/bin/x @@ -1,24 +0,0 @@ -#!/bin/sh - -xinitrc() { - export DISPLAY=:0 - feh --randomize \ - --bg-scale $HOME/Pictures/Wallpapers/Landscape/*.jpg \ - --bg-scale $HOME/Pictures/Wallpapers/Portrait/*.jpg - exec sowm -} - -trap xinitrc USR1 - -( - trap '' USR1 - - exec X -ardelay 200 \ - -arinterval 20 \ - -dpms \ - -dpi 192 \ - -nolisten tcp \ - :0 vt1 -) & - -wait