File size: 6,827 Bytes
7344bef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
cd "$(dirname "$0")/.."

check_python() {
    command -v python3 >/dev/null 2>&1 && python3 -c "import sys; sys.exit(0 if sys.version_info >= (3,11) else 1)" >/dev/null 2>&1
}

install_python() {
    echo "[*] Attempting to install Python 3.11+ via system package manager..."
    
    if command -v apt-get >/dev/null 2>&1; then
        echo "[*] Detected Debian/Ubuntu based system."
        sudo apt-get update
        sudo apt-get install -y python3 python3-venv python3-pip
        return $?
    elif command -v dnf >/dev/null 2>&1; then
        echo "[*] Detected Fedora/RHEL based system."
        sudo dnf install -y python3 python3-pip
        return $?
    elif command -v pacman >/dev/null 2>&1; then
        echo "[*] Detected Arch based system."
        sudo pacman -Sy --noconfirm python python-pip
        return $?
    else
        echo "[-] Unsupported package manager. Please install Python 3.11+ manually."
        return 1
    fi
}

install_conda() {
    echo "[-] 'conda' not found."
    echo "[*] Downloading Miniconda3..."
    
    local DL_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh"
    local DL_FILE="miniconda_installer.sh"
    
    if command -v curl >/dev/null 2>&1; then
        curl -L -o "$DL_FILE" "$DL_URL"
    elif command -v wget >/dev/null 2>&1; then
        wget -O "$DL_FILE" "$DL_URL"
    else
        echo "[-] curl or wget is required to download Miniconda."
        return 1
    fi
    
    if [ ! -f "$DL_FILE" ]; then
        echo "[-] Download failed. Please install Miniconda manually."
        return 1
    fi
    
    echo "[*] Installing Miniconda silently (this may take a minute)..."
    bash "$DL_FILE" -b -p "$HOME/miniconda3"
    rm "$DL_FILE"
    
    echo "[*] Auto-accepting Conda Terms of Service and configuring..."
    "$HOME/miniconda3/bin/conda" config --set auto_activate_base false
    "$HOME/miniconda3/bin/conda" tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main >/dev/null 2>&1
    "$HOME/miniconda3/bin/conda" tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r >/dev/null 2>&1
    
    echo "[*] Miniconda installation complete!"
    echo "[*] Note: You may need to restart your terminal or run 'source $HOME/miniconda3/bin/activate' to use conda universally."
    return 0
}

if ! check_python; then
    echo "[!] Python 3.11+ is required but not found (or an older version was detected)."
    read -p "[?] Would you like to automatically install it via system package manager? (y/n): " inst_py
    if [[ "$inst_py" == "y" || "$inst_py" == "Y" ]]; then
        install_python
        
        if ! check_python; then
            echo "[-] Automated installation failed or Python 3.11+ is still not recognized."
            echo "[*] Please install Python 3.11+ manually."
            read -p "Press Enter to exit..."
            exit 1
        fi
    else
        echo "[-] Please install Python 3.11+ manually."
        read -p "Press Enter to exit..."
        exit 1
    fi
fi

clear
echo "=========================================================================================="
echo "                                  WAN2GP INSTALLER MENU                                   "
echo "=========================================================================================="
echo "1. Automatic Install (1-Click, Venv, Auto-Detect GPU)"
echo "2. Custom/Manual Install"
echo "3. Exit"
echo "------------------------------------------------------------------------------------------"
read -p "Select an option (1-3): " main_choice

main_choice=$(echo "$main_choice" | tr -d ' "')

if [ "$main_choice" == "1" ]; then
    ENV_TYPE="venv"
    AUTO_FLAG="--auto"
elif [ "$main_choice" == "2" ]; then
    AUTO_FLAG=""
    clear
    echo "=========================================================================================="
    echo "                                 SELECT ENVIRONMENT TYPE                                  "
    echo "=========================================================================================="
    echo "1. Use 'venv' (Easiest - Comes prepackaged with python)"
    echo "2. Use 'uv' (Recommended - Faster but requires installing uv)"
    echo "3. Use 'conda'"
    echo "4. No Environment (Not Recommended)"
    echo "5. Exit"
    echo "------------------------------------------------------------------------------------------"
    read -p "Select an option (1-5): " choice

    choice=$(echo "$choice" | tr -d ' "')

    if [ "$choice" == "1" ]; then
        ENV_TYPE="venv"
        
    elif [ "$choice" == "2" ]; then
        ENV_TYPE="uv"
        if ! command -v uv &> /dev/null; then
            echo "[-] 'uv' not found."
            read -p "[?] Would you like to install 'uv' now? (y/n): " inst_uv
            if [[ "$inst_uv" == "y" || "$inst_uv" == "Y" ]]; then
                echo "1. Install 'uv' via curl (Recommended)"
                echo "2. Install 'uv' via Pip"
                read -p "Select method: " uv_choice
                
                if [ "$uv_choice" == "1" ]; then
                    curl -LsSf https://astral.sh/uv/install.sh | sh
                    source "$HOME/.cargo/env" 2>/dev/null || true
                elif [ "$uv_choice" == "2" ]; then
                    python3 -m pip install uv
                fi
            else
                echo "[-] 'uv' is required for this option. Exiting."
                exit 1
            fi
        fi

    elif [ "$choice" == "3" ]; then
        ENV_TYPE="conda"
        CONDA_FOUND=0
        
        if command -v conda &> /dev/null; then CONDA_FOUND=1; fi
        if [ -f "$HOME/miniconda3/bin/conda" ]; then CONDA_FOUND=1; fi
        if [ -f "$HOME/anaconda3/bin/conda" ]; then CONDA_FOUND=1; fi

        if [ "$CONDA_FOUND" == "0" ]; then
            echo "[!] Conda is not installed."
            read -p "[?] Would you like to download and install Miniconda3? (y/n): " inst_conda
            if [[ "$inst_conda" == "y" || "$inst_conda" == "Y" ]]; then
                install_conda
                if [ $? -ne 0 ]; then
                    echo "[-] Miniconda installation failed or was aborted."
                    read -p "Press Enter to exit..."
                    exit 1
                fi
            else
                echo "[-] Cannot proceed without conda. Exiting."
                read -p "Press Enter to exit..."
                exit 1
            fi
        fi

    elif [ "$choice" == "4" ]; then
        ENV_TYPE="none"
        
    elif [ "$choice" == "5" ]; then
        exit 0
    else
        exit 0
    fi
elif [ "$main_choice" == "3" ]; then
    exit 0
else
    exit 0
fi

python3 setup.py install --env "$ENV_TYPE" $AUTO_FLAG
echo "Installation complete. Run ./run.sh to start."
read -p "Press Enter to exit..."