diff --git a/Makefile b/Makefile index da3bb0a..3412762 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION ?= 0.4.1 +VERSION ?= 0.4.2 DESTDIR ?= PREFIX ?= /usr/local MIRRORURL ?= https://xmirror.voidlinux.org/raw/mirrors.lst diff --git a/usr/share/locale/pt_BR/LC_MESSAGES/xmirror.mo b/usr/share/locale/pt_BR/LC_MESSAGES/xmirror.mo new file mode 100644 index 0000000..f97e88e Binary files /dev/null and b/usr/share/locale/pt_BR/LC_MESSAGES/xmirror.mo differ diff --git a/usr/share/locale/pt_BR/LC_MESSAGES/xmirror.po b/usr/share/locale/pt_BR/LC_MESSAGES/xmirror.po new file mode 100644 index 0000000..16d0ab3 --- /dev/null +++ b/usr/share/locale/pt_BR/LC_MESSAGES/xmirror.po @@ -0,0 +1,273 @@ +# Portuguese translations for xmirror package. +# Copyright (C) 2025 THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the xmirror package. +# Automatically generated, 2025. +# +msgid "" +msgstr "" +"Project-Id-Version: xmirror 0.4.2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-09-04 16:29-0300\n" +"PO-Revision-Date: 2025-09-04 16:29-0300\n" +"Last-Translator: Fernando Souza\n" +"Language-Team: Portuguese \n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#: xmirror.in:48 +msgid "Interactive script for changing XBPS mirrors" +msgstr "Script interativo para alterar espelhos XBPS" + +#: xmirror.in:50 +msgid "" +"Reset the current mirror to the default, skipping the\n" +" interactive TUI." +msgstr "" +"Redefine o espelho atual para o padrão, ignorando a\n" +" TUI interativa." + +#: xmirror.in:52 +msgid "Show this help and exit." +msgstr "Mostrar esta ajuda e sair." + +#: xmirror.in:53 +msgid "" +"Use an alternative mirror list file. This should be a\n" +" tab-separated value file with the columns: region, url,\n" +" location, tier. Default: /usr/share/xmirror/mirrors.lst" +msgstr "" +"Use um arquivo de lista de espelhos alternativo. Este deve ser um\n" +" arquivo de valores separados por tabulação com as colunas: região, url,\n" +" localização, nível. Padrão: /usr/share/xmirror/mirrors.lst" + +#: xmirror.in:56 +msgid "Don't attempt to update the mirror list." +msgstr "Não tente atualizar a lista de espelhos." + +#: xmirror.in:57 +msgid "Use an alternative rootdir. Acts like xbps's -r flag." +msgstr "Use um diretório raiz alternativo. Atua como a flag -r do xbps." + +#: xmirror.in:58 +msgid "" +"Set the current mirror to mirrorurl and exit, skipping\n" +" the interactive TUI." +msgstr "" +"Defina o espelho atual como mirrorurl e saia, pulando\n" +" a interface gráfica interativa." + +#: xmirror.in:60 +msgid "Show the version and exit." +msgstr "Mostre a versão e saia." + +#: xmirror.in:62 +msgid "Copyright (c) 2023 classabbyamp, released under the BSD-2-Clause license" +msgstr "Copyright (c) 2023 classabbyamp, lançado sob a licença BSD-2-Clause" + +#: xmirror.in:72 +msgid "xmirror v%s" +msgstr "xmirror v%s" + +#: xmirror.in:90 +msgid "" +"For the best experience, choose a mirror geographically close to you, or use the Fastly Global CDN (listed in %sWorld%s). To use the default mirror (%srepo-default.voidlinux.org%s), which can point to any Tier 1 mirror, Select %s%sDefault%s.\n" +"\n" +"Tier 1 mirrors are maintained by the Void Linux Infrastructure Team and will always have the latest packages available. Tier 2 mirrors are not managed by Void and do not have any guarantees of freshness or completeness of packages, nor are they required to sync every available architecture or sub-repository." + +msgstr "" +"Para a melhor experiência, escolha um espelho geograficamente próximo a você ou use o Fastly Global CDN (listado em %sWorld%s). Para usar o espelho padrão (%srepo-default.voidlinux.org%s), que pode apontar para qualquer espelho de Nível 1, selecione %s%sDefault%s.\n" +"\n" +"Os espelhos de Nível 1 são mantidos pela Equipe de Infraestrutura do Void Linux e sempre terão os pacotes mais recentes disponíveis. Os espelhos de Nível 2 não são gerenciados pelo Void e não oferecem nenhuma garantia de atualização ou integridade dos pacotes, nem são obrigados a sincronizar todas as arquiteturas ou sub-repositórios disponíveis." + + +#: xmirror.in:102 +msgid "Use UP and DOWN keys to navigate menus. Use TAB to switch between buttons and ENTER to select." +msgstr "Use as teclas PARA CIMA e PARA BAIXO para navegar pelos menus. Use TAB para alternar entre os botões e ENTER para selecionar." + +#: xmirror.in:113 +msgid "Void Linux Mirror Selector -- https://www.voidlinux.org (v%s)" +msgstr "Seletor de espelho do Void Linux -- https://www.voidlinux.org (v%s)" + +#: xmirror.in:114 +msgid "Back" +msgstr "Voltar" + +#: xmirror.in:142 +msgid "could not find %s" +msgstr "não foi possível encontrar %s" + +#: xmirror.in:170 +msgid "xmirror: could not find xbps-%s or xbps-%s.static" +msgstr "xmirror: não foi possível encontrar xbps-%s ou xbps-%s.static" + +#: xmirror.in:182 +msgid "must be run as root" +msgstr "deve ser executado como root" + +#: xmirror.in:195 +msgid "Africa" +msgstr "África" + +#: xmirror.in:196 +msgid "Antarctica" +msgstr "Antártica" + +#: xmirror.in:197 +msgid "Asia" +msgstr "Ásia" + +#: xmirror.in:198 +msgid "Europe" +msgstr "Europa" + +#: xmirror.in:199 +msgid "North America" +msgstr "América do Norte" + +#: xmirror.in:200 +msgid "Oceania" +msgstr "Oceania" + +#: xmirror.in:201 +msgid "South and Central America" +msgstr "América do Sul e Central" + +#: xmirror.in:202 +msgid "Globally Available" +msgstr "Disponível globalmente" + +#: xmirror.in:214 +msgid "updating mirrorlist in %s/usr/share/xmirror" +msgstr "Atualizando a lista de espelhos em %s/usr/share/xmirror" + +#: xmirror.in:218 +msgid "unable to fetch new mirror list" +msgstr "não foi possível buscar a nova lista de espelhos" + +#: xmirror.in:242 xmirror.in:365 +msgid "Default" +msgstr "Padrão" + +#: xmirror.in:242 +msgid "Reset to the default mirror" +msgstr "Redefinir para o espelho padrão" + +#: xmirror.in:244 xmirror.in:364 +msgid "Exit" +msgstr "Sair" + +#: xmirror.in:244 +msgid "Exit this wizard" +msgstr "Sair deste assistente" + +#: xmirror.in:255 +msgid "" +"%sThe following operations will be executed:%s\\n\\n\n" +"The current mirror will be switched to: %s%s%s\n" +"The following files in %s%s/etc/xbps.d%s will be created or overwritten, if they exist:\n" +"%s%s%s\\n\\n\n" +"%sDo you want to continue?%s" + +msgstr "" +"%sAs seguintes operações serão executadas:%s\\n\\n\n" +"O espelho atual será alternado para: %s%s%s\n" +"Os seguintes arquivos em %s%s/etc/xbps.d%s serão criados ou substituídos, se existirem:\n" +"%s%s%s\\n\\n\n" +"%sDeseja continuar?%s" + + +#: xmirror.in:264 +msgid "Mirror successfully changed to %s!" +msgstr "Espelho alterado com sucesso para %s!" + +#: xmirror.in:274 +msgid "Mirror update failed! See log above for details." +msgstr "Falha na atualização do espelho! Consulte o log acima para obter detalhes." + +#: xmirror.in:278 +msgid "Updating mirror..." +msgstr "Atualizando o espelho..." + +#: xmirror.in:291 +msgid "warning: mirror protocol not specified, assuming http://" +msgstr "aviso: protocolo de espelho não especificado, assumindo http://" + +#: xmirror.in:313 +msgid "" +"%sThe following operations will be executed:%s\\n\\n\n" +"The current mirror will be reset to the default.\n" +"The following files in %s%s/etc/xbps.d%s will be removed, if they exist:\n" +"%s%s%s\\n\\n\n" +"%sDo you want to continue?%s" + +msgstr "" +"%sAs seguintes operações serão executadas:%s\\n\\n\n" +"O espelho atual será redefinido para o padrão.\n" +"Os seguintes arquivos em %s%s/etc/xbps.d%s serão removidos, se existirem:\n" +"%s%s%s\\n\\n\n" +"%sDeseja continuar?%s" + +#: xmirror.in:322 +msgid "Mirror successfully reset!" +msgstr "Espelho redefinido com sucesso!" + +#: xmirror.in:326 +msgid "Mirror reset failed! See log above for details." +msgstr "Falha na redefinição do espelho! Veja o log acima para mais detalhes." + +#: xmirror.in:330 +msgid "Resetting mirror to default..." +msgstr "Redefinindo o espelho para o padrão..." + +#: xmirror.in:357 +msgid "Choose a Region" +msgstr "Escolha uma região" + +#: xmirror.in:384 +msgid "Tier" +msgstr "Nível" + +#: xmirror.in:392 +msgid "Choose a Mirror (Region: %s)" +msgstr "Escolha um espelho (região: %s)" + +#: xmirror.in:446 +msgid "updating mirror to %s..." +msgstr "atualizando o espelho para %s..." + +#: xmirror.in:450 +msgid "mirror successfully updated to %s." +msgstr "espelho atualizado com sucesso para %s." + +#: xmirror.in:462 +msgid "mirror update failed." +msgstr "falha na atualização do espelho." + +#: xmirror.in:474 +msgid "xmirror: resetting mirror..." +msgstr "xmirror: redefinindo o espelho..." + +#: xmirror.in:480 +msgid "xmirror: mirror successfully reset." +msgstr "xmirror: espelho redefinido com sucesso." + +#: xmirror.in:486 +msgid "xmirror: mirror reset failed." +msgstr "xmirror: falha na redefinição do espelho." + +#: xmirror.in:506 +msgid "Void Linux Mirror Selection Wizard" +msgstr "Assistente de seleção de espelho do Void Linux" + + +msgid "Yes" +msgstr "Sim" + +msgid "No" +msgstr "Não" + + + diff --git a/usr/share/locale/pt_BR/LC_MESSAGES/xmirror.pot b/usr/share/locale/pt_BR/LC_MESSAGES/xmirror.pot new file mode 100644 index 0000000..c423036 --- /dev/null +++ b/usr/share/locale/pt_BR/LC_MESSAGES/xmirror.pot @@ -0,0 +1,260 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: xmirror 0.4.2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-09-04 16:29-0300\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: xmirror.in:48 +msgid "Interactive script for changing XBPS mirrors" +msgstr "" + +#: xmirror.in:50 +msgid "" +"Reset the current mirror to the default, skipping the\n" +" interactive TUI." +msgstr "" + +#: xmirror.in:52 +msgid "Show this help and exit." +msgstr "" + +#: xmirror.in:53 +msgid "" +"Use an alternative mirror list file. This should be a\n" +" tab-separated value file with the columns: region, " +"url,\n" +" location, tier. Default: /usr/share/xmirror/mirrors." +"lst" +msgstr "" + +#: xmirror.in:56 +msgid "Don't attempt to update the mirror list." +msgstr "" + +#: xmirror.in:57 +msgid "Use an alternative rootdir. Acts like xbps's -r flag." +msgstr "" + +#: xmirror.in:58 +msgid "" +"Set the current mirror to mirrorurl and exit, skipping\n" +" the interactive TUI." +msgstr "" + +#: xmirror.in:60 +msgid "Show the version and exit." +msgstr "" + +#: xmirror.in:62 +msgid "" +"Copyright (c) 2023 classabbyamp, released under the BSD-2-Clause license" +msgstr "" + +#: xmirror.in:72 +msgid "xmirror v%s" +msgstr "" + +#: xmirror.in:90 +msgid "" +"For the best experience, choose a mirror geographically close to you, or use " +"the Fastly Global CDN (listed in %sWorld%s). To use the default mirror " +"(%srepo-default.voidlinux.org%s), which can point to any Tier 1 mirror, " +"Select %s%sDefault%s.\n" +"\n" +"Tier 1 mirrors are maintained by the Void Linux Infrastructure Team and will " +"always have the latest packages available. Tier 2 mirrors are not managed by " +"Void and do not have any guarantees of freshness or completeness of " +"packages, nor are they required to sync every available architecture or sub-" +"repository." +msgstr "" + +#: xmirror.in:102 +msgid "" +"Use UP and DOWN keys to navigate menus. Use TAB to switch between buttons " +"and ENTER to select." +msgstr "" + +#: xmirror.in:113 +msgid "Void Linux Mirror Selector -- https://www.voidlinux.org (v%s)" +msgstr "" + +#: xmirror.in:114 +msgid "Back" +msgstr "" + +#: xmirror.in:142 +msgid "could not find %s" +msgstr "" + +#: xmirror.in:170 +msgid "xmirror: could not find xbps-%s or xbps-%s.static" +msgstr "" + +#: xmirror.in:182 +msgid "must be run as root" +msgstr "" + +#: xmirror.in:195 +msgid "Africa" +msgstr "" + +#: xmirror.in:196 +msgid "Antarctica" +msgstr "" + +#: xmirror.in:197 +msgid "Asia" +msgstr "" + +#: xmirror.in:198 +msgid "Europe" +msgstr "" + +#: xmirror.in:199 +msgid "North America" +msgstr "" + +#: xmirror.in:200 +msgid "Oceania" +msgstr "" + +#: xmirror.in:201 +msgid "South and Central America" +msgstr "" + +#: xmirror.in:202 +msgid "Globally Available" +msgstr "" + +#: xmirror.in:214 +msgid "updating mirrorlist in %s/usr/share/xmirror" +msgstr "" + +#: xmirror.in:218 +msgid "unable to fetch new mirror list" +msgstr "" + +#: xmirror.in:242 xmirror.in:365 +msgid "Default" +msgstr "" + +#: xmirror.in:242 +msgid "Reset to the default mirror" +msgstr "" + +#: xmirror.in:244 xmirror.in:364 +msgid "Exit" +msgstr "" + +#: xmirror.in:244 +msgid "Exit this wizard" +msgstr "" + +#: xmirror.in:255 +msgid "" +"%sThe following operations will be executed:%s\\n\\n\n" +"The current mirror will be switched to: %s%s%s\n" +"The following files in %s%s/etc/xbps.d%s will be created or overwritten, if " +"they exist:\n" +"%s%s%s\\n\\n\n" +"%sDo you want to continue?%s" +msgstr "" + +#: xmirror.in:264 +msgid "Mirror successfully changed to %s!" +msgstr "" + +#: xmirror.in:274 +msgid "Mirror update failed! See log above for details." +msgstr "" + +#: xmirror.in:278 +msgid "Updating mirror..." +msgstr "" + +#: xmirror.in:291 +msgid "warning: mirror protocol not specified, assuming http://" +msgstr "" + +#: xmirror.in:313 +msgid "" +"%sThe following operations will be executed:%s\\n\\n\n" +"The current mirror will be reset to the default.\n" +"The following files in %s%s/etc/xbps.d%s will be removed, if they exist:\n" +"%s%s%s\\n\\n\n" +"%sDo you want to continue?%s" +msgstr "" + +#: xmirror.in:322 +msgid "Mirror successfully reset!" +msgstr "" + +#: xmirror.in:326 +msgid "Mirror reset failed! See log above for details." +msgstr "" + +#: xmirror.in:330 +msgid "Resetting mirror to default..." +msgstr "" + +#: xmirror.in:357 +msgid "Choose a Region" +msgstr "" + +#: xmirror.in:384 +msgid "Tier" +msgstr "" + +#: xmirror.in:392 +msgid "Choose a Mirror (Region: %s)" +msgstr "" + +#: xmirror.in:446 +msgid "updating mirror to %s..." +msgstr "" + +#: xmirror.in:450 +msgid "mirror successfully updated to %s." +msgstr "" + +#: xmirror.in:462 +msgid "mirror update failed." +msgstr "" + +#: xmirror.in:474 +msgid "xmirror: resetting mirror..." +msgstr "" + +#: xmirror.in:480 +msgid "xmirror: mirror successfully reset." +msgstr "" + +#: xmirror.in:486 +msgid "xmirror: mirror reset failed." +msgstr "" + +#: xmirror.in:506 +msgid "Void Linux Mirror Selection Wizard" +msgstr "" + + +msgid "Yes" +msgstr "" + +msgid "No" +msgstr "" + + diff --git a/usr/share/man/pt_BR/man1/xmirror.1 b/usr/share/man/pt_BR/man1/xmirror.1 new file mode 100644 index 0000000..ccdd0d2 --- /dev/null +++ b/usr/share/man/pt_BR/man1/xmirror.1 @@ -0,0 +1,97 @@ +\"Tradução feita por Fernando Souza - Setembro 2025 +\"Baseada na versão original de xmirror.1 +\"Repositório: https://github.com/void-linux/xmirror +\"======================================================================================= +.Dd 30 de janeiro de 2023 +.Dt XMIRROR 1 +.Os +.Sh NOME +.Nm xmirror +.Nd Script interativo para alterar espelhos XBPS +.Sh SINOPSE +.Nm xmirror +.Op OPÇÕES... +.Sh DESCRIÇÃO +O utilitário +.Nm +configura e redefine o servidor espelho utilizado pelo XBPS. Ele +pode ser usado com e sem a interface gráfica interativa (TUI). O +.Nm +requer permissões de root para ser executado. +.Sh OPÇÕES +.Ss Comum +.Bl -tag -width -x +.It Fl h , Fl -help +Mostrar ajuda e sair. +.It Fl r , Fl -rootdir Ar rootdir +Use um diretório raiz alternativo +.Ar rootdir . +Funciona de forma semelhante à opção +.Fl r +do XBPS. +.It Fl v , Fl -version +Mostrar a versão e sair. +.El +.Ss Interativo +Estas opções só funcionam ao utilizar a interface interativa de navegação (TUI). +.Bl -tag -width -x +.It Fl l , Fl -mirror-list Ar mirrorlist +Use um arquivo +.Ar mirrorlist +alternativo. Este deve estar no formato descrito em +.Sx ARQUIVOS . +Padrão: +.Pa /usr/share/xmirror/mirrors.lst +.It Fl n , Fl -no-fetch +Não tente atualizar a lista de espelhos. +.El +.Ss Não interativo +Usar essas opções ignora o TUI interativo. +.Bl -tag -width -x +.It Fl d , Fl -default +Redefina o espelho atual para o padrão e saia. +.It Fl s , Fl -set Ar mirrorurl +Defina o espelho atual como +.Ar mirrorurl +e saia. +.El +.Sh AMBIENTE +O +.Nm +respeita todas as variáveis ​​de ambiente que o +.Xr xbps-install 1 +usa ao sincronizar índices de repositório após selecionar ou redefinir espelhos. +.Pp +.Sy XBPS_ARCH +é particularmente útil ao definir o espelho em um sistema de +arquitetura diferente. +.Sh ARQUIVOS +.Ar /usr/share/xmirror/mirrors.lst +é onde a lista de espelhos atual é armazenada. É um arquivo de valores separados por tabulação, +com as colunas: +.Bl -tag -width location +.It Sy região +Uma abreviação de continente de +.Lk https://planetarynames.wr.usgs.gov/Abbreviations , +.Em World , +ou outra string que descreva a região do espelho. +.It Sy url +A URL base do espelho, por exemplo: +.Lk https://repo-default.voidlinux.org/ +.It Sy localização +Um local legível para o espelho, como um país e/ou cidade. +.It Sy nível +Um indicador de status. +.El +.Pp +Todas as linhas que começam com +.Em # +são ignoradas. +.Sh VEJA TAMBÉM +.Xr xbps-install 1 , +.Lk https://docs.voidlinux.org/xbps/repositories/mirrors/changing.html +.Sh AUTOR +.An classabbyamp Aq Mt void@placeviolette.net +.Sh BUGS +Relatar bugs em +.Lk https://github.com/void-linux/xmirror/issues diff --git a/xmirror.in b/xmirror.in index cc0f78d..4ffd680 100755 --- a/xmirror.in +++ b/xmirror.in @@ -1,248 +1,450 @@ #!/bin/bash +# +# Author: classabbyamp +# Fernando Souza - https://github.com/tuxslack +# +# Description: Interactive script for changing XBPS mirrors. +# Version: 0.4.2 +# License: BSD-2-Clause + + +# ---------------------------------------------------------------------------------------- + +# Internacionalização com gettext + +export TEXTDOMAIN=xmirror +export TEXTDOMAINDIR=/usr/share/locale + + +# 🌍 Gerar arquivo .pot (modelo de tradução) + +# Depois que todas as strings estiverem com gettext, use o comando: + +# xgettext -L Shell -o xmirror.pot xmirror.in + +# Isso gera um arquivo .pot que pode ser usado para traduzir. + + +# Criar a tradução pt_BR xmirror.po + +# Com base no .pot gerado: + +# msginit --locale=pt_BR --input=xmirror.pot --output=xmirror.po --no-translator --no-wrap + + +# sed -i '/^"Project-Id-Version:/c\"Project-Id-Version: xmirror 0.4.2\\n"' xmirror.po +# sed -i '/^"Report-Msgid-Bugs-To:/c\"Report-Msgid-Bugs-To: \\n"' xmirror.po +# sed -i '/^"POT-Creation-Date:/c\"POT-Creation-Date: 2025-09-04 16:29-0300\\n"' xmirror.po +# sed -i '/^"PO-Revision-Date:/c\"PO-Revision-Date: 2025-09-04 16:29-0300\\n"' xmirror.po +# sed -i '/^"Last-Translator:/c\"Last-Translator: Automatically generated\\n"' xmirror.po +# sed -i '/^"Language-Team:/c\"Language-Team: none\\n"' xmirror.po +# sed -i '/^"Language:/c\"Language: pt_BR\\n"' xmirror.po +# sed -i '/^"Content-Type:/c\"Content-Type: text/plain; charset=UTF-8\\n"' xmirror.po +# sed -i '/^"Plural-Forms:/c\"Plural-Forms: nplurals=2; plural=(n > 1);\\n"' xmirror.po + + +# Para arquivos .po de traduções em português do Brasil, que usam acentuação e caracteres +# especiais (como ç, ã, é, etc.), ASCII não é suficiente. + +# Onde CHARSET deve ser UTF-8 para suportar caracteres acentuados e especiais. + + +# Compilar e instalar a tradução + +# msgfmt xmirror.po -o xmirror.mo + + +# Depois copie para o local correto: + +# sudo mkdir -p /usr/share/locale/pt_BR/LC_MESSAGES + +# sudo cp xmirror.mo /usr/share/locale/pt_BR/LC_MESSAGES/xmirror.mo + + +# Agora, se o sistema estiver com a locale em pt_BR.UTF-8, o script já exibirá as mensagens traduzidas! + +# ---------------------------------------------------------------------------------------- usage() { cat 1>&2 <&2 + + echo "$(printf "$(gettext "xmirror v%s")" "@@VERSION@@")" 1>&2 + exit 0 } +# ---------------------------------------------------------------------------------------- + # dialog colors + RED="\Z1" WHITE="\Z7" BOLD="\Zb" RESET="\Zn" + +# ---------------------------------------------------------------------------------------- + INITMSG=$(fold -sw 76 <"$ANSWER" + --backtitle "${BOLD}${WHITE}$(printf "$(gettext "Void Linux Mirror Selector -- https://www.voidlinux.org (v%s)")" "@@VERSION@@")${RESET}" \ + --cancel-label "$(gettext "Back")" --aspect 20 "$@" 2>"$ANSWER" + return $? } +# ---------------------------------------------------------------------------------------- + die() { + rm -f "$ANSWER" + exit "${1:-0}" } +# ---------------------------------------------------------------------------------------- + log() { echo xmirror: "$@" 1>&2 } +# ---------------------------------------------------------------------------------------- + check_required_programs() { + for cmd in find sed "$@"; do + if ! command -v "$cmd" >/dev/null 2>&1; then - log "could not find $cmd" + + log "$(printf "$(gettext "could not find %s")" "$cmd")" + exit 1 fi + done + XBPS_INSTALL="$(check_xbps_program install)" + XBPS_FETCH="$(check_xbps_program fetch)" } +# ---------------------------------------------------------------------------------------- + check_xbps_program() { + local prog="$1" + if command -v "xbps-$prog" >/dev/null 2>&1; then + echo "xbps-$prog" + elif command -v "xbps-$prog.static" >/dev/null 2>&1; then + echo "xbps-$prog.static" + else - log "xmirror: could not find xbps-$prog or xbps-$prog.static" + + log "$(printf "$(gettext "xmirror: could not find xbps-%s or xbps-%s.static")" "$prog")" + exit 1 fi } +# ---------------------------------------------------------------------------------------- + check_root() { + if [ "$(id -u)" != 0 ]; then - log "must be run as root" + + log "$(gettext "must be run as root")" + exit 1 fi } +# ---------------------------------------------------------------------------------------- + # uses names and abbreviations from https://planetarynames.wr.usgs.gov/Abbreviations + region_name() { + case "$1" in - AF) echo "Africa" ;; - AN) echo "Antarctica" ;; - AS) echo "Asia" ;; - EU) echo "Europe" ;; - NA) echo "North America" ;; - OC) echo "Oceania" ;; - SA) echo "South and Central America" ;; - World) echo "Globally Available" ;; + AF) echo "$(gettext "Africa")" ;; + AN) echo "$(gettext "Antarctica")" ;; + AS) echo "$(gettext "Asia")" ;; + EU) echo "$(gettext "Europe")" ;; + NA) echo "$(gettext "North America")" ;; + OC) echo "$(gettext "Oceania")" ;; + SA) echo "$(gettext "South and Central America")" ;; + World) echo "$(gettext "Globally Available")" ;; *) echo "$1" ;; esac + } +# ---------------------------------------------------------------------------------------- + get_mirrors() { + if [ -z "$NOFETCH" ]; then - log "updating mirrorlist in ${ROOTDIR}/usr/share/xmirror" + + log "$(printf "$(gettext "updating mirrorlist in %s/usr/share/xmirror")" "${ROOTDIR}")" + if ! $XBPS_FETCH -o "$MIRRORLIST" "$MIRRORURL" &>/dev/null; then - log "unable to fetch new mirror list" + + log "$(gettext "unable to fetch new mirror list")" + fi fi + while read -r line; do + [[ "$line" = '#'* ]] && continue + while IFS=$'\t' read -r region rest; do + allmirrors["$region"]+="$rest"$'\n' + done <<< "$line" + done < "$MIRRORLIST" for region in $(printf '%s\n' "${!allmirrors[@]}" | sort -u); do + regions+=( "$region" "$(region_name "$region")" ) + done - regions+=( "Default" "Reset to the default mirror" ) - regions+=( "Exit" "Exit this wizard" ) + regions+=( "$(gettext "Default")" "$(gettext "Reset to the default mirror")" ) + + regions+=( "$(gettext "Exit")" "$(gettext "Exit this wizard")" ) } +# ---------------------------------------------------------------------------------------- + write_mirrors_int() { + local FILES REPOSITORY="$1" + FILES="$(find "${ROOTDIR}"/usr/share/xbps.d/ -name '*-repository-*.conf' | sort -u | sed 's|/usr/share|/etc|g')" - DIALOG --cr-wrap --yesno "${BOLD}The following operations will be executed:${RESET}\n\n -The current mirror will be switched to: ${RED}${REPOSITORY}${RESET} -The following files in ${BOLD}${ROOTDIR}/etc/xbps.d${RESET} will be created or overwritten, if they exist: -${RED}${FILES// /$'\n'}${RESET}\n\n -${BOLD}Do you want to continue?${RESET}" 20 80 || return + + DIALOG --cr-wrap --yes-label "$(gettext "Yes")" --no-label "$(gettext "No")" --yesno "$(printf "$(gettext "%sThe following operations will be executed:%s\n\n +The current mirror will be switched to: %s%s%s +The following files in %s%s/etc/xbps.d%s will be created or overwritten, if they exist: +%s%s%s\n\n +%sDo you want to continue?%s")" "${BOLD}" "${RESET}" "${RED}" "${REPOSITORY}" "${RESET}" "${BOLD}" "${ROOTDIR}" "${RESET}" "${RED}" "${FILES// /$'\n'}" "${RESET}" "${BOLD}" "${RESET}")" 20 80 || return { if write_mirrors "$REPOSITORY"; then - printf "\nMirror successfully changed to %s!\n" "$REPOSITORY" + + printf "\n$(gettext "Mirror successfully changed to %s!")\n" "$REPOSITORY" + else + for f in "${ROOTDIR}/etc/xbps.d"/*-repository-*.conf.old; do + mv "$f" "${f%.old}" + done - printf "\nMirror update failed! See log above for details.\n" + + printf "\n$(gettext "Mirror update failed! See log above for details.")\n" + fi - } |& DIALOG --title " Updating mirror... " --programbox 16 80 + + } |& DIALOG --title " $(gettext "Updating mirror...") " --programbox 16 80 + exit 0 } +# ---------------------------------------------------------------------------------------- + write_mirrors() { + local REPOSITORY="$1" + if ! [[ "$REPOSITORY" = *"://"* ]]; then - log "warning: mirror protocol not specified, assuming http://" + + log "$(gettext "warning: mirror protocol not specified, assuming http://")" + REPOSITORY="http://$REPOSITORY" fi + mkdir -p "${ROOTDIR}/etc/xbps.d" + cp --no-preserve=mode,ownership --backup=simple --suffix=.old \ "${ROOTDIR}/usr/share/xbps.d"/*-repository-*.conf "${ROOTDIR}/etc/xbps.d/" && sed -i "s|https://repo-default.voidlinux.org|${REPOSITORY%/}|g" "${ROOTDIR}/etc/xbps.d"/*-repository-*.conf && $XBPS_INSTALL -S -r "${ROOTDIR}" + } +# ---------------------------------------------------------------------------------------- + reset_mirrors_int() { + local FILES + FILES="$(find "${ROOTDIR}"/usr/share/xbps.d/ -name '*-repository-*.conf' | sort -u | sed 's|/usr/share|/etc|g')" - DIALOG --cr-wrap --yesno "${BOLD}The following operations will be executed:${RESET}\n\n + + DIALOG --cr-wrap --yes-label "$(gettext "Yes")" --no-label "$(gettext "No")" --yesno "$(printf "$(gettext "%sThe following operations will be executed:%s\n\n The current mirror will be reset to the default. -The following files in ${BOLD}${ROOTDIR}/etc/xbps.d${RESET} will be removed, if they exist: -${RED}${FILES// /$'\n'}${RESET}\n\n -${BOLD}Do you want to continue?${RESET}" 20 80 || return +The following files in %s%s/etc/xbps.d%s will be removed, if they exist: +%s%s%s\n\n +%sDo you want to continue?%s")" "${BOLD}" "${RESET}" "${BOLD}" "${ROOTDIR}" "${RESET}" "${RED}" "${FILES// /$'\n'}" "${RESET}" "${BOLD}" "${RESET}")" 20 80 || return { if reset_mirrors "$FILES"; then - printf "\nMirror successfully reset!\n" + + printf "\n$(gettext "Mirror successfully reset!")\n" + else - printf "\nMirror reset failed! See log above for details.\n" + + printf "\n$(gettext "Mirror reset failed! See log above for details.")\n" + fi - } |& DIALOG --title " Resetting mirror to default... " --programbox 16 80 + + } |& DIALOG --title " $(gettext "Resetting mirror to default...") " --programbox 16 80 + exit 0 } +# ---------------------------------------------------------------------------------------- + reset_mirrors() { + local FILES="$1" + set -e + # shellcheck disable=SC2086 rm -f $FILES + $XBPS_INSTALL -S -r "${ROOTDIR}" + set +e } +# ---------------------------------------------------------------------------------------- + region_menu() { + local sel - DIALOG --title " Choose a Region " \ + + DIALOG --title " $(gettext "Choose a Region") " \ --menu "$MENULABEL" 10 78 0 \ "${regions[@]}" sel="$(cat "$ANSWER")" + case $sel in - "Exit"|'') exit 0 ;; - "Default") reset_mirrors_int ;; + "$(gettext "Exit")"|'') exit 0 ;; + "$(gettext "Default")") reset_mirrors_int ;; *) mirror_menu "$sel" ;; esac } +# ---------------------------------------------------------------------------------------- + mirror_menu() { + local sel region="$1" unset mirrors declare -a mirrors while read -r line; do + [ -z "$line" ] && continue + while IFS=$'\t' read -r url location tier rest; do - mirrors+=( "$url" "$location (Tier $tier)" ) + + mirrors+=( "$url" "$location ($(gettext "Tier") $tier)" ) + done <<< "$line" + done <<< "${allmirrors[$region]}" while true; do - DIALOG --title " Choose a Mirror (Region: $(region_name "$region")) " \ + + DIALOG --title " $(printf " $(gettext "Choose a Mirror (Region: %s)") " "$(region_name "$region")")" \ --menu "$MENULABEL" 10 78 0 \ "${mirrors[@]}" sel="$(cat "$ANSWER")" + case $sel in "") return ;; *) write_mirrors_int "$sel" ;; esac + done } +# ---------------------------------------------------------------------------------------- + TEMP=$(getopt -o 'l:r:s:dnvh' --long 'mirror-list:,rootdir:,set:,default,no-fetch,version,help' -n xmirror -- "$@") # shellcheck disable=SC2181 + if [ $? -ne 0 ]; then + usage + fi eval set -- "$TEMP" + unset TEMP while true; do + case "$1" in '-l'|'--mirror-list') MIRRORLIST="$2"; NOFETCH=1; shift 2 ;; '-r'|'--rootdir') ROOTDIR="$2"; shift 2 ;; @@ -254,35 +456,59 @@ while true; do ''|'--') break ;; *) usage ;; esac + done check_root if [ -n "$SETMIRROR" ]; then + check_required_programs + SETMIRROR="${SETMIRROR%%/current*}" - log "updating mirror to $SETMIRROR..." + + log "$(printf "$(gettext "updating mirror to %s...")" "$SETMIRROR")" + if write_mirrors "$SETMIRROR"; then - log "mirror successfully updated to $SETMIRROR." + + log "$(printf "$(gettext "mirror successfully updated to %s.")" "$SETMIRROR")" + exit 0 + else + for f in "${ROOTDIR}/etc/xbps.d"/*-repository-*.conf.old; do + mv "$f" "${f%.old}" + done - log "mirror update failed." + + log "$(gettext "mirror update failed.")" + exit 1 + fi + fi if [ -n "$RESETMIRROR" ]; then + check_required_programs - log "xmirror: resetting mirror..." + + log "$(gettext "xmirror: resetting mirror...")" + FILES="$(find "${ROOTDIR}"/usr/share/xbps.d/ -name '*-repository-*.conf' | sort -u | sed 's|/usr/share|/etc|g')" + if reset_mirrors "$FILES"; then - log "xmirror: mirror successfully reset." + + log "$(gettext "xmirror: mirror successfully reset.")" + exit 0 + else - log "xmirror: mirror reset failed." + + log "$(gettext "xmirror: mirror reset failed.")" + exit 1 fi fi @@ -295,15 +521,19 @@ declare -a regions check_required_programs dialog -trap "die" INT TERM QUIT EXIT +trap die INT TERM QUIT EXIT get_mirrors ANSWER=$(mktemp -t xmirror-XXXXXXXX) || exit 1 -DIALOG --title "${BOLD} Void Linux Mirror Selection Wizard ${RESET}" --msgbox "$INITMSG" 15 80 +DIALOG --title "${BOLD} $(gettext "Void Linux Mirror Selection Wizard") ${RESET}" --msgbox "$INITMSG" 15 80 while true; do + region_menu + done + # vim: set ft=bash: +