3.3. 使用 curl 下载 ISO 镜像
使用 curl
工具,您可以使用命令行从 web 获取所需的文件,以保存在本地或者根据需要将其传送给另一个程序。这部分解释了如何使用 curl
命令下载安装镜像。
先决条件
curl
和jq
软件包已安装。如果您的 Linux 发行版没有使用
yum
或apt
,或者您没有使用 Linux,请从 curl 网站下载最合适的软件包。- 您有一个从 Red Hat API Tokens 产生的离线令牌。
- 您有一个要从 Product Downloads 下载的文件的校验和。
流程
使用以下内容创建一个 bash 文件:
#!/bin/bash # set the offline token and checksum parameters offline_token="<offline_token>" checksum=<checksum> # get an access token access_token=$(curl https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token -d grant_type=refresh_token -d client_id=rhsm-api -d refresh_token=$offline_token | jq -r '.access_token') # get the filename and download url image=$(curl -H "Authorization: Bearer $access_token" "https://api.access.redhat.com/management/v1/images/$checksum/download") filename=$(echo $image | jq -r .body.filename) url=$(echo $image | jq -r .body.href) # download the file curl $url -o $filename
在上面的文本中,将 <offline_token> 替换为从 Red Hat API 门户收集的令牌,并将 <checksum> 替换为 Product Downloads 页面中的 checksum 值。
使此文件可执行。
$ chmod u+x FILEPATH/FILENAME.sh
打开终端窗口并执行 bash 文件。
$ ./FILEPATH/FILENAME.sh
警告
使用与网络最佳实践一致的密码管理。
- 不要以纯文本形式存储密码或凭据。
- 防止令牌未经授权使用。
其他资源