使用自托管的Arch Linux metapackages复制系统

这些年来,我花了很多时间来调整系统以适应我的口味。诸如Openbox,Vim,Zsh,Tmux之类的东西有无数的选项和插件,我会尽力进行配置,此外,我还收集了已安装程序的集合,这些程序和配置福彩双色球开奖结果已调整。

如果要将设置复制到新系统(例如工作计算机,平板电脑或VM)中,则一次又一次地进行所有过程非常耗时且令人讨厌。最重要的是,个性化是一个无休止的过程,因此我们面临着将未来更改同步到所有设备的问题。

和其他Arch Linux用户一样,我最终编写了安装脚本。我将自己的配置脚本和福彩双色球开奖结果托管在自己的主机中 吉特 实例,并且我过去一直保留已安装软件包的自动最新列表,如中所述 这另一个职位.

尽管这是向前迈出的一步,但是当您有一堆要同步的设备时,这并不理想。我不’希望我所有系统中的所有软件包以及配置的某些部分可能有所不同。

为了解决第二个问题,我通常会盲目复制主配置福彩双色球开奖结果,然后再复制单独同步的本地配置福彩双色球开奖结果。

For instance, a .vimrc file can end with a source .vimrc.local file, or sometimes I set up a conf.d kind of directory where I can add or remove files from.

我受到启发 这个帖子 尝试使用元软件包方法来解决这两个问题:复制我的软件包和配置福彩双色球开奖结果,以及同步我的更改。我的全部功劳归功于作者,只是我个人更愿意自行托管我的软件包。

拱元包

元包只是一个没有’实际打包福彩双色球开奖结果。取而代之的是,我们使用元数据来执行诸如将依赖项分组在一起,指定包冲突等操作。

每当我们安装metapackage时,所有依赖项也将被引入。满容易。这并没有比以前的方法好多少:我们只是从安装软件包列表的脚本更改为将软件包列表嵌入到软件包管理器能够理解的元软件包中。

The interesting part is that we can also add our configuration files to the package. When we update the package those files will be updated as well without any additional effort. Also, pacman is aware of what files belong to what package, so it will warn us if we have modified them and 它将保存一个名为 pacnew 福彩双色球开奖结果,以便我们可以对其进行比较。我们可以配置某些配置福彩双色球开奖结果 要备份 以及自动替换,而不是简单地覆盖。

# pacman -Rdd nacho-vim

Packages (1) nacho-vim-0.0.1-2

Total Removed Size:  1.36 MiB

