Upgraded install script for windows

This commit is contained in:
Saifeddine ALOUI 2023-04-11 10:24:12 +02:00
parent 85237770ad
commit abd8ed0d80
3 changed files with 98 additions and 53 deletions

View File

@ -75,79 +75,119 @@ exit /b 1
REM Check if Python is installed REM Check if Python is installed
set /p="Checking for python..." <nul set /p="Checking for python..." <nul
where python >nul 2>&1 where python >nul 2>&1
if %errorlevel% neq 0 ( if %ERRORLEVEL% EQU 0 (
goto PYTHON_CHECKED
) else (
goto PYTHON_INSTALL
)
:PYTHON_CHECKED
echo "Python is installed."
goto PYTHON_SKIP
:PYTHON_INSTALL
echo. echo.
set /p choice=Python is not installed. Would you like to install Python? [Y/N] choice /C YN /M "Do you want to download and install python?"
if /i ".choice." equ "Y" ( if errorlevel 2 goto PYTHON_CANCEL
if errorlevel 1 goto PYTHON_INSTALL_2
:PYTHON_INSTALL_2
REM Download Python installer REM Download Python installer
echo Downloading Python installer... echo Downloading Python installer...
powershell -Command "Invoke-WebRequest -Uri 'https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe' -OutFile 'tmp/python.exe'" powershell -Command "Invoke-WebRequest -Uri 'https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe' -OutFile 'tmp/python.exe'"
REM Install Python REM Install Python
echo Installing Python... echo Installing Python...
tmp/python.exe /quiet /norestart tmp/python.exe /quiet /norestart
) else (
echo Please install Python and try again. :PYTHON_CANCEL
echo Please install python and try again.
pause pause
exit /b 1 exit /b 1
)
) else ( :PYTHON_SKIP
echo OK
)
REM Check if pip is installed REM Check if pip is installed
set /p="Checking for pip..." <nul set /p="Checking for pip..." <nul
python -m pip >nul 2>&1 python -m pip >nul 2>&1
if %errorlevel% neq 0 ( if %ERRORLEVEL% EQU 0 (
goto PIP_CHECKED
) else (
goto PIP_INSTALL
)
:PIP_CHECKED
echo "Pip is installed."
goto PIP_SKIP
:PIP_INSTALL
echo. echo.
set /p choice=Pip is not installed. Would you like to install pip? [Y/N] choice /C YN /M "Do you want to download and install pip?"
if /i ".choice." equ "Y" ( if errorlevel 2 goto PIP_CANCEL
if errorlevel 1 goto PIP_INSTALL_2
:PIP_INSTALL_2
REM Download get-pip.py REM Download get-pip.py
echo Downloading get-pip.py... echo Downloading get-pip.py...
powershell -Command "Invoke-WebRequest -Uri 'https://bootstrap.pypa.io/get-pip.py' -OutFile 'tmp/get-pip.py'" powershell -Command "Invoke-WebRequest -Uri 'https://bootstrap.pypa.io/get-pip.py' -OutFile 'tmp/get-pip.py'"
REM Install pip REM Install pip
echo Installing pip... echo Installing pip...
python tmp/get-pip.py python tmp/get-pip.py
) else (
:PIP_CANCEL
echo Please install pip and try again. echo Please install pip and try again.
pause pause
exit /b 1 exit /b 1
)
) else (
echo OK
)
REM Check if venv module is available :PIP_SKIP
set /p="Checking for venv..." <nul
python -c "import venv" >nul 2>&1 REM Upgrading pip setuptools and wheel
if %errorlevel% neq 0 ( echo Updating pip setuptools and wheel
echo.
set /p choice=venv module is not available. Would you like to upgrade Python to the latest version? [Y/N]
if /i ".choice." equ "Y" (
REM Upgrade Python
echo Upgrading Python...
python -m pip install --upgrade pip setuptools wheel python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade --user python
REM Check if pip is installed
set /p="Checking for virtual environment..." <nul
python -c "import venv" >nul 2>&1
if %ERRORLEVEL% EQU 0 (
goto VENV_CHECKED
) else ( ) else (
echo Please upgrade your Python installation and try again. goto VENV_INSTALL
)
:VENV_CHECKED
echo "Virtual environment is installed."
goto VENV_SKIP
:VENV_INSTALL
echo.
choice /C YN /M "Do you want to download and install venv?"
if errorlevel 2 goto VENV_CANCEL
if errorlevel 1 goto VENV_INSTALL_2
:VENV_INSTALL_2
REM Installinv venv
echo installing venv...
pip install virtualenv
:VENV_CANCEL
echo Please install venv and try again.
pause pause
exit /b 1 exit /b 1
)
) else ( :VENV_SKIP
echo OK
)
REM Create a new virtual environment REM Create a new virtual environment
set /p="Creating virtual environment ..." <nul set /p="Creating virtual environment ..." <nul
python -m venv env python -m venv env >nul 2>&1
if %errorlevel% neq 0 ( if %ERRORLEVEL% EQU 0 (
goto VENV_CREATED
) else (
echo Failed to create virtual environment. Please check your Python installation and try again. echo Failed to create virtual environment. Please check your Python installation and try again.
pause pause
exit /b 1 exit /b 1
) else (
echo OK
) )
:VENV_CREATED
REM Activate the virtual environment REM Activate the virtual environment
set /p="Activating virtual environment ..." <nul set /p="Activating virtual environment ..." <nul
call env\Scripts\activate.bat call env\Scripts\activate.bat

View File

@ -185,6 +185,10 @@ function addMessage(sender, message, id, rank=0, can_edit=false) {
rank_up.innerText=`Up` rank_up.innerText=`Up`
rank_down.innerText=`Down(${data.new_rank})` rank_down.innerText=`Down(${data.new_rank})`
} }
else{
rank_up.innerText=`Up`
rank_down.innerText=`Down`
}
}) })
.catch(error => { .catch(error => {
console.error('There was a problem updating the message:', error); console.error('There was a problem updating the message:', error);

View File

@ -173,7 +173,8 @@ exportDiscussionButton.addEventListener('click', () => {
.then(data => { .then(data => {
const filename = window.prompt('Please enter a filename:', 'discussion.txt'); const filename = window.prompt('Please enter a filename:', 'discussion.txt');
if (filename !== null) { if (filename !== null) {
const blob = new Blob([data], { type: 'text/plain' }); const text = data.replace(/\n/g, "\r\n");
const blob = new Blob([text], { type: 'text/plain' });
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
const link = document.createElement('a'); const link = document.createElement('a');
link.href = url; link.href = url;