使用 scoop 安装管理 windows 软件(2):github 加速

ref: (https://github.com/ScoopInstaller/Scoop)

1. 安装 scoop

1.1 安装 PowerShell 5.0 以上版本

1.2 以当前Win账户运行PowerShell

1
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

1.3 安装 scoop

1
2
irm get.scoop.sh | iex

1
2
3
4
5
6
7
8
cd ~
curl -o scoop_install.ps1 https://ghproxy.net/https://raw.githubusercontent.com/ScoopInstaller/install/master/install.ps1

# 修改 `scoop_install.ps1` 内容:
(Get-Content scoop_install.ps1).replace('https://github.com/ScoopInstaller/', 'https://ghproxy.net/https://github.com/ScoopInstaller/') | Set-Content scoop_install.ps1

# 安装
.\scoop_install.ps1

使用默认安装时经常卡住,是因为 https://get.scoop.sh 其实指向了 https://raw.githubusercontent.com/,因而导致安装失败。

对应的安装文件在这里: https://github.com/ScoopInstaller/Install/blob/master/install.ps1

1.4 可用的镜像源

2. 使用 github (mirror) 更新 Scoop、 bucket 库

1
2
3
4
5
6
7
scoop config SCOOP_REPO 'https://github.com/ScoopInstaller/Scoop'
scoop bucket add main
scoop bucket add extras
scoop bucket add versions
scoop bucket add portablesoft 'https://github.com/shenbo/portablesoft'

scoop bucket list
1
2
3
4
5
scoop config SCOOP_REPO 'https://ghproxy.net/https://github.com/ScoopInstaller/Scoop'
scoop bucket add main 'https://ghproxy.net/https://github.com/ScoopInstaller/Main'
scoop bucket add extras 'https://ghproxy.net/https://github.com/ScoopInstaller/Extras'
scoop bucket add versions 'https://ghproxy.net/https://github.com/ScoopInstaller/Versions'
scoop bucket add portablesoft 'https://ghproxy.net/https://github.com/shenbo/portablesoft'

3 安装常用软件

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
# main buckets
scoop install 7zip
scoop install git
scoop install aria2

scoop install concfg
scoop install psreadline
scoop install posh-git
scoop install oh-my-posh

scoop install ffmpeg

# extra buckets
scoop install everything
scoop install trafficmonitor
scoop install vscode
scoop install windows-terminal

scoop install fork
scoop install snipaste
scoop install handbrake
scoop install qbittorrent

scoop intsall speccy

scoop install vcredist2022

# portablesoft
scoop install goodsync_x
scoop install mas_x

# python
scoop install python39 # versions
# pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
scoop install pycharm # extra
scoop install cuda11.2
# ref: https://developer.nvidia.com/rdp/cudnn-archive

# nodejs
scoop install nodejs # main

# latex
scoop install miktex # main
scoop install texstudio # extra
scoop install mupdf

3. 修改 scoop 安装文件源码, 加速软件源文件从 github 上的下载

1
2
3
4
5
6
cd ~\scoop\apps\scoop\current\ | notepad lib\install.ps1

# line 245 左右,添加以下内容:
# $urlstxt_content += "$(handle_special_urls $url)`n"
$urlstxt_content += "$(handle_special_urls $url)`n".Replace("https://github.com", "https://hub.fastgit.xyz").Replace("https://raw.githubusercontent.com", "https://raw.fastgit.org")
$urlstxt_content += "$(handle_special_urls $url)`n".Replace("https://github.com", "https://ghproxy.net/https://github.com").Replace("https://raw.githubusercontent.com", "https://ghproxy.net/https://raw.githubusercontent.com")
1
2
3
4
5
6
7
8
9
$scoop_install_file = '~\scoop\apps\scoop\current\lib\install.ps1'
$old_install_cmd = '$urlstxt_content += "$(handle_special_urls $url)`n"'
$web_github = "https://github.com"
$web_mirror = "https://ghproxy.net/https://github.com"
$raw_github = "https://raw.githubusercontent.com"
$raw_mirror = "https://ghproxy.net/https://raw.githubusercontent.com"
$new_install_cmd = '{0}.Replace("{1}", "{2}").Replace("{3}", "{4}")' -f $old_install_cmd, $web_github, $web_mirror, $raw_github, $raw_mirror

(Get-Content $scoop_install_file).replace($old_install_cmd, $new_install_cmd) | Set-Content $scoop_install_file
1
2
cd ~\scoop\apps\scoop\current
git checkout .

PS. 快捷命令

  • 打开 powershell 配置文件:
1
code $PROFILE

PSS. 自定义一个命令

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
# https://shenbo.github.io/tags/powershell/
# https://shenbo.github.io/tags/scoop/
# https://gitee.com/scoop-bucket/

# Set-Location ~

chcp 65001

Set-PSReadLineOption -PredictionSource History

oh-my-posh init pwsh --config ~\scoop\persist\oh-my-posh\themes\yo.omp.yaml | Invoke-Expression

function scoop-source {
param (
[Parameter(Mandatory = $True, Position = 0)]
[String] $Name
)

$info = "USEAGE:`n scoop-source [github | mirror]`n"
Write-Output $info

if ($Name -eq 'github') {
scoop config SCOOP_REPO 'https://github.com/ScoopInstaller/Scoop'

cd ~\scoop\buckets\main | git remote set-url origin 'https://github.com/ScoopInstaller/Main'
cd ~\scoop\buckets\extras | git remote set-url origin 'https://github.com/ScoopInstaller/Extras'
cd ~\scoop\buckets\versions | git remote set-url origin 'https://github.com/ScoopInstaller/Versions'
cd ~\scoop\buckets\portablesoft | git remote set-url origin 'https://github.com/shenbo/portablesoft'
scoop bucket list

cd ~\scoop\apps\scoop\current | git checkout .
git diff
}

if ($Name -eq 'mirror') {
scoop config SCOOP_REPO 'https://gitee.com/scoop-bucket/Scoop'
cd ~\scoop\apps\scoop\current | git checkout . | git pull

$scoop_install_file = '~\scoop\apps\scoop\current\lib\install.ps1'
$old_install_cmd = '$urlstxt_content += "$(handle_special_urls $url)`n"'
$web_github = "https://github.com"
$web_mirror = "https://ghproxy.net/https://github.com"
$raw_github = "https://raw.githubusercontent.com"
$raw_mirror = "https://ghproxy.net/https://raw.githubusercontent.com"
$new_install_cmd = '{0}.Replace("{1}", "{2}").Replace("{3}", "{4}")' -f $old_install_cmd, $web_github, $web_mirror, $raw_github, $raw_mirror

(Get-Content $scoop_install_file).replace($old_install_cmd, $new_install_cmd) | Set-Content $scoop_install_file
git diff --pretty=oneline

cd ~\scoop\buckets\main | git remote set-url origin 'https://ghproxy.net/https://github.com/ScoopInstaller/Main'
cd ~\scoop\buckets\extras | git remote set-url origin 'https://ghproxy.net/https://github.com/ScoopInstaller/Extras'
cd ~\scoop\buckets\versions | git remote set-url origin 'https://ghproxy.net/https://github.com/ScoopInstaller/Versions'
cd ~\scoop\buckets\portablesoft | git remote set-url origin 'https://ghproxy.net/https://github.com/shenbo/portablesoft'
cd ~
scoop bucket list
}

}