Add OfflineSourceFolder parameter for offline installation
This pull-requests implements an offline installation for Scoop. I documented the usage in the updated README.
- Pre-download the following files into a folder of your choice
https://github.com/ScoopInstaller/Scoop/archive/master.zip as ScoopInstaller-Scoop.zip
https://github.com/ScoopInstaller/Main/archive/master.zip as ScoopInstaller-Main.zip
- Later, run
# From a local folder
.\install.ps1 -OfflineSourceFolder 'C:\Local\Path\To\Zip\Files'
# From a network path
.\install.ps1 -OfflineSourceFolder '\\UNC\Path\To\Zip\Files'
The files are not deleted, which means they can be re-used for other installations. This should address https://github.com/ScoopInstaller/Scoop/issues/3505.
I have a few suggestions that might improve the usability of the offline installation feature:
-
Would it be possible to use the default filenames (e.g.,
Scoop-master.zip,Main-master.zip) instead of requiring users to rename the downloaded zip files? -
Could we consider specifying the zip files directly as parameters rather than requiring a folder path? For example, something like:
.\install.ps1 -OfflineScoopFile 'C:\Path\To\Scoop-master.zip' -OfflineMainBucketFile 'C:\Path\To\Main-master.zip' -
It would be great if we could support multiple bucket zip files during installation, rather than limiting it to only the main bucket. This would provide more flexibility for users to include other buckets in the offline setup.
Thanks for the suggestions.
-
My thinking was to rename the download to
{GithubOrg}-{GithubRepo}.zipfor clarity, and removing-masterin case people are actually downloading another branch. But I'm not opposed to using the default names. -
Your suggestion is what I started coding initially. Unfortunately the edge cases were awkward to handle, e.g. if someone specifies 1 ZIP file but not the other. Ideally, for each repo (scoop, main...) we would want to try 1) Offline ZIP 2) Git 3) HTTP. However the current logic is not written this way: it tries Git for all downloads, then HTTP for all downloads, etc. Specifying a single "folder" argument minimised the code changes.
-
It's a good idea. I think it's linked to the question above about refactoring the code. Maybe it can be added as a later improvement?
I'm happy to make some changes; I will let the maintainers decide which way they want to go to hopefully merge this PR.
Thank you for contributing this code! I downloaded your changes and created a batch file to help me quickly set up my development environment on a new system since I'm not very familiar with PowerShell. Because I'm in a region where downloading files from GitHub is very slow and often fails, the offline installation is essential for me, and I plan to switch to online buckets to get updates when the network conditions are better.
I structured my setup as follows:
install.bat
data
β install.ps1
β RefreshEnv.cmd
β ScoopInstaller-Main.zip
β ScoopInstaller-Scoop.zip
β
ββbuckets
β ββjava
β β ββbucket
β β oraclejdk.json
β β ...
β β
β ββ...
β ββbucket
β ...
β
ββcache
7zip#24.08#71f2568.msi
aria2#1.37.0-1#b261731.zip
gsudo#2.5.1#4648498.zip
oraclejdk#23#ff44867.zip
python#3.13.0#e275375.exe
...
The RefreshEnv.cmd file is used to refresh the environment variables without closing the command prompt. I only kept the necessary JSON files in each bucket since copying many small files is slow.
Here's a summary of my batch file:
powershell -Command Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
powershell -NoProfile -File .\data\install.ps1 -OfflineSourceFolder .\data
call .\data\RefreshEnv.cmd
powershell -NoProfile -Command scoop config aria2-warning-enabled false
xcopy /E /Q /H /Y .\data\buckets %USERPROFILE%\scoop\buckets\
set SCOOP_CACHE=.\data\cache
powershell -NoProfile -Command scoop install --no-update-scoop 7zip git aria2 gsudo oraclejdk python ...
set SCOOP_CACHE=
call .\data\RefreshEnv.cmd
gsudo cache on
gsudo regedit /s %USERPROFILE%\scoop\apps\7zip\current\install-context.reg
gsudo regedit /s %USERPROFILE%\scoop\apps\git\current\install-context.reg
...
gsudo cache off
When the network conditions improve, I can convert the buckets to Git repositories using the following commands to enable updates with scoop update:
git -C %USERPROFILE%\scoop\buckets\main init
git -C %USERPROFILE%\scoop\buckets\main remote add origin https://github.com/ScoopInstaller/Main
git -C %USERPROFILE%\scoop\buckets\main fetch origin master
git -C %USERPROFILE%\scoop\buckets\main checkout -f master
git -C %USERPROFILE%\scoop\buckets\java init
git -C %USERPROFILE%\scoop\buckets\java remote add origin https://github.com/ScoopInstaller/Java
git -C %USERPROFILE%\scoop\buckets\java fetch origin master
git -C %USERPROFILE%\scoop\buckets\java checkout -f master
...
Overall, thank you for your work on this! I hope your PR gets reviewed and merged successfully. Since my English is not very strong, I used ChatGPT to help convey my thoughts here. Please feel free to correct me if I've made any mistakes, and I appreciate your guidance!