summarylogtreecommitdiffstats
path: root/spxc
blob: 92fad4fb1a61d9b5a4a5c69cc5794c6dcb021c4d (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
VERSION="V1.7.8"

case "$1" in
    -v)
        echo "spxc-core: $VERSION"
        if command -v spxc-web &> /dev/null; then
            echo "spxc-webtools: $(spxc-web -v)"
        fi
        ;;
    -crdts)
        echo "Creator: Spaceship"
        echo "Discord: https://discord.gg/uCDMuqfSeX"
        ;;
    -gpass)
        LENGTH=$2
        SPECIAL=$3
        NUMBERS=$4
        if [ -z "$LENGTH" ] || [ -z "$SPECIAL" ] || [ -z "$NUMBERS" ]; then
            echo "Usage: spxc -gpass [length] [special (yes/no)] [numbers (yes/no)]"
            exit 1
        fi
        CHARSET="a-zA-Z"
        [ "$SPECIAL" == "yes" ] && CHARSET="${CHARSET}!\@#\$%\^&\*\(\)_\+-\=\[\]\{\}\|;:,.<>\?"
        [ "$NUMBERS" == "yes" ] && CHARSET="${CHARSET}0-9"
        cat /dev/urandom | tr -dc "$CHARSET" | fold -w "$LENGTH" | head -n 1
        echo
        ;;
    -bckup)
        TARGET=$2
        if [ -z "$TARGET" ]; then echo "Usage: spxc -bckup [directory]"; exit 1; fi
        if [ -f "$TARGET/spxc" ] || [ -f "$TARGET/spxc-web" ]; then
            read -p "Existing spxc backup detected in $TARGET. Overwrite? (y/N): " choice
            [[ "$choice" != [Yy]* ]] && echo "Operation cancelled." && exit 1
        fi
        mkdir -p "$TARGET"
        cp /usr/bin/spxc "$TARGET"/
        [ -f /usr/bin/spxc-web ] && cp /usr/bin/spxc-web "$TARGET"/
        echo "Backup created in $TARGET."
        ;;
    -rvbckup)
        SOURCE=$2
        if [ -z "$SOURCE" ]; then echo "Usage: spxc -rvbckup [directory]"; exit 1; fi
        if [ ! -d "$SOURCE" ]; then echo "Backup directory not found."; exit 1; fi
        read -p "This will overwrite your system binaries. Are you sure? (y/N): " choice
        [[ "$choice" != [Yy]* ]] && echo "Operation cancelled." && exit 1
        sudo cp "$SOURCE"/spxc /usr/bin/
        [ -f "$SOURCE"/spxc-web ] && sudo cp "$SOURCE"/spxc-web /usr/bin/
        echo "Backup restored."
        ;;
    -pcheck)
        PORT=$2
        if [ -z "$PORT" ]; then echo "Usage: spxc -pcheck [port]"; exit 1; fi
        PID=$(lsof -t -i:"$PORT")
        if [ -z "$PID" ]; then
            echo "No process is using port $PORT."
        else
            PROC_NAME=$(ps -p "$PID" -o comm=)
            echo "Port $PORT is being used by: $PROC_NAME (PID: $PID)"
            read -p "Do you want to kill this process? (y/N): " choice
            case "$choice" in
                y|Y ) kill -9 "$PID" && echo "Process $PID killed." ;;
                * ) echo "Operation cancelled." ;;
            esac
        fi
        ;;
    -sysfo)
        echo "--- System Information ---"
        echo "CPU: $(lscpu | grep 'Model name' | cut -d ':' -f 2 | sed 's/^[ \t]*//')"
        echo "GPU: $(lspci | grep -i vga | cut -d ':' -f 3 | sed 's/^[ \t]*//')"
        echo "RAM: $(free -h | awk '/^Mem:/ {print $3 "/" $2}')"
        echo "IP (Local): $(ip route get 1.2.3.4 | awk '{print $7}')"
        echo "IP (Public): $(curl -s https://ifconfig.me || echo 'N/A')"
        echo "Timezone: $(timedatectl show --property=Timezone --value)"
        echo "Keyboard: $(localectl status | grep 'X11 Layout' | cut -d ':' -f 2 | sed 's/^[ \t]*//')"
        
        if [ -d /sys/class/power_supply/BAT0 ]; then
            capacity=$(cat /sys/class/power_supply/BAT0/capacity)
            status=$(cat /sys/class/power_supply/BAT0/status)
            echo "Battery: $capacity% ($status)"
        else
            echo "Battery: N/A"
        fi
        echo "--------------------------"
        ;;
    -caupd)
        echo "This will clear your entire yay cache and perform a clean update of the spxc suite."
        read -p "Are you sure you want to proceed? (y/N): " choice
        case "$choice" in
            y|Y )
                echo "Clearing yay cache..."
                yay -Scc --noconfirm
                
                PACKAGES="spxc-core"
                if pacman -Qi spxc-webtools &> /dev/null; then
                    PACKAGES="$PACKAGES spxc-webtools"
                    echo "Performing clean update for spxc-core and spxc-webtools..."
                else
                    echo "Performing clean update for spxc-core..."
                fi
                
                yay -S $PACKAGES --answerclean All --answerdiff None --noconfirm
                ;;
            * )
                echo "Operation cancelled."
                ;;
        esac
        ;;
    -mkserv|-rmweb|-dweb)
        if command -v spxc-web &> /dev/null; then
            spxc-web "$@"
        else
            echo "Web tools are not installed."
            echo "Please install 'spxc-webtools' to use this command."
        fi
        ;;
    --help)
        echo "Available commands (Core):"
        echo "  -v                             Show version"
        echo "  -sysfo                         Show detailed system information"
        echo "  -pcheck [port]                 Check for processes on port and optional kill"
        echo "  -crdts                         Show creator credits"
        echo "  -gpass [len] [spec] [num]      Generate a password (e.g., -gpass 16 yes yes)"
        echo "  -bckup [directory]             Backup spxc suite to a directory"
        echo "  -rvbckup [directory]           Restore spxc suite from a directory"
        echo "  -caupd                         Clear yay cache and update spxc-core (and spxc-webtools if installed)"
        echo ""
        echo "Available commands (Requires spxc-webtools):"
        echo "  -mkserv [directory] [port]     Create and start a Python server"
        echo "  -rmweb [directory]             Remove all HTML files in a directory"
        echo "  -dweb [directory] [URL] [name] Download and bundle a full site into 1 HTML file"
        ;;
    *)
        echo "Usage: spxc --help"
        exit 1
        ;;
esac