-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.bat
185 lines (152 loc) · 6.2 KB
/
install.bat
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
182
183
184
185
@echo off
SETLOCAL EnableDelayedExpansion
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params= %*
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
REM Port forward WSL2 to all interfaces
if "%1" == "start" (
wsl echo hostname -I ^> tempfile
FOR /F %%i IN ('wsl hostname -I') DO (
set WSL_IP=%%i
)
echo WSL IPs are !WSL_IP!
netsh interface portproxy set v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=!WSL_IP!
netsh interface portproxy set v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8080 connectaddress=!WSL_IP!
wsl cd /opt/cityfarm ^&^& docker compose up -d
exit
)
echo _/_/_/ _/ _/ _/_/_/_/
echo _/ _/_/_/_/ _/ _/ _/ _/_/_/ _/ _/_/ _/_/_/ _/_/
echo _/ _/ _/ _/ _/ _/_/_/ _/ _/ _/_/ _/ _/ _/
echo _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
echo _/_/_/ _/ _/_/ _/_/_/ _/ _/_/_/ _/ _/ _/ _/
echo _/
echo _/_/
echo =================================================================================
echo.
echo Hello, my name is C.H.I.P ^(CityFarm Helpful Installation Program^)! I'm here to help you install CityFarm on your computer :^)
echo.
for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set NetworkIP=%%a
:alreadyinstalled
reg query HKEY_LOCAL_MACHINE\SOFTWARE\CityFarm 2>nul 1>nul
if %ERRORLEVEL% EQU 0 (
echo I can see that CityFarm is already installed on this computer.
echo It is accessible at http://%NetworkIP%:3000
echo.
echo Please select an option by number below:
echo 1^) Uninstall CityFarm :^(
echo 2^) Backup CityFarm data
echo 3^) Load CityFarm data from backup
echo 4^) Exit
) else (
goto notinstalled
)
echo.
set /p "install=Enter your choice (1/2/3/4): "
if /i "%install%"=="1" (
echo Uninstalling CityFarm...
schtasks /delete /tn CityFarm /f
REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\CityFarm /f
wsl cd /opt/cityfarm ^&^& docker compose down
echo Done! I hope to see you again...
pause
exit
)
if /i "%install%"=="2" (
echo Backing up CityFarm data...
wsl cd /opt/cityfarm ^&^& docker compose down
wsl tar -czvf cityfarm-backup.tar.gz /opt/cityfarm/mongodb-data
echo Backup complete!
wsl mv cityfarm-backup.tar.gz /mnt/c/Users/%USERNAME%/Downloads
echo Backup saved to Downloads folder!
wsl cd /opt/cityfarm ^&^& docker compose up -d
pause
exit
)
if /i "%install%"=="3" (
echo Loading CityFarm data from backup...
wsl cd /opt/cityfarm && docker compose down -d
wsl mv /mnt/c/Users/%USERNAME%/Downloads/cityfarm-backup.tar.gz .
wsl mv /opt/cityfarm/mongodb-data /opt/cityfarm/mongodb-data-old
wsl tar -xzvf cityfarm-backup.tar.gz
wsl mv mongodb-data /opt/cityfarm/
echo Data loaded!
wsl cd /opt/cityfarm ^&^& docker compose up -d
pause
exit
)
if /i "%install%"=="4" (
echo "Goodbye!"
exit
)
:notinstalled
echo I can see you don't have CityFarm installed on this computer. Would you like me to install it for you?
set /p "install=Enter your choice (y/n): "
if /i "%install%"=="y" (
echo Great! Let's get started!
) else (
echo Too bad! I'll be here if you change your mind :^)
exit
)
echo Warning: tech jargon incoming!
echo Installing WSL2 (this may take a while)...
REM set wsl2 memory limit to 2GB
curl https://pastebin.com/raw/7fpiVnSs --output %USERPROFILE%\.wslconfig
wsl --install --no-launch | findstr /C:"installed" 1>nul
if %ERRORLEVEL% EQU 0 (
echo Installed WSL2 - ATTENTION - Please restart your computer and run this script again to continue the installation process.
pause
exit
) else (
echo WSL2 already installed.
)
ubuntu config --default-user root
echo Getting ready to install Docker...
wsl apt-get update -y
wsl apt-get install -y ca-certificates curl
wsl install -m 0755 -d /etc/apt/keyrings
wsl curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
wsl chmod a+r /etc/apt/keyrings/docker.asc
echo Adding Docker repository...
wsl echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" ^| tee /etc/apt/sources.list.d/docker.list
echo Updating package list...
wsl apt-get update -y
echo Installing Docker...
wsl apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
wsl service docker start
echo Creating CityFarm directory...
wsl mkdir -p /opt/cityfarm
wsl mkdir -p /opt/cityfarm/mongodb-data
echo Downloading Docker Compose file...
wsl curl https://pastebin.com/raw/E3UCcqjE --output /opt/cityfarm/docker-compose.yml
echo Starting Docker Compose...
wsl cd /opt/cityfarm/ ^&^& docker compose up -d
echo Creating scheduled task...
xcopy "%~f0" "%APPDATA%\CityFarm\cityfarm.bat" /Y
schtasks /create /tn CityFarm /sc ONSTART /DELAY 0000:30 /RL HIGHEST /tr "%APPDATA%\CityFarm\cityfarm.bat start" /ru SYSTEM
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\CityFarm /v Installed /t REG_SZ /d "true" /f
echo Done!
echo CityFarm is now accessible at http://%NetworkIP%:3000
start http://%NetworkIP%:3000
pause