Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OfflineSourceFolder parameter for offline installation #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rprieto
Copy link

@rprieto rprieto commented Sep 3, 2024

This pull-requests implements an offline installation for Scoop.
I documented the usage in the updated README.

  1. 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

  1. 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 ScoopInstaller/Scoop#3505.

@caipeter888
Copy link

caipeter888 commented Oct 8, 2024

I have a few suggestions that might improve the usability of the offline installation feature:

  1. 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?

  2. 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'
  3. 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.

@rprieto
Copy link
Author

rprieto commented Oct 8, 2024

Thanks for the suggestions.

  1. My thinking was to rename the download to {GithubOrg}-{GithubRepo}.zip for clarity, and removing -master in case people are actually downloading another branch. But I'm not opposed to using the default names.

  2. 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.

  3. 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.

@caipeter888
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants