[scripts] Add some of the legacy scripts
This commit is contained in:
parent
aeeda91fe7
commit
bb53d01244
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
# Script used for keeping the profile pictures up to date on https://nova-vps.ml
|
||||
|
||||
API_BASE="https://discord.com/api/v9"
|
||||
USERS=( "465702500146610176" "186496078273708033" "717352467280691331" )
|
||||
OUTPUT="$HOME/public_web/static/img/"
|
||||
|
||||
for user in "${USERS[@]}"; do
|
||||
data=$(curl -H "Authorization: Bot $DOTFILES_BOT_TOKEN" "$API_BASE/users/$user")
|
||||
avihash=$(jq -r '.avatar' <<< "$data")
|
||||
username=$(jq -r '.username' <<< "$data")
|
||||
wget "https://cdn.discordapp.com/avatars/$user/$avihash.png?size=2048" -O "$OUTPUT/$username.png"
|
||||
done
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
FILE="$1"
|
||||
DEST="$2"
|
||||
|
||||
command_exists () {
|
||||
whence -- "$@" &> /dev/null
|
||||
}
|
||||
|
||||
if ( ! command_exists markdown2htmldoc ); then
|
||||
echo "md2htmldoc not found. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
filename=$(basename -- "$FILE")
|
||||
extension="${filename##*.}"
|
||||
filename="${filename%.*}"
|
||||
content=$(cat "$FILE")
|
||||
|
||||
md_content="# \`$filename.$extension\`\n\n\`\`\`$extension\n$content\n\`\`\`"
|
||||
|
||||
echo "$md_content" > temp.md
|
||||
|
||||
markdown2htmldoc temp.md "$DEST/$filename.$extension.html"
|
||||
|
||||
rm -rf temp.md
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
ORG="$1"
|
||||
USRNAME="$2"
|
||||
TOKEN="$3"
|
||||
|
||||
for url in $(curl -Lf "https://api.github.com/orgs/$ORG/repos?per_page=1000" | jq -r '.[].html_url' | sort -u); do
|
||||
read repo <<< $(awk -F, -v url="$url" '{split($url,a,"/"); print a[5]}' <<<$url)
|
||||
echo "$ORG/$repo"
|
||||
curl -X PUT -H "Accept: application/vnd.github.v3+json" -u $USRNAME:$TOKEN "https://api.github.com/user/starred/$ORG/$repo"
|
||||
done
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env zsh
|
||||
# CPU load
|
||||
cpustat=$(top -bcn1 -w512 -o %CPU)
|
||||
cpuusage=$(echo $cpustat | awk 'BEGIN {FS = "[,:]\\W+"} NR==3 {i=index($5," "); print 100-substr($5,0,i-1)}')
|
||||
highestcpu=$(echo $cpustat | awk 'NR==8')
|
||||
|
||||
highestcpu_ram=$(echo $highestcpu | awk '{mem=$10; print mem}')
|
||||
highestcpu_cpu=$(echo $highestcpu | awk '{cpu=$9; print cpu}')
|
||||
highestcpu_proc=$(echo $highestcpu | awk '{time=$11; print substr($0, index($0,time)+length(time)+1)}')
|
||||
|
||||
# RAM load
|
||||
memusage=$(free | grep Mem | awk '{print $3/$2 * 100.0}')
|
||||
highestmem=$(ps -eo '%mem %cpu cmd' --sort='-%mem' | awk 'NR==2')
|
||||
|
||||
highestmem_ram=$(echo $highestmem | awk '{print $1}')
|
||||
highestmem_cpu=$(echo $highestmem | awk '{print $2}')
|
||||
highestmem_proc=$(echo $highestmem | awk '{print substr($0, index($0, $3))}')
|
||||
|
||||
# Reporting
|
||||
webhook="$DOTFILES_WEBHOOK_URL"
|
||||
|
||||
ping=""
|
||||
for id in "465702500146610176" "186496078273708033"; do
|
||||
ping="$ping <@$id>"
|
||||
done
|
||||
|
||||
# Usage under 70% is acceptable. If over 70% for long, then something is wrong.
|
||||
if (( $cpuusage > 70 )); then
|
||||
cpu1=$(printf "%-25s %s%%" "Total CPU load" "$cpuusage")
|
||||
cpu2=$(printf "%-25s %s%%" "Max CPU process (RAM%)" "$highestcpu_ram")
|
||||
cpu3=$(printf "%-25s %s%%" "Max CPU process (CPU%)" "$highestcpu_cpu")
|
||||
cpu4=$(printf "%-25s %s" "Max CPU process" "$highestcpu_proc")
|
||||
curl -H "Content-Type: application/json" -d '{"username": "CPU Alert", "content": "'"$ping"'\n```\n'"$cpu1"'\n'"$cpu2"'\n'"$cpu3"'\n'"$cpu4"'\n```"}' $webhook
|
||||
fi
|
||||
|
||||
# Usage under 70% is acceptable. If over 70% for long, then something is wrong.
|
||||
if (( $memusage > 70 )); then
|
||||
mem1=$(printf "%-25s %s%%" "Total RAM load" "$memusage")
|
||||
mem2=$(printf "%-25s %s%%" "Max RAM process (RAM%)" "$highestmem_ram")
|
||||
mem3=$(printf "%-25s %s%%" "Max RAM process (CPU%)" "$highestmem_cpu")
|
||||
mem4=$(printf "%-25s %s" "Max RAM process" "$highestmem_proc")
|
||||
curl -H "Content-Type: application/json" -d '{"username": "RAM Alert", "content": "'"$ping"'\n```\n'"$mem1"'\n'"$mem2"'\n'"$mem3"'\n'"$mem4"'\n```"}' $webhook
|
||||
fi
|
Loading…
Reference in New Issue