Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ function Get-RequestHeaders {
return $headers
}

function Test-ChineseInstallLanguage {
$preference = if (-not [string]::IsNullOrWhiteSpace($env:DOC7_LANG)) {
$env:DOC7_LANG
}
else {
[Globalization.CultureInfo]::CurrentUICulture.Name
}

return $preference -match '^zh(?:[-_]|$)'
}

$useChinese = Test-ChineseInstallLanguage

if ($env:OS -ne "Windows_NT") {
Stop-Install "this installer supports Windows only"
}
Expand Down Expand Up @@ -92,7 +105,12 @@ $extractDir = Join-Path $tempDir "extract"
try {
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null

Write-Host "Downloading doc7 $Version for Windows/$Architecture..."
if ($useChinese) {
Write-Host "正在下载 doc7 $Version(Windows/$Architecture)……"
}
else {
Write-Host "Downloading doc7 $Version for Windows/$Architecture..."
}
$archiveRequest = @{
Uri = "$releaseUrl/$assetName"
Headers = $headers
Expand Down Expand Up @@ -169,10 +187,23 @@ try {
}

$env:Path = "$normalizedInstallDir;$($env:Path)"
& (Join-Path $normalizedInstallDir "doc7.exe") version
Write-Host "Installed directory: $normalizedInstallDir"
Write-Host "Next: doc7 setup"
Write-Host "Then: doc7 <file>"
$installedExecutable = Join-Path $normalizedInstallDir "doc7.exe"
& $installedExecutable version | Out-Null

if ($useChinese) {
Write-Host "doc7 已安装:$installedExecutable"
Write-Host ""
Write-Host "安装完成。下面是 doc7 的使用说明:"
Write-Host ""
}
else {
Write-Host "Installed executable: $installedExecutable"
Write-Host ""
Write-Host "Installation complete. Here is how to use doc7:"
Write-Host ""
}

& $installedExecutable
}
finally {
if (Test-Path -LiteralPath $tempDir) {
Expand Down
47 changes: 41 additions & 6 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

set -euo pipefail

detect_install_language() {
local preference

preference="${DOC7_LANG:-}"
if [[ -z "${preference}" ]] && [[ "$(uname -s)" == "Darwin" ]] && command -v defaults >/dev/null 2>&1; then
preference="$(defaults read -g AppleLanguages 2>/dev/null | awk -F'"' 'NF >= 2 { print $2; exit }' || true)"
fi
if [[ -z "${preference}" ]]; then
preference="${LC_ALL:-${LC_MESSAGES:-${LANG:-}}}"
fi

case "${preference}" in
[zZ][hH] | [zZ][hH][-_]*) printf 'zh-CN\n' ;;
*) printf 'en\n' ;;
esac
}

INSTALL_LANGUAGE="$(detect_install_language)"

fail() {
printf 'doc7 installer: %s\n' "$*" >&2
exit 1
Expand Down Expand Up @@ -114,7 +133,11 @@ cleanup() {
}
trap cleanup EXIT

printf 'Downloading doc7 %s for %s/%s...\n' "${VERSION}" "${OS}" "${ARCH}"
if [[ "${INSTALL_LANGUAGE}" == "zh-CN" ]]; then
printf '正在下载 doc7 %s(%s/%s)……\n' "${VERSION}" "${OS}" "${ARCH}"
else
printf 'Downloading doc7 %s for %s/%s...\n' "${VERSION}" "${OS}" "${ARCH}"
fi
curl --fail --silent --show-error --location \
--output "${ARCHIVE_PATH}" "${RELEASE_URL}/${ASSET_NAME}"
curl --fail --silent --show-error --location \
Expand All @@ -138,16 +161,28 @@ if [[ -f "${README_PATH}" ]]; then
install -m 0644 "${README_PATH}" "${SHARE_DIR}/README.txt"
fi

"${INSTALL_DIR}/doc7" version
printf 'Installed executable: %s\n' "${INSTALL_DIR}/doc7"
"${INSTALL_DIR}/doc7" version >/dev/null
if [[ "${INSTALL_LANGUAGE}" == "zh-CN" ]]; then
printf 'doc7 已安装:%s\n' "${INSTALL_DIR}/doc7"
else
printf 'Installed executable: %s\n' "${INSTALL_DIR}/doc7"
fi

case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*)
printf 'Add this directory to PATH before opening a new shell:\n'
if [[ "${INSTALL_LANGUAGE}" == "zh-CN" ]]; then
printf '请把这个目录加入 PATH,然后重新打开终端:\n'
else
printf 'Add this directory to PATH before opening a new shell:\n'
fi
printf ' export PATH="%s:$PATH"\n' "${INSTALL_DIR}"
;;
esac

printf 'Next: doc7 setup\n'
printf 'Then: doc7 <file>\n'
if [[ "${INSTALL_LANGUAGE}" == "zh-CN" ]]; then
printf '\n安装完成。下面是 doc7 的使用说明:\n\n'
else
printf '\nInstallation complete. Here is how to use doc7:\n\n'
fi
"${INSTALL_DIR}/doc7"
Loading