feat: Update scripts
This commit is contained in:
parent
c6f72095cb
commit
c4f9a98658
4
dockerstart.sh
Executable file
4
dockerstart.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
sudo systemctl start docker
|
||||
sudo systemctl start docker.socket
|
4
dockerstop.sh
Executable file
4
dockerstop.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
sudo systemctl stop docker
|
||||
sudo systemctl stop docker.socket
|
119
hsd-domains.py
Normal file
119
hsd-domains.py
Normal file
@ -0,0 +1,119 @@
|
||||
import json
|
||||
import requests
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import getpass
|
||||
|
||||
# Try to get HSD_API_KEY from environment variable
|
||||
HSD_API_KEY = os.environ.get("HSD_API_KEY")
|
||||
if HSD_API_KEY is None:
|
||||
raise Exception("Please set HSD_API_KEY environment variable")
|
||||
|
||||
days_until_expire = 180
|
||||
|
||||
wallet_list = ["cold","hot","registry","greg","hnsau","renewservice"]
|
||||
|
||||
def get_domains(key,wallet):
|
||||
url = f"http://x:{key}@127.0.0.1:12039/wallet/{wallet}/name?own=true"
|
||||
response = requests.get(url)
|
||||
if response.status_code != 200:
|
||||
return []
|
||||
|
||||
# Check if the response is valid JSON
|
||||
try:
|
||||
response.json()
|
||||
except json.decoder.JSONDecodeError:
|
||||
return []
|
||||
|
||||
return response.json()
|
||||
|
||||
|
||||
def domains_expiring_soon(key,wallet,silent=False):
|
||||
domains = get_domains(key,wallet)
|
||||
expiring = []
|
||||
for domain in domains:
|
||||
days_left = domain["stats"]["daysUntilExpire"]
|
||||
if days_left < days_until_expire:
|
||||
if not silent:
|
||||
print(f"{domain['name']} expires in {days_left} days")
|
||||
expiring.append(domain["name"])
|
||||
|
||||
if len(expiring) > 0:
|
||||
with open(f"/tmp/domains_expiring_soon_{wallet}.txt", "w") as f:
|
||||
for domain in expiring:
|
||||
f.write(f"{domain}\n")
|
||||
return expiring
|
||||
|
||||
if __name__ == "__main__":
|
||||
# optional args --wallet <wallet> --days <days> --api_key <api_key>
|
||||
parser = argparse.ArgumentParser(description='Check HSD domains for expiration')
|
||||
parser.add_argument('--wallet', help='Wallet to check', default="all")
|
||||
parser.add_argument('--days', help='Days until expiration', default=180)
|
||||
parser.add_argument('--api_key', help='API key', default=HSD_API_KEY)
|
||||
parser.add_argument('--renew', help='Renew domains', action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
|
||||
HSD_API_KEY = args.api_key
|
||||
days_until_expire = args.days
|
||||
# Try to convert days_until_expire to an integer
|
||||
try:
|
||||
days_until_expire = int(days_until_expire)
|
||||
except ValueError:
|
||||
print("Invalid days_until_expire value")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
wallets = args.wallet
|
||||
if wallets == "all":
|
||||
wallets = wallet_list
|
||||
else:
|
||||
wallets = [wallets]
|
||||
|
||||
for wallet in wallets:
|
||||
print(f"Checking {wallet} wallet...")
|
||||
domains_expiring_soon(HSD_API_KEY,wallet)
|
||||
|
||||
if args.renew:
|
||||
print("Renewing domains...")
|
||||
for wallet in wallets:
|
||||
domains = domains_expiring_soon(HSD_API_KEY,wallet,silent=True)
|
||||
if len(domains) > 0:
|
||||
print(f"Renewing {len(domains)} domains for {wallet} wallet...")
|
||||
batch = []
|
||||
for domain in domains:
|
||||
batch.append(f'["RENEW", "{domain}"]')
|
||||
|
||||
batchTX = "[" + ", ".join(batch) + "]"
|
||||
reqcontent = f'{{"method": "sendbatch","params":[ {batchTX} ]}}'
|
||||
|
||||
# Select wallet
|
||||
response = requests.post(f'http://x:{HSD_API_KEY}@127.0.0.1:12039', data='{"method": "selectwallet","params": [ "'+wallet+'" ]}')
|
||||
if response.status_code != 200:
|
||||
print(f"Error selecting wallet {wallet}: {response.text}")
|
||||
continue
|
||||
|
||||
# Ask user for password
|
||||
password = getpass.getpass(prompt=f"Enter password for wallet {wallet}: ")
|
||||
if password != "":
|
||||
response = requests.post(f'http://x:{HSD_API_KEY}@127.0.0.1:12039', data='{"method": "walletpassphrase","params": [ "'+password+'", 300 ]}')
|
||||
if response.status_code != 200:
|
||||
print(f"Error setting password for wallet {wallet}: {response.text}")
|
||||
continue
|
||||
|
||||
response = requests.post(f'http://x:{HSD_API_KEY}@127.0.0.1:12039', data=reqcontent)
|
||||
|
||||
if response.status_code != 200:
|
||||
print(f"Error renewing domains for wallet {wallet}: {response.text}")
|
||||
continue
|
||||
|
||||
output = response.json()
|
||||
if "error" in output:
|
||||
if output["error"]:
|
||||
print(f"Error renewing domains for wallet {wallet}: {output['error']}")
|
||||
|
||||
print("TX: " + output["result"]["hash"])
|
||||
|
||||
|
25
music.sh
25
music.sh
@ -44,10 +44,14 @@ if ! command -v playerctl &>/dev/null; then
|
||||
fi
|
||||
|
||||
# Get all player names and statuses
|
||||
players=$(playerctl -a -l)
|
||||
players=$(playerctl -a -l 2>/dev/null)
|
||||
active_players=()
|
||||
brave=""
|
||||
|
||||
exlude=(
|
||||
"Messenger"
|
||||
)
|
||||
|
||||
# Loop through each player and check its status
|
||||
for player in $players; do
|
||||
if [ "$verbose" -eq 1 ]; then
|
||||
@ -62,6 +66,23 @@ for player in $players; do
|
||||
brave=$player
|
||||
fi
|
||||
|
||||
title=$(playerctl -p "$player" metadata --format '{{title}}' 2>/dev/null)
|
||||
if [ "$verbose" -eq 1 ]; then
|
||||
echo "Title: $title"
|
||||
fi
|
||||
|
||||
# If title contains any string in the exclude array, skip the player
|
||||
|
||||
for exclude in "${exlude[@]}"; do
|
||||
if [[ "$title" == *"$exclude"* ]]; then
|
||||
if [ "$verbose" -eq 1 ]; then
|
||||
echo "Excluding player $player"
|
||||
fi
|
||||
continue 2
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if [[ "$status" == "Playing" || "$status" == "Paused" ]]; then
|
||||
if [[ $verbose -eq 1 ]]; then
|
||||
echo "Player $player is active"
|
||||
@ -195,6 +216,7 @@ elif [ "$active_count" -gt 1 ]; then
|
||||
else
|
||||
# Check if brave is not empty
|
||||
if [ -z "$brave" ]; then
|
||||
echo ""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@ -224,6 +246,7 @@ else
|
||||
else
|
||||
echo " $truncated_title (Paused)"
|
||||
fi
|
||||
echo ""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
35
venv.sh
35
venv.sh
@ -1,15 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script is used to create a virtual environment for the project
|
||||
|
||||
# Check if the virtual environment already exists
|
||||
if [ -d ".venv" ]; then
|
||||
# Check if arg exit passed
|
||||
if [ "$1" = "exit" ]; then
|
||||
echo "Exiting virtual environment"
|
||||
deactivate
|
||||
else
|
||||
|
||||
if [ "$1" = "exit" ]; then
|
||||
echo "Exiting virtual environment"
|
||||
deactivate
|
||||
else
|
||||
# Check if the virtual environment already exists
|
||||
if [ -d ".venv" ]; then
|
||||
# Check if the virtual environment is active
|
||||
if [ -n "$VIRTUAL_ENV" ]; then
|
||||
echo "Virtual environment is active"
|
||||
@ -17,17 +14,17 @@ if [ -d ".venv" ]; then
|
||||
echo "Activating existing virtual environment"
|
||||
source .venv/bin/activate
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# Create the virtual environment
|
||||
python3 -m venv .venv
|
||||
else
|
||||
# Create the virtual environment
|
||||
python3 -m venv .venv
|
||||
|
||||
# Activate the virtual environment
|
||||
source .venv/bin/activate
|
||||
# Activate the virtual environment
|
||||
source .venv/bin/activate
|
||||
|
||||
# Install the required packages
|
||||
if [ -f "requirements.txt" ]; then
|
||||
echo "Installing required packages"
|
||||
python3 -m pip install -r requirements.txt
|
||||
# Install the required packages
|
||||
if [ -f "requirements.txt" ]; then
|
||||
echo "Installing required packages"
|
||||
python3 -m pip install -r requirements.txt
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
41
zellij.sh
41
zellij.sh
@ -1,23 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if focus on zellig window worked wmctrl -a zellij
|
||||
# Save logs to ~/.logs/zellij.log
|
||||
|
||||
# Check if focus on zellig window worked wmctrl -a zellij
|
||||
if [ -z "$(wmctrl -l | grep Zellij)" ]; then
|
||||
echo "No terminal running" > /tmp/message
|
||||
echo "No terminal running" >/tmp/message
|
||||
echo "No terminal running" >>~/.logs/zellij.log
|
||||
polybar-msg action message hook 0
|
||||
exit 1
|
||||
else
|
||||
wmctrl -a Zellij
|
||||
echo "Focused on terminal" >>~/.logs/zellij.log
|
||||
fi
|
||||
|
||||
# Get arguments and run in new zellij pane
|
||||
if [ "$#" -ne 0 ];
|
||||
then
|
||||
# Check if --cwd flag is passed
|
||||
if [ "$1" == "--cwd" ];
|
||||
then
|
||||
zellij run -fc --cwd "$2" -- "${@:3}"
|
||||
session=$(zellij list-sessions | grep -v "EXITED" | sed -r 's/\x1B\[[0-9;]*[mK]//g' | awk '{print $1}')
|
||||
|
||||
# For each line in the session list, echo to log
|
||||
for line in $session; do
|
||||
echo "Found session: $line" >>~/.logs/zellij.log
|
||||
echo "Found session: $line"
|
||||
# Get arguments and run in new zellij pane
|
||||
if [ "$#" -ne 0 ]; then
|
||||
# Check if --cwd flag is passed
|
||||
if [ "$1" == "--cwd" ]; then
|
||||
echo "Using cwd: $2" >>~/.logs/zellij.log
|
||||
echo "Running command: ${@:3}" >>~/.logs/zellij.log
|
||||
|
||||
zellij --session $line run -fc --cwd "$2" -- "${@:3}" >>~/.logs/zellij.log 2>&1
|
||||
else
|
||||
echo "Running command: $@" >>~/.logs/zellij.log
|
||||
zellij --session $line run -fc -- "$@" >>~/.logs/zellij.log 2>&1
|
||||
fi
|
||||
else
|
||||
zellij run -fc -- "$@"
|
||||
echo "No command provided" >>~/.logs/zellij.log
|
||||
echo "Usage: zelij.sh <command>"
|
||||
fi
|
||||
else
|
||||
echo "Usage: zelij.sh <command>"
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue
Block a user