使用 msmtp 和 GMail 账号部署服务器 SMTP 发信(2024年)

实验室新添加的服务器需要一个基本的邮件通知功能,也就是在某些事件发生时能够向外发送电子邮件进行通知。众所周知,配置电子邮件的基础设施通常会很麻烦。因此,我在寻找解决方案时有以下三点考虑:

  • 服务器程序发送电子邮件的接口应该通用。因此,我优先考虑使用提供了兼容/usr/sbin/sendmail命令的软件。
  • 避免额外注册邮箱账号的麻烦。因此我选择重复利用我已有的 GMail 账号。
  • 考虑 GMail 的特有限制。由于使用 Google 主密码进行 SMTP 发信身份认证的操作已经被 GMail 认为不安全而禁用了,所以这次必须变相使用用户名和密码完成 SMTP 配置。Google 提供了一个名为 App passwords 的特别功能,能够根据需要创建一个起替代作用的纯文本密码。

我最后选择的解决方案是 msmtp 配合 msmtp-mta 以及 GMail SMTP + App Passwords 组合。整个过程基本是遵循Gmail with an App Password这篇英文博客文章来部署的。

本文的配置在2024年10月有效,但无法保证永远生效。请在进行配置之前先行验证方法的有效性。
Read More

Golden Corral 的单人餐,拍摄于2024年1月。

匹兹堡自助餐/吃到饱(buffet/all you can eat)餐厅简评

我个人下馆子并不喜欢被菜单约束住,因为总是看上去什么都想吃,但限于没有同伴总是单人用餐而无法多点几道菜。因此,我比较喜欢允许餐点自选的自助餐厅。这里我就简单评价一下截至2024年1月我在美国宾州匹兹堡地区去过的,提供自助餐(buffet)或吃到饱(all you can eat)服务的几家餐厅。列出的餐厅都是适合单人前往的,像 Hunan Bar 那种三人以上的火锅自助不在本文讨论范围内。

总的来说,匹兹堡地区的自助餐和吃到饱餐厅以中餐和印餐为主,这和美国其它地区的情况可能有所不同。除了市内商业区的餐厅外,市郊更有更多令人惊喜的自助和吃到饱餐厅可供选择。

Read More

Hide “AMD Software” entry in Windows 11 Context Menu (right-click menu)

Background

I just bought a Lenovo 14p Gen 3 laptop with preinstalled Windows 11. Since it is an AMD-based laptop, it has an AMD configuration software installed, namely AMD Software: Adrenalin Edition. It provides several useful features for screen display. However, the annoying thing is that it adds an extra entry in Windows 11’s default Context Menu. Luckily, there is a way to block such entry without uninstalling the AMD software.

Desktop right click menu in default installation
Desktop right click menu, showing the annoying “AMD software: Adrenalin Edition” entry.

Steps to hide entry using Regedit

  1. Open regedit.exe and visit \HKEY_CLASSES_ROOT\PackagedCom\ClassIndex\. There should be several tens of entries (keys) under that, all named after {UUID}.
  2. Expand all entries you saw in Step 1 and look for the entry containing keyword AdvancedMicroDevicesInc (“AMD”). Once you find it, copy its corresponding UUID string. We will use it in the steps below.
    In this case, the UUID starting with 6767... is what we need.
  3. Open regedit.exe and visit \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\. There should be three keys under Shell Extensions: Approved, Blocked, and Cached. If there is no Blocked key on your system, manually create it by right-clicking Shell Extensions, and create a new key named Blocked.
  4. Enter Blocked key (which appears as a directory in regedit tool). Under directory Blocked, create a new String (aka type REG_SZ). Rename the String as {UUID}, in which UUID is the same UUID as we found in Step 2.
    Example of final result under Shell Extensions\Blocked key
  5. Go back to desktop and try with right click. If everything is done correctly, the AMD Software entry will immediately disappear in the right-click menu.
  6. If you want to revert our modification, simply delete the value we created in Step 4.

References

Quick guide: set up chroot environment and build Debian packages (sbuild version)

TL;DR: Pbuilder-related tools are ineffective and redundant. By installing sbuild and schroot, one can set up clean and reusable chroot environments quickly and use the sole sbuild command to build Debian source packages (using src tree or .dsc files).
Fade away please pbuilder/cowbuilder; long live sbuild!


Quick example

Install tools and preparation

sudo apt update;
sudo apt install sbuild schroot;
sudo mkdir -p /var/lib/sbuild/chroots; # the last component is made by us
sudo chown sbuild:sbuild /var/lib/sbuild/chroots;

Initialize a chroot environment using sbuild-createchroot

# Assume host machine is of x86_64 architecture, create an unstable chroot
sudo sbuild-createchroot unstable /var/lib/sbuild/chroots/unstable-amd64 \
  --alias=sid --alias=UNRELEASED http://deb.debian.org/debian;

Keep (s)chroot environment updated

sudo sbuild-update -ud unstable;

Build a Debian package using sbuild with previously created chroot environment

# If you want to drop superuser privilege, add yourself into sbuild group first.
# Other settings might be needed. See sbuild-adduser(1).
# #################################
# Option 1: have proper Debian source package
sbuild -A -v -d unstable /path/to/package.dsc
#
# Option 2: chdir into extracted source tree with .orig tarball in parent directory
sbuild -A -v -d unstable
# Option 3: integrate with git-buildpackage (gbp)
gbp buildpackage --git-builder=sbuild -A -v -d unstable
#
# Notes:
# 1. If you need source-only changes (https://wiki.debian.org/SourceOnlyUpload),
#    append "--source" to sbuild's invocation
# 2. If you want to sign your build, append "-kxxxxxxxx"
#    to your sbuild's invocation, where xxxxxxxx is you gpg keyid

How to destroy schroot environment properly

If you do not wish to use schroot and sbuild anymore, you may use the following tool to properly destroy the schroot environment:

# Destroy the chroot instance named "unstable"
sudo sbuild-destroychroot unstable
# This script actually does nothing other than providing instructions.
# You will need to follow the printed instruction and safely
# destroy the schroot instance by yourself.

References

To be continued…


Updates

  • July 19, 2020: Replace httpredir.debian.org with CDN-enabled deb.debian.org.
  • July 19, 2020: Add text related to sbuild-destroychroot.
  • July 22, 2020: Remove “sudo” from sbuild invocation. No privilege is needed in this case.

配合Git为Debian系发行版打包的正确方式

配合Git为Debian系发行版打包的正确方式教你使用正确的姿势又好又快地得到一个deb安装包

Debian这个发行版历史悠久,其软件包管理工具apt和dpkg更是作为其特色沿用至今,在保留严谨传统的同时得到了长足的发展和演进。然而正是由于其不短的历史(虽然还没到三十年,但是这样的时间跨度对于IT行业的产物已经算惊人的长了),Debian的包管理工具不可避免地存在着稍显沉重的历史包袱。一些过去的真理和守则反而成为了现在的累赘,一代又一代地误导着后来者。为了让后来者少走弯路,我在这里记录一些摸索过程中的体会和技巧,希望能够让更多人体会到Debian的魅力所在。
如果你只想了解最佳的工作流的话,请直接翻到最后面查看。但是具体工具的使用方法需要自行查找资料,或者回到前文寻找相应的内容。
Read More

Fast preparation of a source-only upload for Debian

Let’s assume that you find the source code of a software for Debian with a debian/ directory included. How to prepare the .dsc package (Debian source package) used for upload quickly? I will show you here.

  1. Extract the software into a certain directory, let’s say foobar/.
  2. Repack original tarball and exclude debian/ dir using tar. Rename orig tarball as <PKGNAME>_<PKGVER>.orig.tar.{bz2,gz,lzma,xz}. Note that if your package is Debian native, you should skip this step.
  3. cd foobar/
  4. dpkg-source -b .
  5. (cd ..; debsign ./*.dsc -k<YOUR_GPG_KEY_FINGERPRINT>)
  6. dpkg-genchanges -S > ../<PKGNAME>_<PKGVER>.changes
  7. cd ..; debsign ./*.changes -k<YOUR_GPG_KEY_FINGERPRINT>

All done. You may now upload the source package with dput tool.

被雪藏的大号瑞士军刀:eric6 IDE

作为一个有跨平台强迫症和被Python惯坏的业余伪程序员,我在挑选开发桌面应用的时候果断地选择了PyQt,因为它结合了Python的强大、快速开发的特点与Qt的跨平台性质。

然而常见的图形应用程序大都需要集成开发环境(IDE)以辅助开发,在挑选IDE时我着实费了一番功夫。让我们简单地列一下现在(2016年初)能够排得上名的IDE

  • PyCharm,常见的选择,据说十分强大,然而它是JetBrains公司的产品(意味着你要结合Java使用),也存在商业版,有一种不爽的感觉。
  • Eclipse,没用过不做评价。但是还是Java
  • Python IDLE,这东西能用?

今天我要推荐的是一款不是那么出名的软件:eric6 IDE。

Read More