:: Do you want to remove these packages? [Y/n] 
:: Processing package changes...
(1/1) removing nacho-vim                                                     [###########################################] 100%
warning: /home/nacho/.vimrc saved as /home/nacho/.vimrc.pacsave

# mv .vimrc.pacsave .vimrc
# pacman -S nacho-vim 
resolving dependencies...
looking for conflicting packages...

Packages (1) nacho-vim-0.0.1-2

Total Installed Size:  1.36 MiB

:: Proceed with installation? [Y/n] 
(1/1) checking keys in keyring                                               [###########################################] 100%
(1/1) checking package integrity                                             [###########################################] 100%
(1/1) loading package files                                                  [###########################################] 100%
(1/1) checking for file conflicts                                            [###########################################] 100%
(1/1) checking available disk space                                          [###########################################] 100%
:: Processing package changes...
(1/1) installing nacho-vim                                                   [###########################################] 100%
warning: /home/nacho/.vimrc installed as /home/nacho/.vimrc.pacnew

I also package my many custom scripts, and wrappers that live in my ~/.bin folder. We can package any files we want.

It is also useful to create relationships between metapackages when this makes sense. For instance, I always want to install vim alongside with ctags and cscope, or zsh with zsh-suggestions, powerline and all the cool stuff, together with their respective dotfiles. So I have them grouped in the nacho-vim and nacho-zsh metapackages, and instead of adding vim and zsh as dependencies of nacho-base I do add nacho-vim and nacho-zsh in their place.

Finally we can add custom post ugrade and post install hooks to run operations such as enabling a service we just installed or adjusting permissions of the files that pacman copied over.

The great thing about metapackages is that we get the functionality of a dotfile manager without requiring additional tools. Just running pacman -Syu as we normally do will also update our configuration files and an new packages we might have added to our favorite setup.

其中一些可以通过软件包组来完成,但是我所追求的重要功能是所有系统都会自动升级。来自 拱形维基

与组相比,元软件包的优势在于,当使用一组新的依赖项更新元软件包本身时,将安装任何新的成员软件包。这与不会自动安装新组成员的组相反。

创建我们的元包

无需再次解释已经很好解释的内容。软件包是从 PKGBUILD 与福彩双色球开奖结果 makepkg 命令。您可以查看有关以下内容的Wiki: 如何创建包.

有很多方法可以给猫皮。我只会提及我喜欢做的几件事。

我喜欢使用这种结构

$ tree zsh
├── PKGBUILD
├── _zprofile
├── _zsh_aliases
├── _zshrc
├── zsh.install
└── zsh.txt

The files to be included need to be in the same directory as the PKGBUILD file. zsh.install is where I define my post-upgrade and post-update hooks

post_install() {
  # set zsh as my default  贝壳 
  chsh -s /usr/bin/zsh nacho
}

post_upgrade() {
  # pacman copies the files as root:root
  chown -R nacho: /home/nacho/{.zsh,.oh-my-zsh,.config,.zshrc,.zsh_aliases,.zprofile}
}

zsh.txt 只是依赖项列表

zsh
zsh-syntax-highlighting
zsh-theme-powerlevel9k
# and so on

我对所有元包都遵循相同的模式。首先,我采购了这个简单的福彩双色球开奖结果以避免重复

# package version
gittag=$(git describe --tags --always)
pkgver=${gittag%%-*}
pkgrel=${gittag##*-}

# home directory
home="\${pkgdir}"/home/nacho

# add all files in this directory to the package
source=($(find . -maxdepth 1 -type f))
for i in $(seq 1 ${#source[@]}); do sha256sums+=(SKIP); done

# use .txt and .install if they exist for deps an hooks
config_from_files() {
  [[ -f "$1.txt"     ]] && depends=($(grep -v "^#" "$1.txt"))
  [[ -f "$1.install" ]] && install="$1.install"
  return 0
}

# for convenience
INSTALL_="install -D -o nacho -g nacho --verbose --backup --compare -m644"
INSTALLX="install -D -o nacho -g nacho --verbose --backup --compare -m750"
INSTALLD="install -d -o nacho -g nacho --verbose --backup --compare "

This way I only need to set the 吉特 tag in the repository and the package versions will be derived from it. Also I can add the .txt and the .install files if I want to.

Finally, a simplified PKGBUILD can look something like this

# Maintainer: 纳乔帕克 <nacho@ownyourbits.com>
pkgname='nacho-zsh'
pkgdesc="zsh personalization"
arch=('any')
license=('GPL2')
url="//server/bla"

source ../common.sh

package_nacho-zsh() {
  config_from_files zsh
  local home=$(eval echo "${home}")

  # Install oh-my-zsh, autosuggestions and all the rest here
  
  # Package home files as backup (replace initial _ for .)
  for file in "${source[@]}"; do
    local f=$(basename "${file}" | sed 's=^_=.=')
    [[ "${f}" =~ ^\..* ]] || continue
    $INSTALL_ "${file}" "${home}"/"${f}"
    backup+=("home/nacho/${f}")
  done
}

有了这些信息后,95%的维护工作就是使用来自 最后发表 关于这个话题。

自托管我们的Arch存储库

所以我们已经有了自己的包和元包,现在我们需要在我们的机器之间进行同步。

存储库只不过是软件包和一个软件包的集合。 数据库福彩双色球开奖结果 包含软件包列表和元数据。

打包后,我们将使用 回购 帮手

回购 nacho.db.tar.xz $generated_packages

Then, we can place packages and database in different places that pacman understands. This can be in our own filesystem (useful to install packages from USB or CD), HTTP or FTP for example.

如果我们想使用Raspberry Pi之类的工具,我们所要做的就是为这些福彩双色球开奖结果静态提供目录。这样就足够了

sudo -u http darkhttpd /path/to/repo --no-server-id

但是,由于我已经将Apache用于 下一个 CloudPi,我在端口8888上添加了新的虚拟主机

$ cat /etc/apache2/sites-available/arch-repo.conf 
Listen 8888
<VirtualHost *:8888>
  DocumentRoot /path/to/arch-repo/
</VirtualHost>

<Directory /path/to/arch-repo/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>
# a2ensite  拱 -repo

现在我们拥有了所有的碎片,所以让’s just put them together. Whenever I change my package list in one of the .txt files, I run the following script

#!/bin/bash
set -e
for d in $(ls -d */); do (cd $d &&  makepkg  -f -c); done                                                                        
pkgs=$(find -name 'nacho-*.pkg.tar.xz')
repo-add nacho.db.tar.xz $pkgs
scp nacho.db $pkgs home-server:/path/to/arch-repo
git clean -fd .

生成软件包,然后创建数据库福彩双色球开奖结果并将其全部发送到我们的静态托管目录。

Finally we add to our installation script a line where we point pacman to our personal repository. We need the following in all our machines

$ tail -3 /etc/pacman.conf
[nacho]
SigLevel = Optional TrustAll
Server = http://mycloud.com:8888/

下次我们升级系统时,我们的个人存储库也将同步

# pacman -Syu
:: Synchronizing package databases...
 core is up to date
 extra is up to date
 community is up to date
 nacho                                                3.3 KiB   329K/s 00:00 [###########################################] 100%
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...

Packages (4) nacho-base-0.0.1-3  nacho-openbox-0.0.1-3  nacho-vim-0.0.1-3  nacho-zsh-0.0.1-3

Total Download Size:   4.65 MiB
Total Installed Size:  7.91 MiB
Net Upgrade Size:      0.02 MiB

:: Proceed with installation? [Y/n]

There we go, that was pretty easy. Whenever we do our routine pacman -Syu the database will be synchronized and if there’是该软件包的新版本,将下载并安装该软件包,并在此过程中同步我们所有的配置和新的依赖项。

毫无疑问,随着时间的流逝,它会不断发展。希望它能给您一些想法。

作者: 纳乔帕克

谦虚地分享我认为有用的东西 [ 的github 码头工人 hub ]

发表评论

您的电子邮件地址不会被公开。 必需的地方已做标记 *