mirror of
https://github.com/LCTT/TranslateProject.git
synced 2026-08-23 04:03:29 +08:00
@@ -0,0 +1,68 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (qhwdw)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10478-1.html)
|
||||
[#]: subject: (Computer Laboratory – Raspberry Pi: Lesson 2 OK02)
|
||||
[#]: via: (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok02.html)
|
||||
[#]: author: (Robert Mullins http://www.cl.cam.ac.uk/~rdm34)
|
||||
|
||||
计算机实验室之树莓派:课程 2 OK02
|
||||
======
|
||||
|
||||
OK02 课程构建于 OK01 课程的基础上,通过不停地打开和关闭 OK 或 ACT LED 指示灯来实现闪烁。假设你已经有了 [课程 1:OK01][1] 操作系统的代码,它将是这一节课的基础。
|
||||
|
||||
### 1、等待
|
||||
|
||||
等待是操作系统开发中非常有用的部分。操作系统经常发现自己无事可做,以及必须要延迟。在这个例子中,我们希望通过等待,让 LED 灯打开、关闭的闪烁可以看到。如果你只是打开和关闭它,你将看到这个视觉效果,因为计算机每秒种可以打开和关闭它好几千次(LCTT 译注:视觉暂留效应会使你难以发觉它的闪烁)。在后面的课程中,我们将看到精确的等待,但是现在,我们只要简单地去消耗时间就足够了。
|
||||
|
||||
```
|
||||
mov r2,#0x3F0000
|
||||
wait1$:
|
||||
sub r2,#1
|
||||
cmp r2,#0
|
||||
bne wait1$
|
||||
```
|
||||
|
||||
> `sub reg,#val` 从寄存器 `reg` 中的值上减去数字 `val`
|
||||
>
|
||||
> `cmp reg,#val` 将寄存器中的值与数字 `val` 进行比较。
|
||||
>
|
||||
> 如果最后的比较结果是不相等,那么执行后缀了 `ne` 的 `b` 命令。
|
||||
|
||||
上面是一个很常见的产生延迟的代码片段,由于每个树莓派基本上是相同的,所以产生的延迟大致也是相同的。它的工作原理是,使用一个 `mov` 命令将值 3F0000<sub>16</sub> 推入到寄存器 `r2` 中,然后将这个值减 1,直到这个值减到 0 为止。在这里使用了三个新命令 `sub`、 `cmp` 和 `bne`。
|
||||
|
||||
`sub` 是减法命令,它只是简单地从第一个参数中的值减去第二个参数中的值。
|
||||
|
||||
`cmp` 是个很有趣的命令。它将第一个参数与第二个参数进行比较,然后将比较结果记录到一个称为当前处理器状态寄存器的专用寄存器中。你其实不用担心它,它记住的只是两个数谁大或谁小,或是相等而已。[^1]
|
||||
|
||||
`bne` 其实是一个伪装的分支命令。在 ARM 汇编语言家族中,任何指令都可以有条件地运行。这意味着如果上一个比较结果是某个确定的结果,那个指令才会运行。这是个非常有意思的技巧,我们在后面将大量使用到它,但在本案例中,我们在 `b` 命令后面的 `ne` 后缀意思是 “只有在上一个比较的结果是值不相等,才去运行该分支”。`ne` 后缀可以使用在任何命令上,其它几个(总共 16 个)条件也是如此,比如 `eq` 表示等于,而 `lt` 表示小于。
|
||||
|
||||
### 2、组合到一起
|
||||
|
||||
上一节讲我提到过,通过将 GPIO 地址偏移量设置为 28(即:`str r1,[r0,#28]`)而不是 40 即可实现 LED 的关闭。因此,你需要去修改课程 OK01 的代码,在打开 LED 后,运行等待代码,然后再关闭 LED,再次运行等待代码,并包含一个回到开始位置的分支。注意,不需要重新启用 GPIO 的 16 号针脚的输出功能,这个操作只需要做一次就可以了。如果你想更高效,我建议你复用 `r1` 寄存器的值。所有课程都一样,你可以在 [下载页面][2] 找到所有的解决方案。需要注意的是,必须保证你的所有标签都是唯一的。当你写了 `wait1$:` 你其它行上的标签就不能再使用 `wait1$` 了。
|
||||
|
||||
在我的树莓派上,它大约是每秒闪两次。通过改变我们所设置的 `r2` 寄存器中的值,可以很轻松地修改它。但是,不幸的是,我不能够精确地预测它的运行速度。如果你的树莓派未按预期正常工作,请查看我们的故障排除页面,如果它正常工作,恭喜你。
|
||||
|
||||
在这个课程中,我们学习了另外两个汇编命令:`sub` 和 `cmp`,同时学习了 ARM 中如何实现有条件运行。
|
||||
|
||||
在下一个课程,[课程 3:OK03][3] 中我们将学习如何编写代码,以及建立一些代码复用的标准,并且如果需要的话,可能会使用 C 或 C++ 来写代码。
|
||||
|
||||
[^1]: 如果你点了这个链接,说明你一定想知道它的具体内容。CPSR 是一个由许多独立的比特位组成的 32 比特寄存器。它有一个位用于表示正数、零和负数。当一个 `cmp` 指令运行后,它从第一个参数上减去第二个参数,然后用这个位记下它的结果是正数、零还是负数。如果是零意味着它们相等(`a-b=0` 暗示着 `a=b`)如果为正数意味着 a 大于 b(`a-b>0` 暗示着 `a>b`),如果为负数意味着小于。还有其它比较指令,但 `cmp` 指令最直观。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok02.html
|
||||
|
||||
作者:[Robert Mullins][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: http://www.cl.cam.ac.uk/~rdm34
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://linux.cn/article-10458-1.html
|
||||
[2]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/downloads.html
|
||||
[3]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok03.html
|
||||
@@ -1,7 +1,7 @@
|
||||
红宝石(Ruby)史话
|
||||
======
|
||||
|
||||
尽管我很难说清楚为什么,但 Ruby 一直是我最喜爱的一门编程语言。如果用音乐来类比的话,Python 给我的感觉像是<ruby>朋克摇滚<rt>punk rock</rt></ruby>,简单、直接,但略显单调,而 Ruby 则像是爵士乐,赋予了程序员表达自我的根本自由,虽然这可能会让代码变复杂,编写出来的程序对其他人来说不直观。
|
||||
尽管我很难说清楚为什么,但 Ruby 一直是我最喜爱的一门编程语言。如果用音乐来类比的话,Python 给我的感觉像是<ruby>朋克摇滚<rt>punk rock</rt></ruby>,简单、直接,但略显单调,而 Ruby 则像是爵士乐,从根本上赋予了程序员表达自我的自由,虽然这可能会让代码变复杂,编写出来的程序对其他人来说不直观。
|
||||
|
||||
Ruby 社区一直将<ruby>灵活表达<rt>freedom of expression</rt></ruby>视为其核心价值。可我不认同这对于 Ruby 的开发和普及是最重要的。创建一门编程语言也许是为了更高的性能,也许是为了在抽象上节省更多的时间,可 Ruby 就有趣在它并不关心这些,从它诞生之初,它的目标就是让程序员更快乐。
|
||||
|
||||
@@ -13,7 +13,7 @@ Ruby 社区一直将<ruby>灵活表达<rt>freedom of expression</rt></ruby>视
|
||||
|
||||
> 我那时就知道 Python 了,但我不喜欢它,因为我认为它不是一门真正的面向对象的语言。面向对象就像是 Python 的一个附件。作为一个编程语言狂热者,我在 15 年里一直是面向对象的忠实粉丝。我真的想要一门生来就面向对象而且易用的脚本语言。我为此特地寻找过,可事实并不如愿。[^1]
|
||||
|
||||
所以一种解释松本创造 Ruby 的动机就是他想要创造一门更好的,而且面向对象版的 Perl。
|
||||
所以一种解释松本创造 Ruby 的动机就是他想要创造一门更好,且面向对象的 Perl。
|
||||
|
||||
但在其他场合,松本说他创造 Ruby 主要是为了让他自己和别人更快乐。2008 年,松本在谷歌技术讲座结束时放映了这张幻灯片:
|
||||
|
||||
@@ -25,39 +25,39 @@ Ruby 社区一直将<ruby>灵活表达<rt>freedom of expression</rt></ruby>视
|
||||
|
||||
松本开玩笑的说他制作 Ruby 的原因很自私,因为他觉得其它的语言乏味,所以需要创造一点让自己开心的东西。
|
||||
|
||||
这张幻灯片展现了松本谦虚的一面。其实,松本是一位摩门教徒践行者,因此我很好奇他传奇般的友善有多少归功于他的宗教信仰。无论如何,他的友善在 Ruby 社区广为流传,甚至有一条称为 MINASWAN 的原则,即“<ruby>松本人很好,我们也一样<rt>Matz Is Nice And So We Are Nice</rt></ruby>”。我想那张幻灯片一定震惊了来自 Google 的观众。我想谷歌技术讲座上的每张幻灯片都充满着代码和运行效率的指标,来说明一个方案比另一个更快更有效,可仅仅放映崇高的目标的幻灯片却寥寥无几。
|
||||
这张幻灯片展现了松本谦虚的一面。其实,松本是一位摩门教践行者,因此我很好奇他传奇般的友善有多少归功于他的宗教信仰。无论如何,他的友善在 Ruby 社区广为流传,甚至有一条称为 MINASWAN 的原则,即“<ruby>松本人很好,我们也一样<rt>Matz Is Nice And So We Are Nice</rt></ruby>”。我想那张幻灯片一定震惊了来自 Google 的观众。我想谷歌技术讲座上的每张幻灯片都充满着代码和运行效率的指标,来说明一个方案比另一个更快更有效,可仅仅放映崇高的目标的幻灯片却寥寥无几。
|
||||
|
||||
Ruby 主要受到 Perl 的影响。Perl 则是由 Larry Wall 于 20 世纪 80 年代晚期创造的语言,主要用于处理和转换基于文本的数据。Perl 因其文本处理和正则表达式而闻名于世。对于 Ruby 程序员,Perl 程序中的很多语法元素都不陌生,例如符号 `$`、符号 `@`、`elsif` 等等。虽然我觉得,这些不是 Ruby 应该具有的特征。除了这些符号外,Ruby 还借鉴了 Perl 中的正则表达式的处理和标准库。
|
||||
|
||||
但影响了 Ruby 的不仅仅只有 Perl 。在 Ruby 之前松本就完全用 Emacs Lisp 写过一个邮件客户端。这一经历让他对 Emacs 和 Lisp 语言运行的内部原理有了更多的认识。松本说 Ruby 底层的对象模型也受其启发。在那之上,松本添加了一个 Smalltalk 风格的信息传递系统,这一系统随后成为了 Ruby 中任何依赖 `#method_missing` 的操作的基石。松本也表示过 Ada 和 Eiffel 也影响了 Ruby 的设计。
|
||||
但影响了 Ruby 的不仅仅只有 Perl 。在 Ruby 之前,松本制作过一个仅用 Emacs Lisp 编写的邮件客户端。这一经历让他对 Emacs 和 Lisp 语言运行的内部原理有了更多的认识。松本说 Ruby 底层的对象模型也受其启发。在那之上,松本添加了一个 Smalltalk 风格的信息传递系统,这一系统随后成为了 Ruby 中任何依赖 `#method_missing` 的操作的基石。松本也表示过 Ada 和 Eiffel 也影响了 Ruby 的设计。
|
||||
|
||||
当时间来到了给这门新语言命名的时候,松本和他的同事 Keiju Ishitsuka 挑选了很多个名字。他们希望名字能够体现新语言和 Perl、shell 脚本间的联系。在[这一段非常值得一读的即时消息记录][2]中,Ishitsuka 和 松本也许花了太多的时间来思考 <ruby>shell<rt>贝壳</rt></ruby>、<ruby>clam<rt>蛤蛎</rt></ruby>、<ruby>oyster<rt>牡蛎</rt></ruby>和<ruby>pearl<rt>珍珠</rt></ruby>之间的关系了,以至于差点把 Ruby 命名为“<ruby>Coral<rt>珊瑚虫</rt></ruby>”或“<ruby>Bisque<rt>贝类浓汤</rt></ruby>”。幸好,他们决定使用 Ruby,因为它就像 pearl 一样,是一种珍贵的宝石。此外,<ruby>Ruby<rt>红宝石</rt></ruby> 还是 7 月的生辰石,而 <ruby>Pearl<rt>珍珠</rt></ruby> 则是 6 月的生辰石,采用了类似 C++ 和 C# 的隐喻,暗示着她们是改进自前辈的编程语言。(LCTT 译注:Perl 和 Pearl 发音相同,所以也常以“珍珠”来借喻 Perl;shell 是操作系统提供的用户界面,这里指的是命令行界面;更多有关生辰石的[信息](https://zh.wikipedia.org/zh-hans/%E8%AA%95%E7%94%9F%E7%9F%B3)。)
|
||||
|
||||
### Ruby 西渐
|
||||
|
||||
Ruby 在日本的普及很快。1995 年 Ruby 刚刚发布后不久后,松本就被一家名为 Netlab 的日本软件咨询财团(全名 Network Applied Communication Laboratory)雇用,并全职为 Ruby 工作。到 2000 年时,在 Ruby 发布仅仅 5 年后,Ruby 在日本的流行度就超过了 Python。可这时的 Ruby 才刚刚进入英语国家。虽然从 Ruby 的诞生之初就存在讨论它的日语邮件列表,但是英语的邮件列表直到 1998 年才建立起来。而且起初英语的邮件列表是用于日本的 Ruby 狂热者用英语交流的,但这一情况随着 Ruby 的普及而逐渐得以改变。
|
||||
Ruby 在日本的普及很快。1995 年 Ruby 刚刚发布后不久后,松本就被一家名为 Netlab 的日本软件咨询财团(全名 Network Applied Communication Laboratory)雇用,并全职为 Ruby 工作。到 2000 年时,在 Ruby 发布仅仅 5 年后,Ruby 在日本的流行度就超过了 Python。可这时的 Ruby 才刚刚进入英语国家。虽然从 Ruby 的诞生之初就存在讨论它的日语邮件列表,但是英语的邮件列表直到 1998 年才建立起来。起初,在英语的邮件列表中交流的大多是日本的 Ruby 狂热者,可随着 Ruby 在西方的逐渐普及而得以改变。
|
||||
|
||||
在 2000 年,Dave Thomas 出版了第一本涵盖 Ruby 的英文书籍《Programming Ruby》。因为它的封面上画着一把锄头,所以这本书也被称为锄头书。这是第一次向身处西方的程序员们介绍了 Ruby。就像在日本那样,Ruby 的普及很快,到 2002 年时,英语的 Ruby 邮件列表的通信超过了原来的日语邮件列表。
|
||||
在 2000 年,Dave Thomas 出版了第一本涵盖 Ruby 的英文书籍《Programming Ruby》。因为它的封面上画着一把锄头,所以这本书也被称为锄头书。这是第一次向身处西方的程序员们介绍了 Ruby。就像在日本那样,Ruby 的普及很快,到 2002 年时,英语的 Ruby 邮件列表的通信量就超过了日语邮件列表。
|
||||
|
||||
时间来到了 2005 年,Ruby 更流行了,但它仍然不是主流的编程语言。然而,Ruby on Rails 的发布让一切都不一样了。Ruby on Rails 是 Ruby 的“杀手级应用”,没有别的什么项目能比它更推动 Ruby 的普及了。在 Ruby on Rails 发布后,人们对 Ruby 的兴趣爆发式的增长,看看 TIOBE 监测的语言排行:
|
||||
|
||||
![][3]
|
||||
|
||||
有时人们开玩笑的说,Ruby 程序全是基于 Ruby-on-Rails 的网站。虽然这听起来就像是 Ruby on Rails 占领了整个 Ruby 社区,但在一定程度上,这是事实。因为 Ruby 被人所熟知是因为它是人们写 Rails 应用时用的语言。Rails 欠 Ruby 的和 Ruby 欠 Rails 的一样多。
|
||||
有时人们开玩笑的说,Ruby 程序全是基于 Ruby-on-Rails 的网站。虽然这听起来就像是 Ruby on Rails 占领了整个 Ruby 社区,但在一定程度上,这是事实。因为编写 Rails 应用时使用的语言正是 Ruby。Rails 欠 Ruby 的和 Ruby 欠 Rails 的一样多。
|
||||
|
||||
Ruby 的设计哲学也深深地影响了 Rails 的设计与开发。Rails 之父 David Heinemeier Hansson 常常提起他第一次与 Ruby 的接触的情形,那简直就是一次传教。他说,那种经历简直太有感召力了,让他感受到要为松本的杰作(指 Ruby)“传教”的使命。[^3] 对于 Hansson 来说,Ruby 的灵活性简直就是对 Python 或 Java 语言中自上而下的设计哲学的反抗。他很欣赏 Ruby 这门能够信任自己的语言,Ruby 赋予了他自由选择<ruby>程序表达方式<rt>express his programs</rt></ruby>的权力。
|
||||
|
||||
就像松本那样,Hansson 声称他创造 Rails 时因为对现状的不满并想让自己能更开心。他也认同让程序员更快乐高于一切的观点,所以检验 Rails 是否需要添加一项新特性的标准是“<ruby>更灿烂的笑容标准<rt>The Principle of The Bigger Smile</rt></ruby>”。什么功能能让 Hansson 更开心就给 Rails 添加什么。因此,Rails 中包括了很多非正统的功能,例如 “Inflector” 类和 `Time` 扩展(“Inflector”类试图将单个类的名字映射到多个数据库表的名字;`Time` 扩展允许程序员使用 `2.days.ago` 这样的表达式)。可能会有人觉得这些功能太奇怪了,但 Rails 的成功表明它的确能让很多人的生活得更快乐。
|
||||
|
||||
因此,虽然 Rails 看起来是一个偶然使 Ruby 更流行的应用,但事实上它体现了 Ruby 的很多核心准则。此外,很难看到使用其他语言开发的 Rails,因为 Rails 的实现依赖于 Ruby 中<ruby>类似于宏的类方法调用<rt>macro-like class method calls</rt></ruby>来实现模型关联这样的功能。一些人认为这么多的 Ruby 开发需要基于 Ruby on Rails 是 Ruby 生态不健康的表现,但 Ruby 和 Ruby on Rails 结合的如此紧密并不是没有道理的。
|
||||
因此,虽然 Rails 的火热带动了 Ruby 的普及看起来是一个偶然,但事实上 Rails 体现了 Ruby 的很多核心准则。此外,很难看到使用其他语言开发的 Rails,正是因为 Rails 的实现依赖于 Ruby 中<ruby>类似于宏的类方法调用<rt>macro-like class method calls</rt></ruby>来实现模型关联这样的功能。一些人认为这么多的 Ruby 开发需要基于 Ruby on Rails 是 Ruby 生态不健康的表现,但 Ruby 和 Ruby on Rails 结合的如此紧密并不是没有道理的。
|
||||
|
||||
### Ruby 之未来
|
||||
|
||||
人们似乎对 Ruby(及 Ruby on Rails)是否正在消亡有着异常的兴趣。早在 2011 年,Stack Overflow 和 Quora 上就充斥着程序员在咨询“如果几年后不再使用 Ruby 那么现在是否有必要学它”的话题。这些担忧对 Ruby 并非没有道理,根据 TIOBE 指数和 Stack Overflow 趋势,Ruby 和 Ruby on Rails 的人气一直在萎缩,虽然它也曾是热门新事物,但在更新更热的框架面前它已经黯然失色。
|
||||
|
||||
一种解释这种趋势的理论是程序员们正在舍弃动态类型的语言转而选择静态类型的。TIOBE 指数的趋势中可以看出对软件质量的需求在上升,这使得出现在运行时的异常变得难以接受。他们引用 TypeScript 来说明这一趋势,TypeScript 是 JavaScript 的全新版本,而创造它的目的正是为了保证客户端运行的代码能受益于编译所提供的安全保障。
|
||||
一种解释这种趋势的理论是程序员们正在舍弃动态类型的语言转而选择静态类型的。TIOBE 指数的趋势中可以看出对软件质量的需求在上升,这意味着出现在运行时的异常变得难以接受。他们引用 TypeScript 来说明这一趋势,TypeScript 是 JavaScript 的全新版本,而创造它的目的正是为了保证客户端运行的代码能受益于编译所提供的安全保障。
|
||||
|
||||
我认为另一个更可能的原因是比起 Ruby on Rails 推出的时候,现在存在着更多有竞争力的框架。2005 年它刚刚发布的时候,还没有那么多用于创建 Web 程序的框架,其主要的替代者还是 Java。可在今天,你可以使用为 Go、Javascript 或者 Python 开发的各种优秀的框架,而这还仅仅是主流的选择。Web 的世界似乎正走向更加分布式的结构,与其使用一块代码来完成从数据库读取到页面渲染所有事务,不如将事务拆分到多个组件,其中每个组件专注于一项事务并将其做到最好。在这种趋势下,Rails 相较于那些专攻于 JavaScript 前端通信的 JSON API 就显得过于宽泛和臃肿。
|
||||
我认为另一个更可能的原因是比起 Ruby on Rails 推出的时候,现在存在着更多有竞争力的框架。2005 年它刚刚发布的时候,还没有那么多用于创建 Web 程序的框架,其主要的替代者还是 Java。可在今天,你可以使用为 Go、Javascript 或者 Python 开发的各种优秀的框架,而这还仅仅是主流的选择。Web 的世界似乎正走向更加分布式的结构,与其使用一块代码来完成从数据库读取到页面渲染所有事务,不如将事务拆分到多个组件,其中每个组件专注于一项事务并将其做到最好。在这种趋势下,Rails 相较于那些专攻于 JavaScript 前端通信的 JSON API 就显得过于宽泛和臃肿。
|
||||
|
||||
总而言之,我们有理由对 Ruby 的未来持乐观态度。因为不管是 Ruby 还是 Rails 的开发都还很活跃。松本和其他的贡献者们都在努力开发 Ruby 的第三个主要版本。新的版本将比现在的版本快上 3 倍,以减轻制约着 Ruby 发展的性能问题。虽然从 2005 年起,越来越多的 Web 框架被开发出来,但这并不意味着 Ruby on Rails 就失去了其生存空间。Rails 是一个富有大量功能的成熟的工具,对于一些特定类型的应用开发一直是非常好的选择。
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
关于团队敏捷开发实践的 6 个常见问题
|
||||
======
|
||||
|
||||
> 专家回答了敏捷实践如何帮助团队更有效的 6 个常见问题。
|
||||
|
||||

|
||||
|
||||
”有问题么?“
|
||||
|
||||
你可能听过演讲者在演讲结束的时候提出这个问题。这是演讲中最重要的部分 —— 毕竟,你不仅仅是听讲座, 而是参加讨论和社群交流。
|
||||
|
||||
最近,我有机会听到我的同伴 Red Hatters 给当地一所大学的一群技术型学生做一个名为 “[敏捷实践][1]” 的讲座。讲座中有软件工程师 Tomas Tomecek 和敏捷开发的从业者 Fernando Colleone 、Pavel Najman 合作解释了敏捷开发方法的基础,并展示最佳实践在日常活动中的应用。
|
||||
|
||||
知道了学生们参加这个课程是为了了解什么是敏捷实践以及如何将其应用于项目,我想知道学生们的问题会与我作为敏捷从业者在 Red Hat 每天听到的问题相比有什么不同。结果学生的疑问和我的同事们如出一辙。这些问题都直指敏捷实践的核心。
|
||||
|
||||
### 1、完美的团队规模是多大?
|
||||
|
||||
学生们想知道一个小团队和一个大团队的规模是多少。这个问题与任何曾经合作过做项目的人都是相关的。根据 Tomas 作为技术领导的经验,12 个人从事的项目被认为是一个大型团队。现实中,团队规模通常与生产力没有直接关系。在有些时候,在一个地方或同一个时区的小团队也许会比一个成员分布在满世界的大团队更具有生产力。最终,该讲座建议理想的团队大小大概是 5 个人(正如 scrum 开发方法的 7,+-2)。
|
||||
|
||||
### 2、团队会面临哪些实际挑战?
|
||||
|
||||
演讲者比较了由本地团队组成的项目(团队成员都是一个办公室的,或者相邻近的人)与分散型的团队(位于不同时区)。当项目需要团队成员之间密切合作时,工程师更喜欢本地的团队,因为时间差异造成的延迟可能会破坏软件开发的“流”。同时,分散型团队可以将可能不适用与当地项目但适用于某些开发用例的技能集合在一起。此外,还有各种最佳方法可用于改进分散型团队中的合作方式。
|
||||
|
||||
### 3、整理堆积的工作需要多少时间?
|
||||
|
||||
因为这是一个对于新学习敏捷的学生的介绍性质的演讲,演讲者着重把 [Scrum][2] 和 [Kanban][3] 作为介绍敏捷开发的方法。他们使用 Scrum 框架来作为说明软件编写的方法,并且用 Kanban 作为工作规划和沟通的系统。关于需要多少时间来整理项目堆积的工作,演讲者解释说并没有固定的准则,相对的,实践出真知:在开发的早期阶段,当一个崭新的项目 —— 特别如果团队里有新人 —— 每周可能会花费数个小时在整理工作上。随着时间推移和不断地练习,会越来越高效。
|
||||
|
||||
### 4、产品负责人是否是必要的? 他们扮演什么样的角色?
|
||||
|
||||
产品负责人会帮助团队更方便的拓展,然而,职位名称并不重要,重要的是你的团队中有人能够传递用户的意愿。在许多团队中,特别是在大型团队中从事单个任务的团队,首席工程师就可以担任产品负责人。
|
||||
|
||||
### 5、建议使用哪些敏捷开发的工具?使用 Scrum 或 Kanban 做敏捷开发的时候必须用特定的软件么?
|
||||
|
||||
尽管使用一些专业软件例如 Jira 或 Trello 会很有帮助,特别是在与大量从事大型企业项目的工作者合作时,但它们不是必需的。Scrum 和 Kanban 可以使用像纸卡这样简单的工具完成。关键是在团队中要有一个清晰的信息来源和紧密的交流。推荐两个优秀的 kanban 开源工具 [Taiga][4] 和 [Wekan][5]。更多信息请查看 [Trello 的 5 个开源替代品][6] 和 [敏捷团队的最好的 7 个开源项目管理工具][7] 。
|
||||
|
||||
### 6、学生如何在学校项目中使用敏捷开发技术?
|
||||
|
||||
演讲者鼓励学生使用 kanban 在项目结束前使用可视化和概述要完成的任务。关键是要创建一个公共板块,这样整个团队就可以看到项目的状态。通过使用 kanban 或者类似的高度可视化的策略,学生不会在项目后期才发现个别成员没有跟上进度。
|
||||
|
||||
Scrum 实践比如 sprints 和 daily standups 也是确认每个人都在进步以及项目的各个部分最终会一起发挥作用的绝佳方法。定期检查和信息共享也至关重要。更多关于 Scrum 的信息,访问 [什么是 scrum?][8] 。
|
||||
|
||||
牢记 Kanban 和 Scrum 只是敏捷开发中众多框架和工具中的两个而已。它们可能不是应对每一种情况的最佳方法。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/3/agile-mindset
|
||||
|
||||
作者:[Dominika Bula][a]
|
||||
译者:[lixinyuxx](https://github.com/lixinxyuxx)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/dominika
|
||||
[1]:http://zijemeit.cz/sessions/agile-in-practice/
|
||||
[2]:https://www.scrum.org/resources/what-is-scrum
|
||||
[3]:https://en.wikipedia.org/wiki/Kanban
|
||||
[4]:https://taiga.io/
|
||||
[5]:https://wekan.github.io/
|
||||
[6]:https://opensource.com/alternatives/trello
|
||||
[7]:https://opensource.com/article/18/2/agile-project-management-tools
|
||||
[8]:https://opensource.com/resources/scrum
|
||||
@@ -3,7 +3,7 @@ Flatpak 新手指南
|
||||
|
||||

|
||||
|
||||
不久前,我们介绍 Ubuntu 推出的 [**Snaps**][1]。Snaps 是由 Canonical 公司为 Ubuntu 开发的,并随后移植到其他的 Linux 发行版,如 Arch、Gentoo、Fedora 等等。由于一个 snap 包中含有软件的二进制文件和其所需的所有依赖和库,所以可以在无视软件版本、在任意 Linux 发行版上安装软件。和 Snaps 类似,还有一个名为 **Flatpak** 的工具。也许你已经知道,为不同的 Linux 发行版打包并分发应用时已经多么费时又复杂的工作,因为不同的 Linux 发行版的库不同,库的版本也不同。现在,Flatpak 作为分发桌面应用的新框架可以让开发者完全摆脱这些负担。开发者只需构建一个 Flatpak app 就可以在多种发行版上安装使用。这真是又酷又棒!
|
||||
以前,我们介绍 Ubuntu 推出的 [Snaps][1]。Snaps 是由 Canonical 公司为 Ubuntu 开发的,并随后移植到其他的 Linux 发行版,如 Arch、Gentoo、Fedora 等等。由于一个 snap 包中含有软件的二进制文件和其所需的所有依赖和库,所以可以在无视软件版本、在任意 Linux 发行版上安装软件。和 Snaps 类似,还有一个名为 Flatpak 的工具。也许你已经知道,为不同的 Linux 发行版打包并分发应用是一件多么费时又复杂的工作,因为不同的 Linux 发行版的库不同,库的版本也不同。现在,Flatpak 作为分发桌面应用的新框架可以让开发者完全摆脱这些负担。开发者只需构建一个 Flatpak app 就可以在多种发行版上安装使用。这真是又酷又棒!
|
||||
|
||||
用户也完全不用担心库和依赖的问题了,所有的东西都和 app 打包在了一起。更重要的是 Flatpak app 们都自带沙箱,而且与宿主操作系统的其他部分隔离。对了,Flatpak 还有一个很棒的特性,它允许用户在同一个系统中安装同一应用的多个版本,例如 VLC 播放器的 2.1 版、2.2 版、2.3 版。这使开发者测试同一个软件的多个版本变得更加方便。
|
||||
|
||||
@@ -14,56 +14,54 @@ Flatpak 新手指南
|
||||
Flatpak 可以在大多数的主流 Linux 发行版上安装使用,如 Arch Linux、Debian、Fedora、Gentoo、Red Hat、Linux Mint、openSUSE、Solus、Mageia 还有 Ubuntu。
|
||||
|
||||
在 Arch Linux 上,使用这一条命令来安装 Flatpak:
|
||||
|
||||
```
|
||||
$ sudo pacman -S flatpak
|
||||
|
||||
```
|
||||
|
||||
对于 Debian 用户,Flatpak 被收录进 Stretch 或更新版本的默认软件源中。要安装 Flatpak,直接执行:
|
||||
对于 Debian 用户,Flatpak 被收录进 Stretch 或之后版本的默认软件源中。要安装 Flatpak,直接执行:
|
||||
|
||||
```
|
||||
$ sudo apt install flatpak
|
||||
|
||||
```
|
||||
|
||||
对于 Fedora 用户,Flatpak 是发行版默认安装的软件。你可以直接跳过这一步。
|
||||
|
||||
如果因为任何原因没有安装的话,可以执行:
|
||||
如果因为某种原因没有安装的话,可以执行:
|
||||
|
||||
```
|
||||
$ sudo dnf install flatpak
|
||||
|
||||
```
|
||||
|
||||
对于 RHEL 7 用户,安装 Flatpak 的命令为:
|
||||
|
||||
```
|
||||
$ sudo yum install flatpak
|
||||
|
||||
```
|
||||
|
||||
如果你在使用 Linux Mint 18.3,那么 Flatpat 也随系统默认安装,所以跳过这一步。
|
||||
|
||||
在 openSUSE Tumbleweed 中,使用 Zypper 包管理来安装 Flatpak:
|
||||
|
||||
```
|
||||
$ sudo zypper install flatpak
|
||||
|
||||
```
|
||||
|
||||
而 Ubuntu 需要添加下面的软件源再安装 Flatpak,命令如下:
|
||||
|
||||
```
|
||||
$ sudo add-apt-repository ppa:alexlarsson/flatpak
|
||||
|
||||
$ sudo apt update
|
||||
|
||||
$ sudo apt install flatpak
|
||||
|
||||
```
|
||||
|
||||
Gnome 提供了一个 Flatpak 插件,安装它就可以使用图形界面来安装 Flatpak app 了。插件的安装命令为:
|
||||
|
||||
```
|
||||
$ sudo apt install gnome-software-plugin-flatpak
|
||||
|
||||
```
|
||||
|
||||
如果你是用发行版没有在上述的说明里,请你参考官方[**安装指南**][2]。
|
||||
如果你是用发行版没有在上述的说明里,请你参考官方[安装指南][2]。
|
||||
|
||||
### 开始使用 Flatpak
|
||||
|
||||
@@ -75,55 +73,54 @@ $ sudo apt install gnome-software-plugin-flatpak
|
||||
|
||||
#### 添加软件仓库
|
||||
|
||||
**添加 Flathub 仓库:**
|
||||
**添加 Flathub 仓库:**
|
||||
|
||||
Flathub 是一个包含了几乎所有 flatpak 应用的仓库。运行这条命令来启用它:
|
||||
|
||||
**Flathub** 是一个包含了几乎所有 flatpak 应用的仓库。运行这条命令来启用它:
|
||||
```
|
||||
$ sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
|
||||
|
||||
```
|
||||
|
||||
对于流行应用来说,Flathub 已经可以满足需求。如果你想试试 GNOME 应用的话,可以添加 GNOME 的仓库。
|
||||
|
||||
**添加 GNOME 仓库:**
|
||||
**添加 GNOME 仓库:**
|
||||
|
||||
GNOME 仓库包括了所有的 GNOME 核心应用,它提供了两种版本:<ruby>**稳定版**<rt>stable</rt></ruby>和<strong><ruby>**每日构建版**<rt>nightly</rt></ruby></strong>。
|
||||
GNOME 仓库包括了所有的 GNOME 核心应用,它提供了两种版本:<ruby>稳定版<rt>stable</rt></ruby>和<strong><ruby>每日构建版<rt>nightly</rt></ruby></strong>。
|
||||
|
||||
使用下面的命令来添加 GNOME 稳定版仓库:
|
||||
|
||||
```
|
||||
$ wget https://sdk.gnome.org/keys/gnome-sdk.gpg
|
||||
|
||||
$ sudo flatpak remote-add --gpg-import=gnome-sdk.gpg --if-not-exists gnome-apps https://sdk.gnome.org/repo-apps/
|
||||
|
||||
```
|
||||
|
||||
需要注意的是,GNOME 稳定版仓库中的应用需要 **3.20 版本的 org.gnome.Platform 运行时环境**。
|
||||
|
||||
安装稳定版运行时环境,请执行:
|
||||
|
||||
```
|
||||
$ sudo flatpak remote-add --gpg-import=gnome-sdk.gpg gnome https://sdk.gnome.org/repo/
|
||||
|
||||
```
|
||||
|
||||
如果想使用每日构建版的 GNOME 仓库,使用如下的命令:
|
||||
|
||||
```
|
||||
$ wget https://sdk.gnome.org/nightly/keys/nightly.gpg
|
||||
|
||||
$ sudo flatpak remote-add --gpg-import=nightly.gpg --if-not-exists gnome-nightly-apps https://sdk.gnome.org/nightly/repo-apps/
|
||||
|
||||
```
|
||||
|
||||
同样,每日构建版的 GNOME 仓库也需要 **org.gnome.Platform 运行时环境的每日构建版本**。
|
||||
|
||||
执行下面的命令安装每日构建版的运行时环境:
|
||||
|
||||
```
|
||||
$ sudo flatpak remote-add --gpg-import=nightly.gpg gnome-nightly https://sdk.gnome.org/nightly/repo/
|
||||
|
||||
```
|
||||
|
||||
#### 查看软件仓库
|
||||
|
||||
要查看已经添加的软件仓库,执行下面的命令:
|
||||
|
||||
```
|
||||
$ flatpak remotes
|
||||
Name Options
|
||||
@@ -132,7 +129,6 @@ gnome system
|
||||
gnome-apps system
|
||||
gnome-nightly system
|
||||
gnome-nightly-apps system
|
||||
|
||||
```
|
||||
|
||||
如你所见,上述命令会列出你添加到系统中的软件仓库。此外,执行结果还表明了软件仓库的配置是<ruby>用户级<rt>per-user</rt></ruby>还是<ruby>系统级<rt>system-wide</rt></ruby>。
|
||||
@@ -140,121 +136,122 @@ gnome-nightly-apps system
|
||||
#### 删除软件仓库
|
||||
|
||||
要删除软件仓库,例如 flathub,用这条命令:
|
||||
|
||||
```
|
||||
$ sudo flatpak remote-delete flathub
|
||||
|
||||
```
|
||||
|
||||
这里的 **flathub** 是软件仓库的名字。
|
||||
这里的 flathub 是软件仓库的名字。
|
||||
|
||||
#### 安装 Flatpak 应用
|
||||
|
||||
这一节,我们将学习如何安装 flatpak 应用。
|
||||
|
||||
要安装一个应用,只要一条命令就能完成:
|
||||
|
||||
```
|
||||
$ sudo flatpak install flathub com.spotify.Client
|
||||
|
||||
```
|
||||
|
||||
所有的稳定版 GNOME 软件仓库中的应用,都使用“stable”作为版本名。
|
||||
|
||||
例如,想从稳定版 GNOME 软件仓库中安装稳定版 **Evince**,就执行:
|
||||
例如,想从稳定版 GNOME 软件仓库中安装稳定版 Evince,就执行:
|
||||
|
||||
```
|
||||
$ sudo flatpak install gnome-apps org.gnome.Evince stable
|
||||
|
||||
```
|
||||
|
||||
所有的每日构建版 GNOME 仓库中的应用,都使用“master”作为版本名。
|
||||
|
||||
例如,要从每日构建版 GNOME 软件仓库中安装 gedit 的每次构建版本,就执行:
|
||||
|
||||
```
|
||||
$ sudo flatpak install gnome-nightly-apps org.gnome.gedit master
|
||||
|
||||
```
|
||||
|
||||
如果不希望应用安装在<ruby>系统级<rt>system-wide</rt></ruby>,而只安装在<ruby>用户级<rt>per-user</rt></ruby>,那么你可以这样安装软件:
|
||||
|
||||
```
|
||||
$ flatpak install --user <name-of-app>
|
||||
|
||||
```
|
||||
|
||||
所有的应用都会被存储在 **$HOME/.var/app/** 目录下.
|
||||
所有的应用都会被存储在 `$HOME/.var/app/` 目录下.
|
||||
|
||||
```
|
||||
$ ls $HOME/.var/app/
|
||||
com.spotify.Client
|
||||
|
||||
```
|
||||
|
||||
#### 执行 Flatpak 应用
|
||||
|
||||
你可以直接使用<ruby>应用启动器<rt>application launcher</rt></ruby>来运行已安装的 Flatpak 应用。如果你想从命令行启动的话,以 Spotify 为例,执行下面的命令:
|
||||
|
||||
```
|
||||
$ flatpak run com.spotify.Client
|
||||
|
||||
```
|
||||
|
||||
#### 列出已安装的 Flatpak 应用
|
||||
|
||||
要查看已安装的应用程序和运行时环境,执行:
|
||||
|
||||
```
|
||||
$ flatpak list
|
||||
|
||||
```
|
||||
|
||||
想只查看已安装的应用,那就用这条命令:
|
||||
|
||||
```
|
||||
$ flatpak list --app
|
||||
|
||||
```
|
||||
|
||||
如果想查询已添加的软件仓库中的可安装程序和可安装的运行时环境,使用命令:
|
||||
|
||||
```
|
||||
$ flatpak remote-ls
|
||||
|
||||
```
|
||||
|
||||
只列出可安装的应用程序的命令是:
|
||||
|
||||
```
|
||||
$ flatpak remote-ls --app
|
||||
|
||||
```
|
||||
|
||||
查询指定远程仓库中的所有可安装的应用程序和运行时环境,这里以 **gnome-apps** 为例,执行命令:
|
||||
查询指定远程仓库中的所有可安装的应用程序和运行时环境,这里以 gnome-apps 为例,执行命令:
|
||||
|
||||
```
|
||||
$ flatpak remote-ls gnome-apps
|
||||
|
||||
```
|
||||
|
||||
只列出可安装的应用程序,这里以 **flathub** 为例:
|
||||
只列出可安装的应用程序,这里以 flathub 为例:
|
||||
|
||||
```
|
||||
$ flatpak remote-ls flathub --app
|
||||
|
||||
```
|
||||
|
||||
#### 更新应用程序
|
||||
|
||||
更新所有的 Flatpak 应用程序,执行:
|
||||
|
||||
```
|
||||
$ flatpak update
|
||||
|
||||
```
|
||||
|
||||
更新指定的 Flatpak 应用程序,执行:
|
||||
|
||||
```
|
||||
$ flatpak update com.spotify.Client
|
||||
|
||||
```
|
||||
|
||||
#### 获取应用详情
|
||||
|
||||
执行下面的命令来查看已安装应用程序的详细信息:
|
||||
|
||||
```
|
||||
$ flatpak info io.github.mmstick.FontFinder
|
||||
|
||||
```
|
||||
|
||||
输出样例:
|
||||
|
||||
```
|
||||
Ref: app/io.github.mmstick.FontFinder/x86_64/stable
|
||||
ID: io.github.mmstick.FontFinder
|
||||
@@ -268,28 +265,27 @@ Parent: dbff9150fce9fdfbc53d27e82965010805f16491ec7aa1aa76bf24ec1882d683
|
||||
Location: /var/lib/flatpak/app/io.github.mmstick.FontFinder/x86_64/stable/07164e84148c9fc8b0a2a263c8a468a5355b89061b43e32d95008fc5dc4988f4
|
||||
Installed size: 2.5 MB
|
||||
Runtime: org.gnome.Platform/x86_64/3.28
|
||||
|
||||
```
|
||||
|
||||
#### 删除应用程序
|
||||
|
||||
要删除一个 Flatpak 应用程序,这里以 spotify 为例,执行:
|
||||
|
||||
```
|
||||
$ sudo flatpak uninstall com.spotify.Client
|
||||
|
||||
```
|
||||
|
||||
如果你需要更多信息,可以参考 Flatpak 的帮助。
|
||||
|
||||
```
|
||||
$ flatpak --help
|
||||
|
||||
```
|
||||
|
||||
到此,希望你对 Flatpak 有了一些基础了解。
|
||||
|
||||
如果你觉得这篇指南有些帮助,请在你的社交媒体上分享它来支持 OSTechNix。
|
||||
如果你觉得这篇指南有些帮助,请在你的社交媒体上分享它来支持我们。
|
||||
|
||||
稍后还有更多精彩内容,尽情期待~
|
||||
稍后还有更多精彩内容,敬请期待~
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@@ -299,7 +295,7 @@ via: https://www.ostechnix.com/flatpak-new-framework-desktop-applications-linux/
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[wwhio](https://github.com/wwhio)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
67
published/20180507 Modularity in Fedora 28 Server Edition.md
Normal file
67
published/20180507 Modularity in Fedora 28 Server Edition.md
Normal file
@@ -0,0 +1,67 @@
|
||||
Fedora 28 服务器版的模块化
|
||||
========
|
||||
|
||||

|
||||
|
||||
### 什么是模块化
|
||||
|
||||
所有开源发行版都面临的一个经典难题是“太快/太慢”的问题。用户安装操作系统是为了能够使用其应用程序。像 Fedora 这样的全面的发行版在大量可用软件方面有其优势和劣势。虽然有用户想要的软件包,但可能无法使用其所需的版本。以下是<ruby>模块化<rt>Modularity</rt></ruby>如何帮助解决该问题。
|
||||
|
||||
对于某些用户,Fedora 有时升级得太快。其快速发布周期以及尽可能提供最新稳定软件的愿望可能导致与应用程序的兼容性下降。如果因为 Fedora 将 Web 框架升级为不兼容的版本而导致用户无法运行 Web 应用程序,则会非常令人沮丧。对“太快”问题的经典回答是“Fedora 应该有一个 LTS 版本。”然而,这种方法只能解决问题的一半,并使这个难题的另一面变得更糟。
|
||||
|
||||
有时候 Fedora 对某些用户而言又升级速度太慢。例如,Fedora 的发布可能与其它想要的软件的发布时间不匹配。一旦 Fedora 版本宣布稳定,打包者必须遵守 [稳定更新政策][1] 并且不能在系统中引入不兼容的更改。
|
||||
|
||||
Fedora 的模块化从两个方面解决了这个问题。Fedora 仍将根据其传统政策发布标准版本。但是,它还将提供一组模块给出流行软件的限定替代版本。那些处于“太快”阵营的人仍然可以享受 Fedora 的新内核和其它通用平台增强功能。此外,他们仍然可以访问支持其应用程序的旧框架或工具链。
|
||||
|
||||
此外,那些喜欢更新潮一些的用户可以访问比发布时更新的软件。
|
||||
|
||||
### 模块化不是什么?
|
||||
|
||||
模块化不是 <ruby>[软件集合][2]<rt>Software Collections</rt></ruby> 的直接替代品。这两种技术试图解决许多相同的问题,但有明显的差异。
|
||||
|
||||
软件集合可以在系统上并行安装不同版本的软件包。但是,它们的缺点是每份安装包都存在于文件系统上的它们自己的命名空间里面。此外,需要告诉每个依赖它们的应用程序在哪里找到它们。
|
||||
|
||||
使用模块化,系统上只存在一个版本的软件包,但用户可以选择哪个版本。优点是该版本位于系统的标准位置。该程序包不需要对依赖它的应用程序进行特殊更改。来自用户研究的反馈表明,大多数用户实际上并不依赖于并行安装。容器化和虚拟化解决了这个问题。
|
||||
|
||||
### 为什么不干脆使用容器化?
|
||||
|
||||
这是另一个常见问题。为什么用户在可以使用容器时还需要模块?答案是,人们仍然需要维护容器中的软件。 模块为那些用户不需要自己维护、更新和修补的容器提供预打包的内容。这就是 Fedora 如何利用发行版的传统价值并将其转移到新的容器化的世界。
|
||||
|
||||
以下是模块化如何为 Node.js 和 Review Board 的用户解决问题的示例。
|
||||
|
||||
### Node.js
|
||||
|
||||
许多读者可能熟悉 Node.js,这是一个流行的服务器端 JavaScript 运行时环境。Node.js 采用偶数/奇数版本策略。它的社区支持偶数版本(6.x、8.x、10.x 等)约 30 个月。同时,他们也支持奇数版本,基本上是 9 个月的开发者预览版。
|
||||
|
||||
由于这个周期的原因,Fedora 在其稳定的仓库中只携带最新的偶数版本的 Node.js。它完全避免了奇数版本,因为它们的生命周期比 Fedora 短,并且通常与 Fedora 发布周期不一致。对于一些希望获得最新和最大增强功能的 Fedora 用户来说,这并不合适。
|
||||
|
||||
由于模块化,Fedora 28 不是提供了一个版本,而是提供了三个版本的 Node.js,以满足开发人员和稳定部署的需求。Fedora 28 的传统仓库带有 Node.js 8.x。此版本是发布时最新的长期稳定版本。模块仓库(默认情况下在 Fedora 28 Server 版本上可用)也使得更旧的 Node.js 6.x 版本和更新的 Node.js 9.x 开发版本可用。
|
||||
|
||||
另外,Node.js 在 Fedora 28 之后几天发布了 10.x 上游版本。过去,想要部署该版本的用户必须等到 Fedora 29,或者使用来自 Fedora 之外的源代码。但是,再次感谢模块化,Node.js 10.x 已经在 Fedora 28 的 Modular Updates-Testing 仓库中 [可用][3] 了。
|
||||
|
||||
### Review Board
|
||||
|
||||
Review Board 是一个流行的 Django 应用程序,用于执行代码审查。Fedora 从 Fedora 13 到 Fedora 21 都包括了 Review Board。此时,Fedora 转移到了 Django 1.7。由于 Django 数据库支持的向后兼容性在不断变化,而 Review Board 无法跟上。它在 RHEL / CentOS 7 的 EPEL 仓库中仍然存在,而仅仅是因为这些发行版的版本幸运地被冻结在 Django 1.6上。尽管如此,它在 Fedora 的时代显然已经过去了。
|
||||
|
||||
然而,随着模块化的出现,Fedora 能够再次将旧的 Django 作为非默认模块流发布。因此,Review Board 已作为一个模块在 Fedora 上恢复了。Fedora 承载了来自上游的两个受支持的版本:2.5.x 和 3.0.x。
|
||||
|
||||
### 组合在一起
|
||||
|
||||
Fedora 一直为用户提供非常广泛的软件使用。Fedora 模块化现在为他们所需的软件版本提供了更深入的选择。接下来的几年对于 Fedora 来说将是非常令人兴奋的,因为开发人员和用户可以以新的和令人兴奋的(或旧的和令人兴奋的)方式组合他们的软件。
|
||||
|
||||
------
|
||||
|
||||
via: https://fedoramagazine.org/working-modules-fedora-28/
|
||||
|
||||
作者:[Stephen Gallagher][a]
|
||||
选题:[wxy](https://github.com/wxy)
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/sgallagh/
|
||||
[1]: https://fedoraproject.org/wiki/Updates_Policy#Stable_Releases
|
||||
[2]: https://www.softwarecollections.org/
|
||||
[3]: https://bodhi.fedoraproject.org/updates/FEDORA-MODULAR-2018-2b0846cb86
|
||||
|
||||
111
published/20180604 4 Firefox extensions worth checking out.md
Normal file
111
published/20180604 4 Firefox extensions worth checking out.md
Normal file
@@ -0,0 +1,111 @@
|
||||
4 个值得一提的 Firefox 扩展插件
|
||||
======
|
||||
|
||||
> 这些扩展可以使火狐更具生产力和使用乐趣。
|
||||
|
||||

|
||||
|
||||
自从大约 12 年前 Firefox(火狐浏览器)v2.0 推出以来, 我一直是它的用户。它不是那时最好的网络浏览器,但是总会有一个理由让我回到它:我最喜爱的浏览器扩展插件不能工作在其它浏览器上。
|
||||
|
||||
如今,我喜欢现下的 Firefox,因为它快速、可定制和开源,我也很欣赏那些体现了原开发人员从未想到过的想法的扩展插件:如果你想在没有鼠标的情况下浏览网页呢?如果你不喜欢盯着晚上从显示器里发出来的强光呢?如何在 YouTube 和其他视频托管网站上使用一个更专业的播放器来获得更好的性能和更多播放控制呢?如果你需要更复杂的方法来禁用跟踪器和加快加载页面,该怎么办?
|
||||
|
||||
幸运的是,这些问题都有答案,我将展现给你我最喜爱的扩展 —— 所有这些都是免费软件或开源的 (即,在 [GNU GPL][1]、[MPL][2] 或 [Apache][3] 许可帧下) ,它们可以使一个优秀的浏览器更优秀。
|
||||
|
||||
尽管术语<ruby>加载项<rt>add-on</rt></ruby>和<ruby>扩展<rt>extension</rt></ruby>的含义稍微不同,但我在本文中的使用不会区分它们。
|
||||
|
||||
### Tridactyl
|
||||
|
||||
![Tridactyl screenshot][5]
|
||||
|
||||
*Tridactyl 的新选项卡页面,展示了链接的指引。*
|
||||
|
||||
[Tridactyl][6] 使你能够在大多数浏览活动中使用键盘。它的灵感来自于现已不复存在的 [Vimperator][7] 和 [Pentadactyl][8],而它们受到了 [Vim][9] 的默认键绑定的启发。由于我已经习惯了 Vim 和其他命令行应用程序,我发现了它的功能类似于使用键值 `h/j/k/l` 进行导航,用 `f/F` 可以与超链接进行交互,而且创建自定义的键绑定和命令非常方便。
|
||||
|
||||
Tridactyl 最近刚刚实现了一个可选的本地信使(目前,仅适用于 GNU/Linux 和 Mac OSX),提供了更酷的功能。例如,有了它,你可以隐藏 Firefox 用户界面上的一些元素(以 Vimperator 和 Pentadactyl 的方式)、在外部程序中打开链接或当前页(我经常用 [mpv][10] 和 [youtube-dl][11] 播放视频)、通过按 `Ctrl-I`(或者任意你选择的组合键)用你喜爱的编辑器来编辑文本框的内容。
|
||||
|
||||
话虽如此,但要记住,这是一个相对早期的项目,细节可能还是很粗糙。另一方面,它的开发非常活跃,当你回顾它早期的缺陷时,未尝不是一种乐趣。
|
||||
|
||||
### Open With
|
||||
|
||||
![Open With Screenshot][13]
|
||||
|
||||
*Open With 提供的菜单。我可以用这里列出的一个外部程序打开当前页面。*
|
||||
|
||||
说到与外部程序的互动,有时能够用鼠标来做到这一点还是让人很高兴的。这是 [Open With][14] 的用武之地。
|
||||
|
||||
除了添加的上下文菜单(如屏幕截图所示)之外,你还可以通过单击加载项栏上的扩展图标来找到自己定义的命令。如[它在 Mozilla Add-ons 页面上][14] 的图标和描述所示,它主要是为了切换到其它的 web 浏览器,但我也可以轻松地将它与 mpv 和 youtube-dl 相配合。
|
||||
|
||||
它也提供了键盘快捷方式,但它们受到了严重限制。可以在扩展设置的下拉列表中选择的组合不超过三种。相反,Tridactyl 允许我将命令分配给几乎任何没有被 Firefox 所阻止的东西。没错,Open With 目前为鼠标而准备的。
|
||||
|
||||
### Stylus
|
||||
|
||||
![Stylus Screenshot][16]
|
||||
|
||||
*在这个屏幕截图中,我刚刚搜索并为当前正在浏览的 Stylus 的网站安装了一个黑暗主题。即使是弹出窗口也可以定制风格(称为 Deepdark Stylus)!*
|
||||
|
||||
[Stylus][17] 是一个用户样式管理器,这意味着可以通过编写自定义 CSS 规则并将其加载到 Stylus 中来更改任何网页的外观。如果你不懂 CSS,在如 [userstyles.org][18] 这样网站上有大量的其他人制作的样式。
|
||||
|
||||
现在,你可能会问,“这不就是 [Stylish][19] 么?” 你是对的!Stylus 是基于 Stylish 的,并提供了更多的改进:它不包含任何远程记录、尊重你的隐私,所有开发都是公开的(尽管 Stylish 仍在积极开发,我一直未能找到最新版本的源代码),而且它还支持 [UserCSS][20]。
|
||||
|
||||
UserCSS 是一种有趣的格式,尤其是对于开发人员来说。我已经为不同的网站写了几种用户样式(主要是黑暗主题,和为了提高可读性的调整),虽然 Stylus 的内部编辑器很好,我还是喜欢用 Neovim 编辑代码。为了做到这样我所需要做的就是用 “.user.css” 作为本地加载文件的后缀名,在 Stylus 里启动 “Live Reload” 选项,只要我在 Neovim 中保存文件就会应用所有的更改。它也支持远程 UserCSS 文件,因此,每当我将更改推送到 GitHub 或任何基于 git 的开发平台时,它们将自动对用户可用。(我提供了指向该文件的原始版本的链接,以便他们可以轻松地访问它。)
|
||||
|
||||
### uMatrix
|
||||
|
||||
![uMatrix Screenshot][22]
|
||||
|
||||
*uMatrix 的用户界面,显示当前访问过的网页的当前规则。*
|
||||
|
||||
Jeremy Garcia 在他发表在 Opensource.com 的[文章][23]中提到了一个优秀的拦截器 uBlock Origin。我想提请大家关注另一个由 [gorhill][24] 开发的扩展插件: uMatrix 。
|
||||
|
||||
[uMatrix][25] 允许你为网页上的某些请求设置拦截规则,可以通过点击该加载项的弹出窗口来切换(在上面的屏幕截图中可以看到)。这些请求的区别在于脚本的类别、脚本发起的请求、cookies、CSS 规则、图像、媒体、帧,和被 uMatrix 标记为“other” 的其它内容。例如,你可以设置全局规则,以便在默认情况下允许所有请求,并将特定的请求添加到黑名单中(更方便的方法),或在默认情况下阻止所有内容,并手动将某些请求列入白名单(更安全的方法)。如果你一直在使用 NoScript 或 RequestPolicy,你可以从它们 [导入][26] 你的白名单规则。
|
||||
|
||||
另外 uMatrix 支持 [hosts 文件][27],可用于阻止来自某些域的请求。不要与 uBlock Origin 所使用的筛选列表混淆,它使用的语法同 Adblock Plus 一样。默认情况下,uMatrix 会通过几个 hosts 文件阻止已知的分发广告、跟踪器和恶意软件的服务器,如果需要,你可以添加更多外部数据源。
|
||||
|
||||
那么你将选择哪一个:uBlock Origin 或 uMatrix ?就个人而言,我在电脑上两个都用,而只在安卓手机上用 uMatrix 。[据 gorhill 所说][28],两者之间存在某种重叠,但它们有不同的目标用户和目地。如果你想要的只是阻止跟踪器和广告的简单方法,uBlock Origine 是更好的选择;另一方面,如果你希望对网页在浏览器中可以执行或不能执行的操作进行精细的控制,即使需要一些时间来进行配置,并且可能会阻止某些网站如预期的工作,uMatrix 也是更好的选择。
|
||||
|
||||
### 结论
|
||||
|
||||
目前,这些是 Firefox 里我最喜欢的扩展。Tridactyl 通过依靠键盘和与外部程序交互,加快了浏览导航速度;Open With 能让我用鼠标在另外一个程序中打开页面;Stylus 是全面的用户样式管理器,对用户和开发人员都很有吸引力;uMatrix 本质上是 Firefox 的防火墙,可以用于过滤未知的请求。
|
||||
|
||||
尽管我基本上只是讨论了这些加载项的好处,但没有一个软件是完美的。如果你喜欢它们中的任何一个,并认为它们的某些方面可以改进,我建议你去它们的 Github 页面,并查看它们的贡献指南。通常情况下,自由开源软件的开发人员是欢迎错误报告和提交请求的。告诉你的朋友或道谢也是帮助开发者的好方法,特别是如果这些开发者是在业余时间从事他们的项目的话。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/6/firefox-open-source-extensions
|
||||
|
||||
作者:[Zsolt Szakács][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[lixinyuxx](https://github.com/lixinyuxx)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/zsolt
|
||||
[1]:https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
[2]:https://www.mozilla.org/en-US/MPL/
|
||||
[3]:https://www.apache.org/licenses/LICENSE-2.0
|
||||
[4]:/file/398411
|
||||
[5]:https://opensource.com/sites/default/files/uploads/tridactyl.png "Tridactyl's new tab page, showcasing link hinting"
|
||||
[6]:https://addons.mozilla.org/en-US/firefox/addon/tridactyl-vim/
|
||||
[7]:https://github.com/vimperator/vimperator-labs
|
||||
[8]:https://addons.mozilla.org/en-US/firefox/addon/pentadactyl/
|
||||
[9]:https://www.vim.org/
|
||||
[10]:https://mpv.io/
|
||||
[11]:https://rg3.github.io/youtube-dl/index.html
|
||||
[12]:/file/398416
|
||||
[13]:https://opensource.com/sites/default/files/uploads/openwith.png "A context menu provided by Open With. I can open the current page with one of the external programs listed here."
|
||||
[14]:https://addons.mozilla.org/en-US/firefox/addon/open-with/
|
||||
[15]:/file/398421
|
||||
[16]:https://opensource.com/sites/default/files/uploads/stylus.png "In this screenshot, I've just searched for and installed a dark theme for the site I'm currently on with Stylus. Even the popup has custom style (called Deepdark Stylus)!"
|
||||
[17]:https://addons.mozilla.org/en-US/firefox/addon/styl-us/
|
||||
[18]:https://userstyles.org/
|
||||
[19]:https://addons.mozilla.org/en-US/firefox/addon/stylish/
|
||||
[20]:https://github.com/openstyles/stylus/wiki/Usercss
|
||||
[21]:/file/398426
|
||||
[22]:https://opensource.com/sites/default/files/uploads/umatrix.png "The user interface of uMatrix, showing the current rules for the currently visited webpage."
|
||||
[23]:https://opensource.com/article/18/5/firefox-extensions
|
||||
[24]:https://addons.mozilla.org/en-US/firefox/user/gorhill/
|
||||
[25]:https://addons.mozilla.org/en-US/firefox/addon/umatrix
|
||||
[26]:https://github.com/gorhill/uMatrix/wiki/FAQ
|
||||
[27]:https://en.wikipedia.org/wiki/Hosts_(file)
|
||||
[28]:https://github.com/gorhill/uMatrix/issues/32#issuecomment-61372436
|
||||
69
published/20180625 The life cycle of a software bug.md
Normal file
69
published/20180625 The life cycle of a software bug.md
Normal file
@@ -0,0 +1,69 @@
|
||||
软件 bug 的生命周期
|
||||
======
|
||||
|
||||
> 从发现软件故障到解决它们,这里讲述是开发团队如何压制软件 bug。
|
||||
|
||||

|
||||
|
||||
1947 年,发现了第一个计算机 bug —— 被困在计算机继电器中的飞蛾。
|
||||
|
||||
要是所有的 bug 都能如此简单地发现就好了。随着软件变得越来越复杂,测试和调试的过程也变得更加复杂。如今,软件 bug 的生命周期可能会很长,尽管正确的技术和业务流程可能会有所帮助。对于开源软件,开发人员使用严格的工单服务和协作来查找和解决 bug。
|
||||
|
||||
### 确认计算机 bug
|
||||
|
||||
在测试过程中,发现的 bug 会报告给开发团队。质量保证测试人员尽可能详细地描述 bug ,报告他们的系统状态、他们正在进行的过程以及 bug 是如何表现出来的。
|
||||
|
||||
尽管如此,一些 bug 从未得到确认;它们可能会在测试中报告,但永远无法在可控环境中重现。在这种情况下,它们可能得不到解决,而是被关闭。
|
||||
|
||||
有些计算机 bug 可能很难确认,因为使用的平台种类繁多,用户行为也非常多。有些 bug 只是间歇性地或在非常特殊的情况下发生的,而另一些 bug 可能会出现在随机的情况下。
|
||||
|
||||
许多人使用开源软件并与之交互,许多 bug 和问题可能是不可重复的,或者可能没有得到充分的描述。不过,由于每个用户和开发人员也都扮演质量保证测试人员的角色,至少在一定程度上,bug 还是很有可能会发现的。
|
||||
|
||||
确认 bug 后,修复工作就开始了。
|
||||
|
||||
### 分配要修复的 bug
|
||||
|
||||
已确认的 bug 被分配给负责解决的开发人员或开发团队。在此阶段,需要重现 bug,发现问题,并修复相关代码。如果 bug 的优先级较低,开发人员可以将此 bug 分类为稍后要修复的问题,也可以在该 bug 具有高优先级的情况下直接指派某人修复。无论哪种方式,都会在开发过程中打开一个工单,并且 bug 将成为已知的问题。
|
||||
|
||||
在开源解决方案中,开发人员可以进行选择他们想要解决的 bug,要么选择他们最熟悉的程序区域,要么从优先级最高的的开始。综合解决方案,如 [GitHub][1] 使得多个开发人员能够轻松地着手解决,而不会干扰彼此的工作。
|
||||
|
||||
当将 bug 设置为需要修复时,bug 报告者还可以为该 bug 选择优先级。主要的 bug 可能具有较高的优先级,而仅与外观相关的 bug 可能具有较低的级别。优先级确定开发团队解决这些问题的方式和时间。无论哪种方式,所有的 bug 都需要先解决,然后才能认为产品已完成。在这方面,适当的回溯到优先级高的需求也会很有帮助。
|
||||
|
||||
### 解决 bug
|
||||
|
||||
一旦修复了 bug ,通常会将其作为已解决的 bug 发送回质量保证测试人员。然后,质量保证测试人员再次将产品置于其工作中,以重现 bug。如果无法重现 bug ,质量保证测验人员将假定它已得到适当解决。
|
||||
|
||||
在开源情况下,任何更改都会被分发,通常是作为正在测试的暂定版本。此测试版本分发给用户,用户再次履行质量保证测试人员的职责并测试产品。
|
||||
|
||||
如果 bug 再次出现,问题将被发送回开发团队。在此阶段,该 bug 将重新触发,开发团队有责任重复解决该 bug 的循环。这种情况可能会发生多次,尤其是在 bug 不可预知或间歇性发生的情况下。众所周知,间歇性的 bug 很难解决。
|
||||
|
||||
如果该 bug 不再出现,则该问题将被标记为已解决。在某些情况下,最初的 bug 得到了解决,但由于所做的更改,会出现其他 bug。发生这种情况时,可能需要新的 bug 报告,然后重新开始该过程。
|
||||
|
||||
### 关闭 bug
|
||||
|
||||
在处理、识别和解决 bug 后,该 bug 将被关闭,开发人员可以转到软件开发和测试的其他阶段。如果始终找不到 bug ,或者开发人员无法重现 bug ,则该 bug 也将被关闭 —— 无论哪种方式,都将开始开发和测试的下一阶段。
|
||||
|
||||
在测试版本中对解决方案所做的任何更改都将滚动到产品的下一个版本中。如果 bug 是严重的,则在下一个版本发布之前,可能会为当前用户提供修补程序或修补程序。这在安全问题中很常见。
|
||||
|
||||
软件 bug 可能很难找到,但通过遵循过程,开发人员可以使开发更快、更容易、更一致。质量保证是这一过程的重要组成部分,因为质量保证测试人员必须发现和识别 bug ,并帮助开发人员重现这些 bug 。在 bug 不再发生之前,无法关闭和解决 bug。
|
||||
|
||||
开源的解决方案分散了质量保证测试、开发和缓解的负担,这往往导致 bug 被更快、更全面地发现和缓解。但是,由于开源技术的性质,此过程的速度和准确性通常取决于解决方案的受欢迎程度及其维护和开发团队的敬业精神。
|
||||
|
||||
Rich Butkevic 是一个 PMP 项目经理认证,,敏捷开发框架认证(certified scrum master) 并且 维护 [Project Zendo][2],这是供项目管理专业人员去发现、简化和改进其项目成果策略的网站。可以在 [Richbutkevic.com][3] 或者使用 [LinkedIn][4] 与 Rich 联系。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/6/life-cycle-software-bug
|
||||
|
||||
作者:[Rich Butkevic][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[lixinyuxx](https://github.com/lixinyuxx)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/rich-butkevic
|
||||
[1]:https://github.com/
|
||||
[2]:https://projectzendo.com
|
||||
[3]:https://richbutkevic.com
|
||||
[4]:https://www.linkedin.com/in/richbutkevic
|
||||
@@ -1,40 +1,42 @@
|
||||
|
||||
五种 DevSecOps 提升安全性
|
||||
DevSecOps 提升安全性的五种方式
|
||||
======
|
||||
|
||||
> 安全必须进化以跟上当今的应用开发和部署方式。
|
||||
|
||||

|
||||
|
||||
对于我们是否需要扩展 DevOps 以确实提升安全性,我们一直都有争议。毕竟,我们的想法是,DevOps 一直是一系列的新实践的简写,使用新工具(通常是开源的)并且在这之上构建更多的协作文化。为什么 DevBizOps 不能更好地满足商业的需求?或者说 DevChatOps 强调的是更快更好的沟通?
|
||||
对于我们是否需要扩展 DevOps 以确实提升安全性,我们一直都有争议。毕竟,我们认为,DevOps 一直是一系列的新实践的简写,使用新工具(通常是开源的)并且在这之上构建更多的协作文化。为什么 [DevBizOps][3] 不能更好地满足商业的需求?或者说 DevChatOps 强调的是更快更好的沟通?
|
||||
|
||||
在今年(译者注:此处是2018年)的早些时候写的关于他理解的 DevSecOps 术语,“我希望,有一天在世界范围内,我们能不再使用 DevSecOps 这个词,安全会是所有的服务交付讨论中理所应当的部分。直到那一天到来为止,在这一点上,我的一般性结论是,这个词只有三个新的特性。更重要的是,我们作为一个产业,在信息安全方面并没有做的很好,而这个名称切实地区分出了问题的状况”
|
||||
然而,如 [John Willis][4] 在今年(LCTT 译注:此处是 2018 年)的早些时候写的关于他对 [DevSecOps][5] 术语的理解,“我希望,有一天我们能在任何地方都不再使用 DevSecOps 这个词,安全会是所有关于服务交付的讨论中理所应当的部分。在那一天到来前,在这一点上,我的一般性结论是,这个词只是三个新的特性而已。更重要的是,我们作为一个产业,在信息安全方面并没有做的很好,而这个名称切实地区分出了问题的状况。”
|
||||
|
||||
所以,为什么我们在信息安全方面做的不好,在 DevSecOps 的语境下安全做的好又是什么意思呢?
|
||||
所以,为什么我们在[信息安全][6]方面做的不好,在 DevSecOps 的语境下安全做的好又是什么意思呢?
|
||||
|
||||
我们大概从未做好过信息安全,尽管(也可能是因为)复杂的工业点产品地址拥挤问题。我们仍然可以在这个时代把工作做得足够好,以此来防范威胁,这些威胁主要集中在一个范围内,网络的连接是有限的,而且大多数的用户都是公司的员工,使用的是公司提供的设备。
|
||||
尽管(也可能是因为)庞大的复杂行业的单点产品解决了特定方面的问题,但我们可以说是从未做好过信息安全。我们仍然可以在这个时代把工作做得足够好,以此来防范威胁,这些威胁主要集中在一个范围内,网络的连接是受限的,而且大多数的用户都是公司的员工,使用的是公司提供的设备。
|
||||
|
||||
这些年来,这些情况并没有能准确地描述出大多数组织的真实现状。但在现在这个时代,不止引入了 DevSecOps,也同时引入了新的应用架构模型,开发实践,和越来越多的安全威胁,这些一起定义了一个需要更快迭代的新常态。还没有应用得很多的 DevSecOps 在独立改变安全,但是 2018 年的信息安全需要新的方法。
|
||||
这些年来,这些情况并没有能准确地描述出大多数组织的真实现状。但在现在这个时代,不止引入了 DevSecOps,也同时引入了新的应用架构模型、开发实践,和越来越多的安全威胁,这些一起定义了一个需要更快迭代的新常态。与其说 DevSecOps 孤立地改变了安全,不如说信息安全公司在 2018 年需要新的方法。
|
||||
|
||||
请仔细思考下面这五个领域。
|
||||
|
||||
### 自动化
|
||||
|
||||
大量的自动化通常是 DevOps 的标志,这部分是关于速度的,如果你要快速移动(并且不会打坏东西),你需要有可重复的过程,而且这个过程不需要太多的人工干预。实际上,自动化是 DevOps 最好的切入点之一,甚至是在仍然主要工作在单片机电路程序的组织里也是如此。使用像 Ansible 这样易于使用的工具来自动化地处理相关的配置或者是测试,这是快速开始 DevOps 之路的常用方法。
|
||||
大量的自动化通常是 DevOps 的标志,这部分是关于速度的,如果你要快速变化(并且不会造成破坏),你需要有可重复的过程,而且这个过程不需要太多的人工干预。实际上,自动化是 DevOps 最好的切入点之一,甚至是在仍然主要使用老式的<ruby>独石应用<rt>monolithic app</rt></ruby>的组织里也是如此。使用像 Ansible 这样易于使用的工具来自动化地处理相关的配置或者是测试,这是快速开始 DevOps 之路的常用方法。
|
||||
|
||||
DevSecOps 也不例外,在今天,安全已经变成了一个持续性的过程,而不是在应用的生命周期里进行不定期的检查,甚至是每周、每月的检查。当漏洞被厂商发现并修复的时候,这些漏洞能被快速地应用是很重要的,因为利用这些漏洞的利用程序很快就会被淘汰。
|
||||
DevSecOps 也不例外,在今天,安全已经变成了一个持续性的过程,而不是在应用的生命周期里进行不定期的检查,甚至是每周、每月的检查。当漏洞被厂商发现并修复的时候,这些修复能被快速地应用是很重要的,这样对这些漏洞的利用程序很快就会被淘汰。
|
||||
|
||||
### "左转"
|
||||
### “左移”
|
||||
|
||||
在开发流程结束时,传统安全通常被视作一个守门人。检查所有的部分确保没有问题,然后这个应用程序就可以投入生产了。否则,就要再来一次。所以安全团队的声誉并不高。
|
||||
在开发流程结束时,传统的安全通常被视作一个守门人。检查所有的部分确保没有问题,然后这个应用程序就可以投入生产了。否则,就要再来一次。安全小组以说“不”而闻名。
|
||||
|
||||
因此,我们想的是,没什么不把安全这个部分提到前面呢(左边是一个典型的从左到右的开发流程图)?安全性可能仍然不行,但在开发的早期进行重构的影响要远远小于开发已经完成并且准备上线时进行重构的影响。
|
||||
因此,我们想的是,为什么不把安全这个部分提到前面呢(在一个典型的从左到右的开发流程图的“左边”)?安全团队仍然可以说“不”,但在开发的早期进行重构的影响要远远小于开发已经完成并且准备上线时进行重构的影响。
|
||||
|
||||
不过,我不喜欢“左移”这个词,这意味着安全仍然是一个只不过提前进行的一次性工作。在应用程序的整个生命周期里,从供应链到开发,再到测试,直到上线部署,安全都需要进行大量的自动化处理。
|
||||
|
||||
### 管理依赖
|
||||
|
||||
我们在现代应用程序开发过程中看到的一个最大的改变,就是你通常不需要去编写这个程序的大部分代码。使用开源的函数库和框架就是一个明显的例子。但是你也可以从公共的云服务商或其他来源那里获得额外的服务。在许多情况下,这些额外的代码和服务比你给自己写的要好得多。
|
||||
我们在现代应用程序开发过程中看到的一个最大的改变,就是你通常不需要去编写这个程序的大部分代码。使用开源的函数库和框架就是一个明显的例子。而且你也可以从公共的云服务商或其他来源那里获得额外的服务。在许多情况下,这些额外的代码和服务比你给自己写的要好得多。
|
||||
|
||||
因此,DevSecOps 需要你把重点放在你的软件供应链上,你是从可信的来源那里获取你的软件的吗?这些软件是最新的吗?它们已经集成到了你为自己的代码使用的安全流程中了吗?对于这些你能使用的代码和 API 你有哪些策略?你为自己的产品代码使用的组件是否有可用的商业支持?
|
||||
因此,DevSecOps 需要你把重点放在你的[软件供应链][8]上,你是从可信的来源那里获取你的软件的吗?这些软件是最新的吗?它们已经集成到了你为自己的代码所使用的安全流程中了吗?对于这些你能使用的代码和 API 你有哪些策略?你为自己的产品代码使用的组件是否有可用的商业支持?
|
||||
|
||||
没有一套标准答案可以应对所有的情况。对于概念验证和大规模的生产,它们可能会有所不同。但是,正如制造业长期存在的情况(DevSecOps 和制造业的发展方面有许多相似之处),供应链的可信是至关重要的。
|
||||
|
||||
@@ -42,7 +44,7 @@ DevSecOps 也不例外,在今天,安全已经变成了一个持续性的过
|
||||
|
||||
关于贯穿应用程序整个生命周期里所有阶段的自动化的需求,我已经谈过很多了。这里假设我们能看见每个阶段里发生的情况。
|
||||
|
||||
有效的 DevSecOps 需要有效的检测,以便于自动化程序知道要做什么。这个检测分了很多类别。一些长期的和高级别的指标能帮助我们了解整个 DevSecOps 流程是否工作良好。严重威胁级别的警报需要立刻有人进行处理(安全扫描系统已经关闭!)。有一些警报,比如扫描失败,需要进行修复。我们记录了大量的参数来生成日志,以便事后进行分析(随着时间的推移,哪些发生了改变?导致失败的原因是什么?)。
|
||||
有效的 DevSecOps 需要有效的检测,以便于自动化程序知道要做什么。这个检测分了很多类别。一些长期的和高级别的指标能帮助我们了解整个 DevSecOps 流程是否工作良好。严重威胁级别的警报需要立刻有人进行处理(安全扫描系统已经关闭!)。有一些警报,比如扫描失败,需要进行修复。我们记录了许多参数的志以便事后进行分析(随着时间的推移,哪些发生了改变?导致失败的原因是什么?)。
|
||||
|
||||
### 分散服务 vs 一体化解决方案
|
||||
|
||||
@@ -50,7 +52,7 @@ DevSecOps 也不例外,在今天,安全已经变成了一个持续性的过
|
||||
|
||||
这种方法确实带来了一些新的安全挑战,组件之间的交互可能会很复杂,总的攻击面会更大,因为现在应用程序通过网络有了更多的切入点。
|
||||
|
||||
另一方面,这种类型的架构还意味着自动化的安全和监视可以更加精细地查看应用程序的组件,因为它们不再深埋在一整个应用程序之中。
|
||||
另一方面,这种类型的架构还意味着自动化的安全和监视可以更加精细地查看应用程序的组件,因为它们不再深埋在一个独石应用程序之中。
|
||||
|
||||
不要过多地关注 DevSecOps 这个术语,但要提醒一下,安全正在不断地演变,因为我们编写和部署程序的方式也在不断地演变。
|
||||
|
||||
@@ -61,7 +63,7 @@ via: https://opensource.com/article/18/9/devsecops-changes-security
|
||||
作者:[Gordon Haff][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[hopefully2333](https://github.com/hopefully2333)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
最终的 JOS 项目
|
||||
Caffeinated 6.828:实验 6:最终的 JOS 项目
|
||||
======
|
||||
|
||||
### 简介
|
||||
|
||||
对于最后的项目,你有两个选择:
|
||||
|
||||
* 继续使用你自己的 JOS 内核并做 [实验 6][1],包括实验 6 中的一个挑战问题。(你可以随意地、以任何有趣的方式去扩展实验 6 或者 JOS 的任何部分,当然了,这不是课程规定的。)
|
||||
|
||||
* 在一个、二个或三个人组成的团队中,你选择去做一个涉及了你的 JOS 的项目。这个项目必须是涉及到与实验 6 相同或更大的(如果你是团队中的一员)领域。
|
||||
* 在一个、二个或三个人组成的团队中,你选择去做一个涉及了你的 JOS 的项目。这个项目必须是涉及到与实验 6 相同或更大的领域(如果你是团队中的一员)。
|
||||
|
||||
目标是为了获得乐趣或探索更高级的 O/S 的话题;你不需要做最新的研究。
|
||||
|
||||
@@ -16,70 +16,48 @@
|
||||
|
||||
### 交付期限
|
||||
|
||||
```
|
||||
11 月 3 日:Piazza 讨论和 1、2、或 3 年级组选择(根据你的最终选择来定)。使用在 Piazza 上的 lab7 标记/目录。在 Piazza 上的文章评论区与其它人计论想法。使用这些文章帮你去找到有类似想法的其它学生一起组建一个小组。课程的教学人员将在 Piazza 上为你的项目想法给出反馈;如果你想得到更详细的反馈,可以与我们单独讨论。
|
||||
```
|
||||
> 11 月 3 日:Piazza 讨论和 1、2、或 3 年级组选择(根据你的最终选择来定)。使用在 Piazza 上的 lab7 标记/目录。在 Piazza 上的文章评论区与其它人计论想法。使用这些文章帮你去找到有类似想法的其它学生一起组建一个小组。课程的教学人员将在 Piazza 上为你的项目想法给出反馈;如果你想得到更详细的反馈,可以与我们单独讨论。
|
||||
|
||||
```markdown
|
||||
11 月 9 日:在 [提交网站][19] 上提交一个提议,只需要一到两个段落就可以。提议要包括你的小组成员列表、你的计划、以及明确的设计和实现打算。(如果你做实验 6,就不用做这个了)
|
||||
```
|
||||
.
|
||||
|
||||
```markdown
|
||||
12 月 7 日:和你的简短报告一起提交源代码。将你的报告放在与名为 "README.pdf" 的文件相同的目录下。由于你只是这个实验任务小组中的一员,你可能需要去使用 git 在小组成员之间共享你的项目代码。因此你需要去决定哪些源代码将作为你的小组项目的共享起始点。一定要为你的最终项目去创建一个分支,并且命名为 `lab7`。(如果你做了实验 6,就按实验 6 的提交要求做即可。)
|
||||
```
|
||||
> 11 月 9 日:在 [提交网站][19] 上提交一个提议,只需要一到两个段落就可以。提议要包括你的小组成员列表、你的计划、以及明确的设计和实现打算。(如果你做实验 6,就不用做这个了)
|
||||
|
||||
```
|
||||
12 月 11 日这一周:简短的课堂演示。为你的 JOS 项目准备一个简短的课堂演示。为了你的项目演示,我们将提供一个投影仪。根据小组数量和每个小组选择的项目类型,我们可能会限制总的演讲数,并且有些小组可能最终没有机会上台演示。
|
||||
```
|
||||
.
|
||||
|
||||
```
|
||||
12 月 11 日这一周:助教们验收。向助教演示你的项目,因此我们可能会提问一些问题,去了解你所做的一些细节。
|
||||
```
|
||||
> 12 月 7 日:和你的简短报告一起提交源代码。将你的报告放在与名为 “README.pdf” 的文件相同的目录下。由于你只是这个实验任务小组中的一员,你可能需要去使用 git 在小组成员之间共享你的项目代码。因此你需要去决定哪些源代码将作为你的小组项目的共享起始点。一定要为你的最终项目去创建一个分支,并且命名为 `lab7`。(如果你做了实验 6,就按实验 6 的提交要求做即可。)
|
||||
|
||||
.
|
||||
|
||||
> 12 月 11 日这一周:简短的课堂演示。为你的 JOS 项目准备一个简短的课堂演示。为了你的项目演示,我们将提供一个投影仪。根据小组数量和每个小组选择的项目类型,我们可能会限制总的演讲数,并且有些小组可能最终没有机会上台演示。
|
||||
|
||||
.
|
||||
|
||||
> 12 月 11 日这一周:助教们验收。向助教演示你的项目,因此我们可能会提问一些问题,去了解你所做的一些细节。
|
||||
|
||||
### 项目想法
|
||||
|
||||
如果你不做实验 6,下面是一个启迪你的想法列表。但是,你应该大胆地去实现你自己的想法。其中一些想法只是一个开端,并且本身不在实验 6 的领域内,并且其它的可能是在更大的领域中。
|
||||
|
||||
* 使用 [x86 虚拟机支持][2] 去构建一个能够运行多个访客系统(比如,多个 JOS 实例)的虚拟机监视器。
|
||||
|
||||
* 使用 Intel SGX 硬件保护机制做一些有用的事情。[这是使用 Intel SGX 的最新的论文][3]。
|
||||
|
||||
* 让 JOS 文件系统支持写入、文件创建、为持久性使用日志、等等。或许你可以从 Linux EXT3 上找到一些启示。
|
||||
|
||||
* 从 [软更新][4]、[WAFL][5]、ZFS、或其它较高级的文件系统上找到一些使用文件系统的想法。
|
||||
|
||||
* 给一个文件系统添加快照功能,以便于用户能够查看过去的多个时间点上的文件系统。为了降低空间使用量,你或许要使用一些写时复制技术。
|
||||
|
||||
* 使用分页去提供实时共享的内存,来构建一个 [分布式的共享内存][6](DSM)系统,以便于你在一个机器集群上运行多线程的共享内存的并行程序。当一个线程尝试去访问位于另外一个机器上的页时,页故障将给 DSM 系统提供一个机会,让它基于网络去从当前存储这个页的任意一台机器上获取这个页。
|
||||
|
||||
* 允许进程在机器之间基于网络进行迁移。你将需要做一些关于一个进程状态的多个片段方面的事情,但是由于在 JOS 中许多状态是在用户空间中,它或许从 Linux 上的进程迁移要容易一些。
|
||||
|
||||
* 在 JOS 中实现 [分页][7] 到磁盘,这样那个进程使用的内存就可以大于真实的内存。使用交换空间去扩展你的内存。
|
||||
|
||||
* 为 JOS 实现文件的 [mmap()][8]。
|
||||
|
||||
* 使用 [xfi][9] 将一个进程的代码沙箱化。
|
||||
|
||||
* 支持 x86 的 [2MB 或 4MB 的页大小][10]。
|
||||
|
||||
* 修改 JOS 让内核支持进程内的线程。从查看 [课堂上的 uthread 任务][11] 去开始。实现调度器触发将是实现这个项目的一种方式。
|
||||
|
||||
* 在 JOS 的内核中或文件系统中(实现多线程之后),使用细粒度锁或无锁并发。Linux 内核使用 [读复制更新][12] 去执行无需上锁的读取操作。通过在 JOS 中实现它来探索 RCU,并使用它去支持无锁读取的名称缓存。
|
||||
|
||||
* 实现 [外内核论文][13] 中的想法。例如包过滤器。
|
||||
|
||||
* 使 JOS 拥有软实时行为。用它来辨识一些应用程序时非常有用。
|
||||
|
||||
* 使 JOS 运行在 64 位 CPU 上。这包括重设计虚拟内存让它使用 4 级页表。有关这方面的文档,请查看 [参考页][14]。
|
||||
|
||||
* 移植 JOS 到一个不同的微处理器。这个 [osdev wiki][15] 或许对你有帮助。
|
||||
|
||||
* 为 JOS 系统增加一个“窗口”系统,包括图形驱动和鼠标。有关这方面的文档,请查看 [参考页][16]。[sqrt(x)][17] 就是一个 JOS “窗口” 系统的示例。
|
||||
|
||||
* 在 JOS 中实现 [dune][18],以提供特权硬件指令给用户空间应用程序。
|
||||
|
||||
* 写一个用户级调试器,添加类似跟踪的功能;硬件寄存器概要(即:Oprofile);调用跟踪等等。
|
||||
|
||||
* 为(静态的)Linux 可运行程序做一个二进制仿真。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@@ -89,7 +67,7 @@ via: https://pdos.csail.mit.edu/6.828/2018/labs/lab7/
|
||||
作者:[csail.mit][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "Auk7F7"
|
||||
[#]: reviewer: "wxy"
|
||||
[#]: publisher: "wxy"
|
||||
[#]: subject: "Arch-Audit : A Tool To Check Vulnerable Packages In Arch Linux"
|
||||
[#]: via: "https://www.2daygeek.com/arch-audit-a-tool-to-check-vulnerable-packages-in-arch-linux/"
|
||||
[#]: author: "Prakash Subramanian https://www.2daygeek.com/author/prakash/"
|
||||
[#]: url: "https://linux.cn/article-10473-1.html"
|
||||
|
||||
Arch-Audit:一款在 Arch Linux 上检查易受攻击的软件包的工具
|
||||
======
|
||||
|
||||
我们必须经常更新我们的系统以减少宕机时间和问题。每月给系统打一次补丁,60 天一次或者最多 90 天一次,这是 Linux 管理员的例行任务之一。这是忙碌的工作计划,我们不能在不到一个月内做到这一点,因为它涉及到多种活动和环境。
|
||||
|
||||
基本上,基础设施会一同提供测试、开发、 QA 环境(即各个分段和产品)。
|
||||
|
||||
最初,我们会在测试环境中部署补丁,相应的团队将监视系统一周,然后他们将给出一份或好或坏的状态的报告。如果成功的话,我们将会在其他环境中继续测试,若正常运行,那么最后我们会给生产服务器打上补丁。
|
||||
|
||||
许多组织会对整个系统打上补丁,我的意思是全系统更新,对于典型基础设施这是一种常规修补计划。
|
||||
|
||||
某些基础设施中可能只有生产环境,因此,我们不应该做全系统更新,而是应该使用安全修补程序来使系统更加稳定和安全。
|
||||
|
||||
由于 Arch Linux 及其衍生的发行版属于滚动更新版本,因此可以认为它们始终是最新的,因为它使用上游软件包的最新版本。
|
||||
|
||||
在某些情况下,如果要单独更新安全修补程序,则必须使用 arch-audit 工具来标识和修复安全修补程序。
|
||||
|
||||
### 漏洞是什么?
|
||||
|
||||
漏洞是软件程序或硬件组件(固件)中的安全漏洞。这是一个可以让它容易受到攻击的缺陷。
|
||||
|
||||
为了缓解这种情况,我们需要相应地修补漏洞,就像应用程序/硬件一样,它可能是代码更改或配置更改或参数更改。
|
||||
|
||||
### Arch-Audit 工具是什么?
|
||||
|
||||
[Arch-audit][1] 是一个类似于 Arch Linux 的 pkg-audit 工具。它使用了令人称赞的 Arch 安全小组收集的数据。它不会扫描以发现系统中易受攻击的包(就像 `yum –security check-update & yum updateinfo` 一样列出可用的软件包),它只需解析 <https://security.archlinux.org/> 页面并在终端中显示结果,因此,它将显示准确的数据。(LCTT 译注:此处原作者叙述不清晰。该功能虽然不会像病毒扫描软件一样扫描系统上的文件,但是会读取已安装的软件列表,并据此查询上述网址列出风险报告。)
|
||||
|
||||
Arch 安全小组是一群以跟踪 Arch Linux 软件包的安全问题为目的的志愿者。所有问题都在 Arch 安全追踪者的监视下。
|
||||
|
||||
该小组以前被称为 Arch CVE 监测小组,Arch 安全小组的使命是为提高 Arch Linux 的安全性做出贡献。
|
||||
|
||||
### 如何在 Arch Linux 上安装 Arch-Audit 工具
|
||||
|
||||
Arch-audit 工具已经存在社区的仓库中,所以你可以使用 Pacman 包管理器来安装它。
|
||||
|
||||
```
|
||||
$ sudo pacman -S arch-audit
|
||||
```
|
||||
|
||||
运行 `arch-audit` 工具以查找在基于 Arch 的发行版本上的存在缺陷的包。
|
||||
|
||||
```
|
||||
$ arch-audit
|
||||
Package cairo is affected by CVE-2017-7475. Low risk!
|
||||
Package exiv2 is affected by CVE-2017-11592, CVE-2017-11591, CVE-2017-11553, CVE-2017-17725, CVE-2017-17724, CVE-2017-17723, CVE-2017-17722. Medium risk!
|
||||
Package libtiff is affected by CVE-2018-18661, CVE-2018-18557, CVE-2017-9935, CVE-2017-11613. High risk!. Update to 4.0.10-1!
|
||||
Package openssl is affected by CVE-2018-0735, CVE-2018-0734. Low risk!
|
||||
Package openssl-1.0 is affected by CVE-2018-5407, CVE-2018-0734. Low risk!
|
||||
Package patch is affected by CVE-2018-6952, CVE-2018-1000156. High risk!. Update to 2.7.6-7!
|
||||
Package pcre is affected by CVE-2017-11164. Low risk!
|
||||
Package systemd is affected by CVE-2018-6954, CVE-2018-15688, CVE-2018-15687, CVE-2018-15686. Critical risk!. Update to 239.300-1!
|
||||
Package unzip is affected by CVE-2018-1000035. Medium risk!
|
||||
Package webkit2gtk is affected by CVE-2018-4372. Critical risk!. Update to 2.22.4-1!
|
||||
```
|
||||
|
||||
上述结果显示了系统的脆弱性风险状况,比如:低、中和严重三种情况。
|
||||
|
||||
若要仅显示易受攻击的包及其版本,请执行以下操作。
|
||||
|
||||
```
|
||||
$ arch-audit -q
|
||||
cairo
|
||||
exiv2
|
||||
libtiff>=4.0.10-1
|
||||
openssl
|
||||
openssl-1.0
|
||||
patch>=2.7.6-7
|
||||
pcre
|
||||
systemd>=239.300-1
|
||||
unzip
|
||||
webkit2gtk>=2.22.4-1
|
||||
```
|
||||
|
||||
仅显示已修复的包。
|
||||
|
||||
```
|
||||
$ arch-audit --upgradable --quiet
|
||||
libtiff>=4.0.10-1
|
||||
patch>=2.7.6-7
|
||||
systemd>=239.300-1
|
||||
webkit2gtk>=2.22.4-1
|
||||
```
|
||||
|
||||
为了交叉检查上述结果,我将测试在 <https://www.archlinux.org/packages/> 列出的一个包以确认漏洞是否仍处于开放状态或已修复。是的,它已经被修复了,并于昨天在社区仓库中发布了更新后的包。
|
||||
|
||||
![][3]
|
||||
|
||||
仅打印包名称和其相关的 CVE。
|
||||
|
||||
```
|
||||
$ arch-audit -uf "%n|%c"
|
||||
libtiff|CVE-2018-18661,CVE-2018-18557,CVE-2017-9935,CVE-2017-11613
|
||||
patch|CVE-2018-6952,CVE-2018-1000156
|
||||
systemd|CVE-2018-6954,CVE-2018-15688,CVE-2018-15687,CVE-2018-15686
|
||||
webkit2gtk|CVE-2018-4372
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/arch-audit-a-tool-to-check-vulnerable-packages-in-arch-linux/
|
||||
|
||||
作者:[Prakash Subramanian][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[Auk7F7](https://github.com/Auk7F7)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/prakash/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://github.com/ilpianista/arch-audit
|
||||
[2]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[3]: https://www.2daygeek.com/wp-content/uploads/2018/11/A-Tool-To-Check-Vulnerable-Packages-In-Arch-Linux.png
|
||||
@@ -0,0 +1,55 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10474-1.html)
|
||||
[#]: subject: (Head to the arcade in your Linux terminal with this Pac-man clone)
|
||||
[#]: via: (https://opensource.com/article/18/12/linux-toy-myman)
|
||||
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
|
||||
|
||||
用这个吃豆人游戏在你的终端中玩街机
|
||||
======
|
||||
|
||||
> 想要重现你最喜欢的街机游戏的魔力么?今天的命令行玩具将带你回到过去。
|
||||
|
||||

|
||||
|
||||
欢迎来到今天的 Linux 命令行玩具日历。如果这是你第一次访问该系列,你会问什么是命令行玩具。基本上,它们是游戏和简单的消遣,可以帮助你在终端玩得开心。
|
||||
|
||||
有些是新的,有些是古老的经典。我们希望你喜欢。
|
||||
|
||||
今天的玩具,MyMan,是经典街机游戏<ruby>[吃豆人][1]<rt>Pac-Man</rt></ruby>(你不会认为这是[类似命名的][2] Linux 包管理器对吧?)的有趣克隆。 如果你和我一样,为了在吃豆人游戏中取得高分,你过去在其中花费了很多时间,那么有机会的话,你应该试试这个。
|
||||
|
||||
MyMan 并不是 Linux 终端上唯一的吃豆人克隆版,但是我选择介绍它,因为 1)我喜欢它与原版一致的视觉风格,2)它为我的 Linux 发行版打包了,因此安装很容易。但是你也应该看看其他的克隆。这是[另一个][3]看起来可能不错的,但我没有尝试过。
|
||||
|
||||
由于 MyMan 已为 Fedora 打包,因此安装非常简单:
|
||||
|
||||
```
|
||||
$ dnf install myman
|
||||
```
|
||||
|
||||
MyMan 在 MIT 许可下可用,你可以在 [SourceForge][4] 上查看源代码。
|
||||
|
||||

|
||||
|
||||
你有特别喜欢的命令行小玩具需要我介绍的吗?这个系列要介绍的小玩具大部分已经有了落实,但还预留了几个空位置。如果你有特别想了解的可以评论留言,我会查看的。如果还有空位置,我会考虑介绍它的。如果没有,但如果我得到了一些很好的意见,我会在最后做一些有价值的提及。
|
||||
|
||||
了解一下昨天的玩具,[Linux 终端能做其他事][5],还有记得明天再来!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
via: https://opensource.com/article/18/12/linux-toy-myman
|
||||
|
||||
作者:[Jason Baker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jason-baker
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://en.wikipedia.org/wiki/Pac-Man
|
||||
[2]: https://wiki.archlinux.org/index.php/pacman
|
||||
[3]: https://github.com/YoctoForBeaglebone/pacman4console
|
||||
[4]: https://myman.sourceforge.io/
|
||||
[5]: https://opensource.com/article/18/12/linux-toy-ponysay
|
||||
@@ -0,0 +1,120 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (https://linux.cn/article-10467-1.html)
|
||||
[#]: url: (wxy)
|
||||
[#]: subject: (s-tui: A Terminal Tool To Monitor CPU Temperature, Frequency, Power And Utilization In Linux)
|
||||
[#]: via: (https://www.2daygeek.com/s-tui-stress-terminal-ui-monitor-linux-cpu-temperature-frequency/)
|
||||
[#]: author: (Prakash Subramanian https://www.2daygeek.com/author/prakash/)
|
||||
|
||||
s-tui:在 Linux 中监控 CPU 温度、频率、功率和使用率的终端工具
|
||||
======
|
||||
|
||||
一般每个 Linux 管理员都会使用 [lm_sensors 监控 CPU 温度][1]。lm_sensors (Linux 监控传感器)是一个自由开源程序,它提供了监控温度、电压和风扇的驱动和工具。
|
||||
|
||||
如果你正在找替代的 CLI 工具,我会建议你尝试 s-tui。
|
||||
|
||||
它其实是一个压力测试的终端 UI,可以帮助管理员通过颜色查看 CPU 温度。
|
||||
|
||||
### s-tui 是什么
|
||||
|
||||
s-tui 是一个用于监控计算机的终端 UI。s-tui 可以在终端以图形方式监控 CPU 温度、频率、功率和使用率。此外,它还显示由发热量限制引起的性能下降,它需要很少的资源并且不需要 X 服务器。它是用 Python 编写的,需要 root 权限才能使用它。
|
||||
|
||||
s-tui 是一个独立的程序,可以开箱即用,并且不需要配置文件就可以使用其基本功能。
|
||||
|
||||
s-tui 使用 psutil 来探测你的一些硬件信息。如果不支持你的一些硬件,你可能看不到所有信息。
|
||||
|
||||
以 root 身份运行 s-tui 时,当压测所有 CPU 核心时,可以将 CPU 发挥到最大睿频频率。它在后台使用 Stress 压力测试工具,通过对系统施加某些类型的计算压力来检查其组件的温度是否超过其可接受的范围。只要计算机稳定并且其组件的温度不超过其可接受的范围,PC 超频就没问题。有几个程序可以通过压力测试得到系统的稳定性,从而评估超频水平。
|
||||
|
||||
### 如何在 Linux 中安装 s-tui
|
||||
|
||||
它是用 Python 写的,`pip` 是在 Linux 上安装 s-tui 的推荐方法。确保你在系统上安装了 python-pip 软件包。如果还没有,请使用以下命令进行安装。
|
||||
|
||||
对于 Debian/Ubuntu 用户,使用 [apt 命令][2] 或 [apt-get 命令][3] 来安装 `pip`。
|
||||
|
||||
```
|
||||
$ sudo apt install python-pip stress
|
||||
```
|
||||
|
||||
对于 Archlinux 用户,使用 [pacman 命令][4] 来安装 `pip`。
|
||||
|
||||
```
|
||||
$ sudo pacman -S python-pip stress
|
||||
```
|
||||
|
||||
对于 Fedora 用户,使用 [dnf 命令][5] 来安装 `pip`。
|
||||
|
||||
```
|
||||
$ sudo dnf install python-pip stress
|
||||
```
|
||||
|
||||
对于 CentOS/RHEL 用户,使用 [yum 命令][5] 来安装 `pip`。
|
||||
|
||||
```
|
||||
$ sudo yum install python-pip stress
|
||||
```
|
||||
|
||||
对于 openSUSE 用户,使用 [zypper 命令][5] 来安装 `pip`。
|
||||
|
||||
```
|
||||
$ sudo zypper install python-pip stress
|
||||
```
|
||||
|
||||
最后运行下面的 [pip 命令][8] 在 Linux 中安装 s-tui 工具。
|
||||
|
||||
对于 Python 2.x:
|
||||
|
||||
```
|
||||
$ sudo pip install s-tui
|
||||
```
|
||||
|
||||
对于Python 3.x:
|
||||
|
||||
```
|
||||
$ sudo pip3 install s-tui
|
||||
```
|
||||
|
||||
### 如何使用 s-tui
|
||||
|
||||
正如我在文章开头所说的那样。它需要 root 权限才能从系统获取所有信息。只需运行以下命令即可启动 s-tui。
|
||||
|
||||
```
|
||||
$ sudo s-tui
|
||||
```
|
||||
|
||||
![][10]
|
||||
|
||||
默认情况下,它启用硬件监控并选择 “Stress” 选项以对系统执行压力测试。
|
||||
|
||||
![][11]
|
||||
|
||||
要查看其他选项,请到帮助页面查看。
|
||||
|
||||
```
|
||||
$ s-tui --help
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/s-tui-stress-terminal-ui-monitor-linux-cpu-temperature-frequency/
|
||||
|
||||
作者:[Prakash Subramanian][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/prakash/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.2daygeek.com/view-check-cpu-hard-disk-temperature-linux/
|
||||
[2]: https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[3]: https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[4]: https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/
|
||||
[5]: https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/
|
||||
[6]: https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[7]: https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[8]: https://www.2daygeek.com/install-pip-manage-python-packages-linux/
|
||||
[9]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[10]: https://www.2daygeek.com/wp-content/uploads/2018/12/s-tui-stress-terminal-ui-monitor-linux-cpu-temperature-frequency-1.jpg
|
||||
[11]: https://www.2daygeek.com/wp-content/uploads/2018/12/s-tui-stress-terminal-ui-monitor-linux-cpu-temperature-frequency-2.jpg
|
||||
113
published/20190104 Managing dotfiles with rcm.md
Normal file
113
published/20190104 Managing dotfiles with rcm.md
Normal file
@@ -0,0 +1,113 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10466-1.html)
|
||||
[#]: subject: (Managing dotfiles with rcm)
|
||||
[#]: via: (https://fedoramagazine.org/managing-dotfiles-rcm/)
|
||||
[#]: author: (Link Dupont https://fedoramagazine.org/author/linkdupont/)
|
||||
|
||||
用 rcm 管理隐藏文件
|
||||
======
|
||||
|
||||

|
||||
|
||||
许多 GNU/Linux 程序的一个特点是有个易于编辑的配置文件。几乎所有常见的自由软件都将配置设置保存在纯文本文件中,通常采用结构化格式,如 JSON、YAML 或[“类似 ini”][1] 的文件中。这些配置文件经常隐藏在用户的主目录中。但是,基本的 `ls` 不会显示它们。UNIX 标准要求以点开头的任何文件或目录名称都被视为“隐藏”,除非用户特意要求,否则不会列在目录列表中。例如,要使用 `ls` 列出所有文件,要传递 `-a` 选项。
|
||||
|
||||
随着时间的推移,这些配置文件会有很多定制配置,管理它们变得越来越具有挑战性。不仅如此,在多台计算机之间保持同步是大型组织所面临的共同挑战。最后,许多用户也对其独特的配置感到自豪,并希望以简单的方式与朋友分享。这就是用到 rcm 介入的地方。
|
||||
|
||||
rcm 是一个 “rc” 文件管理套件(“rc” 是命名配置文件的另一种约定,它已被某些 GNU/Linux 程序采用,如 `screen` 或 `bash`)。 rcm 提供了一套命令来管理和列出它跟踪的文件。使用 `dnf` 安装 rcm。
|
||||
|
||||
### 开始使用
|
||||
|
||||
默认情况下,rcm 使用 `~/.dotfiles` 来存储它管理的所有隐藏文件。一个被管理的隐藏文件实际保存在 `~/.dotfiles` 目录中,而它的符号链接会放在文件原本的位置。例如,如果 `~/.bashrc` 由 rcm 所管理,那么详细列表将如下所示。
|
||||
|
||||
```
|
||||
[link@localhost ~]$ ls -l ~/.bashrc
|
||||
lrwxrwxrwx. 1 link link 27 Dec 16 05:19 .bashrc -> /home/link/.dotfiles/bashrc
|
||||
[link@localhost ~]$
|
||||
```
|
||||
|
||||
rcm 包含 4 个命令:
|
||||
|
||||
* `mkrc` – 将文件转换为由 rcm 管理的隐藏文件
|
||||
* `lsrc` – 列出由 rcm 管理的文件
|
||||
* `rcup` – 同步由 rcm 管理的隐藏文件
|
||||
* `rcdn` – 删除 rcm 管理的所有符号链接
|
||||
|
||||
### 在两台计算机上共享 bashrc
|
||||
|
||||
如今用户在多台计算机上拥有 shell 帐户并不罕见。在这些计算机之间同步隐藏文件可能是一个挑战。这里将提供一种可能的解决方案,仅使用 rcm 和 git。
|
||||
|
||||
首先使用 `mkrc` 将文件转换成由 rcm 管理的文件。
|
||||
|
||||
```
|
||||
[link@localhost ~]$ mkrc -v ~/.bashrc
|
||||
Moving...
|
||||
'/home/link/.bashrc' -> '/home/link/.dotfiles/bashrc'
|
||||
Linking...
|
||||
'/home/link/.dotfiles/bashrc' -> '/home/link/.bashrc'
|
||||
[link@localhost ~]$
|
||||
```
|
||||
|
||||
接下来使用 `lsrc` 验证列表是否正确。
|
||||
|
||||
```
|
||||
[link@localhost ~]$ lsrc
|
||||
/home/link/.bashrc:/home/link/.dotfiles/bashrc
|
||||
[link@localhost ~]$
|
||||
```
|
||||
|
||||
现在在 `~/.dotfiles` 中创建一个 git 仓库,并使用你选择的 git 仓库托管设置一个远程仓库。提交 `bashrc` 文件并推送一个新分支。
|
||||
|
||||
```
|
||||
[link@localhost ~]$ cd ~/.dotfiles
|
||||
[link@localhost .dotfiles]$ git init
|
||||
Initialized empty Git repository in /home/link/.dotfiles/.git/
|
||||
[link@localhost .dotfiles]$ git remote add origin git@github.com:linkdupont/dotfiles.git
|
||||
[link@localhost .dotfiles]$ git add bashrc
|
||||
[link@localhost .dotfiles]$ git commit -m "initial commit"
|
||||
[master (root-commit) b54406b] initial commit
|
||||
1 file changed, 15 insertions(+)
|
||||
create mode 100644 bashrc
|
||||
[link@localhost .dotfiles]$ git push -u origin master
|
||||
...
|
||||
[link@localhost .dotfiles]$
|
||||
```
|
||||
|
||||
在第二台机器上,克隆这个仓库到 `~/.dotfiles` 中。
|
||||
|
||||
```
|
||||
[link@remotehost ~]$ git clone git@github.com:linkdupont/dotfiles.git ~/.dotfiles
|
||||
...
|
||||
[link@remotehost ~]$
|
||||
```
|
||||
|
||||
现在使用 `rcup` 更新受 rcm 管理的符号链接。
|
||||
|
||||
```
|
||||
[link@remotehost ~]$ rcup -v
|
||||
replacing identical but unlinked /home/link/.bashrc
|
||||
removed '/home/link/.bashrc'
|
||||
'/home/link/.dotfiles/bashrc' -> '/home/link/.bashrc'
|
||||
[link@remotehost ~]$
|
||||
```
|
||||
|
||||
覆盖现有的 `~/.bashrc`(如果存在)并重启 shell。
|
||||
|
||||
就是这些了!指定主机选项 (`-o`) 是对上面这种情况的有用补充。如往常一样,请阅读手册页。它们包含了很多示例命令。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/managing-dotfiles-rcm/
|
||||
|
||||
作者:[Link Dupont][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/linkdupont/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://en.wikipedia.org/wiki/INI_file
|
||||
@@ -0,0 +1,222 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (MjSeven)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10471-1.html)
|
||||
[#]: subject: (Getting started with Pelican: A Python-based static site generator)
|
||||
[#]: via: (https://opensource.com/article/19/1/getting-started-pelican)
|
||||
[#]: author: (Craig Sebenik https://opensource.com/users/craig5)
|
||||
|
||||
Pelican 入门:一个 Python 静态网站生成器
|
||||
======
|
||||
|
||||
> Pelican 是那些想要自我托管简单网站或博客的 Python 用户的绝佳选择。
|
||||
|
||||

|
||||
|
||||
如果你想创建一个自定义网站或博客,有很多选择。许多提供商可以托管你的网站并为你完成大部分工作。(WordPress 是一个非常受欢迎的选项。)但是使用托管方式,你会失去一些灵活性。作为一名软件开发人员,我更喜欢管理我自己的服务器,并在我的网站如何运行方面保持更多的自由。
|
||||
|
||||
然而,管理 Web 服务器需要大量的工作。安装它并获得一个简单的应用程序来提供内容是非常容易的。但是,维护安全补丁和更新是非常耗时得。如果你只想提供静态网页,那么拥有一个 Web 服务器和一系列应用程序可能会得不偿失。手动创建 HTML 页面也不是一个好选择。
|
||||
|
||||
这是静态网站生成器的用武之地。这些应用程序使用模板来创建所需的静态页面,并将它们与关联的元数据交叉链接。(例如,所有显示的页面都带有公共标签或关键词。)静态网站生成器可以帮助你使用导航区域、页眉和页脚等元素创建一个具有公共外观的网站。
|
||||
|
||||
我使用 [Pyhton][1] 已经很多年了,所以,当我第一次开始寻找生成静态 HTML 页面的东西时,我想要用 Python 编写的东西。主要原因是我经常想要了解应用程序如何工作的内部细节,而使用一种我已经了解的语言使这一点更容易。(如果这对你不重要或者你不使用 Python,那么还有一些其他很棒的[静态网站生成器][2],它们使用 Ruby、JavaScript 和其它语言。)
|
||||
|
||||
我决定试试 [Pelican][3]。它是一个用 Python 编写的常用静态网站生成器。它支持 [reStructuredText][4](LCTT 译注:这是一种用于文本数据的文件格式,主要用于 Python 社区的技术文档),并且也支持 [Markdown][5],这需要通过安装必需的包来完成。所有任务都是通过命令行界面(CLI)工具执行的,这使得熟悉命令行的任何人都可以轻松完成。它简单的 quickstart CLI 工具使得创建一个网站非常容易。
|
||||
|
||||
在本文中,我将介绍如何安装 Pelican 4,添加一篇文章以及更改默认主题。(注意:我是在 MacOS 上开发的,使用其它 Unix/Linux 实验结果都将相同,但我没有 Windows 主机可以测试。)
|
||||
|
||||
### 安装和配置
|
||||
|
||||
第一步是创建一个[虚拟环境][6],在虚拟环境中安装 Pelican。
|
||||
|
||||
```
|
||||
$ mkdir test-site
|
||||
$ cd test-site
|
||||
$ python3 -m venv venv
|
||||
$ ./venv/bin/pip install --upgrade pip
|
||||
...
|
||||
Successfully installed pip-18.1
|
||||
$ ./venv/bin/pip install pelican
|
||||
Collecting pelican
|
||||
...
|
||||
Successfully installed MarkupSafe-1.1.0 blinker-1.4 docutils-0.14 feedgenerator-1.9 jinja2-2.10 pelican-4.0.1 pygments-2.3.1 python-dateutil-2.7.5 pytz-2018.7 six-1.12.0 unidecode-1.0.23
|
||||
```
|
||||
|
||||
Pelican 的 quickstart CLI 工具将创建基本布局和一些文件来帮助你开始,运行 `pelican-quickstart` 命令。为了简单起见,我输入了**网站标题**和**作者**的名字,并对 URL 前缀和文章分页选择了 “N”。(对于其它选项,我使用了默认值。)稍后在配置文件中更改这些设置非常容易。
|
||||
|
||||
```
|
||||
$ ./venv/bin/pelicanquickstart
|
||||
Welcome to pelicanquickstart v4.0.1.
|
||||
|
||||
This script will help you create a new Pelican-based website.
|
||||
|
||||
Please answer the following questions so this script can generate the files needed by Pelican.
|
||||
|
||||
> Where do you want to create your new web site? [.]
|
||||
> What will be the title of this web site? My Test Blog
|
||||
> Who will be the author of this web site? Craig
|
||||
> What will be the default language of this web site? [en]
|
||||
> Do you want to specify a URL prefix? e.g., https://example.com (Y/n) n
|
||||
> Do you want to enable article pagination? (Y/n) n
|
||||
> What is your time zone? [Europe/Paris]
|
||||
> Do you want to generate a tasks.py/Makefile to automate generation and publishing? (Y/n)
|
||||
> Do you want to upload your website using FTP? (y/N)
|
||||
> Do you want to upload your website using SSH? (y/N)
|
||||
> Do you want to upload your website using Dropbox? (y/N)
|
||||
> Do you want to upload your website using S3? (y/N)
|
||||
> Do you want to upload your website using Rackspace Cloud Files? (y/N)
|
||||
> Do you want to upload your website using GitHub Pages? (y/N)
|
||||
Done. Your new project is available at /Users/craig/tmp/pelican/test-site
|
||||
```
|
||||
|
||||
你需要启动的所有文件都准备好了。
|
||||
|
||||
quickstart 默认为欧洲/巴黎时区,所以在继续之前更改一下。在你喜欢的文本编辑器中打开 `pelicanconf.py` 文件,寻找 `TIMEZONE` 变量。
|
||||
|
||||
```
|
||||
TIMEZONE = 'Europe/Paris'
|
||||
```
|
||||
|
||||
将其改为 `UTC`。
|
||||
|
||||
```
|
||||
TIMEZONE = 'UTC'
|
||||
```
|
||||
|
||||
要更新公共设置,在 `pelicanconf.py` 中查找 `SOCIAL` 变量。
|
||||
|
||||
```
|
||||
SOCIAL = (('You can add links in your config file', '#'),
|
||||
('Another social link', '#'),)
|
||||
```
|
||||
|
||||
我将添加一个我的 Twitter 账户链接。
|
||||
|
||||
```
|
||||
SOCIAL = (('Twitter (#craigs55)', 'https://twitter.com/craigs55'),)
|
||||
```
|
||||
|
||||
注意末尾的逗号,它很重要。这个逗号将帮助 Python 识别变量实际上是一个集合。确保你没有删除这个逗号。
|
||||
|
||||
现在你已经有了网站的基本知识。quickstart 创建了一个包含许多目标的 `Makefile`。将 `devserver` 传给 `make` 命令将在你的计算机上启动一个开发服务器,以便你可以预览所有内容。`Makefile` 中使用的 CLI 命令假定放在 `PATH` 搜索路径中,因此你需要首先激活该虚拟环境。
|
||||
|
||||
```
|
||||
$ source ./venv/bin/activate
|
||||
$ make devserver
|
||||
pelican -lr /Users/craig/tmp/pelican/test-site/content o
|
||||
/Users/craig/tmp/pelican/test-site/output -s /Users/craig/tmp/pelican/test-site/pelicanconf.py
|
||||
|
||||
-> Modified: theme, settings. regenerating...
|
||||
WARNING: No valid files found in content for the active readers:
|
||||
| BaseReader (static)
|
||||
| HTMLReader (htm, html)
|
||||
| RstReader (rst)
|
||||
Done: Processed 0 articles, 0 drafts, 0 pages, 0 hidden pages and 0 draft pages in 0.18 seconds.
|
||||
```
|
||||
|
||||
在你最喜欢的浏览器中打开 <http://localhost:8000> 来查看你的简单测试博客。
|
||||
|
||||

|
||||
|
||||
你可以在右侧看到 Twitter 链接,左侧有 Pelican、Python 和 Jinja 的一些链接。(Jinja 是 Pelican 可以使用的一种很棒的模板语言。你可以在 [Jinja 的文档][7]中了解更多相关信息。)
|
||||
|
||||
### 添加内容
|
||||
|
||||
现在你又了一个基本的网站,试着添加一些内容。首先,将名为 `welcome.rst` 的文件添加到网站的 `content` 目录中。在你喜欢的文本编辑器中,使用以下文本创建一个文件:
|
||||
|
||||
```
|
||||
$ pwd
|
||||
/Users/craig/tmp/pelican/test-site
|
||||
$ cat content/welcome.rst
|
||||
|
||||
Welcome to my blog!
|
||||
###################
|
||||
|
||||
:date: 20181216 08:30
|
||||
:tags: welcome
|
||||
:category: Intro
|
||||
:slug: welcome
|
||||
:author: Craig
|
||||
:summary: Welcome document
|
||||
|
||||
Welcome to my blog.
|
||||
This is a short page just to show how to put up a static page.
|
||||
```
|
||||
|
||||
Pelican 会自动解析元数据行,包括日期、标签等。
|
||||
|
||||
编写完文件后,开发服务器应该输出以下内容:
|
||||
|
||||
```
|
||||
-> Modified: content. regenerating...
|
||||
Done: Processed 1 article, 0 drafts, 0 pages, 0 hidden pages and 0 draft pages in 0.10 seconds.
|
||||
```
|
||||
|
||||
在浏览器中刷新你的测试网站来查看更改。
|
||||
|
||||

|
||||
|
||||
元数据(例如日期和标签)会自动添加到页面中。此外,Pelican 会自动检测到 intro 栏目,并将该部分添加到顶部导航中。
|
||||
|
||||
### 更改主题
|
||||
|
||||
使用像 Pelican 这样流行的开源软件的好处之一是,非常多的用户会做出更改并将其贡献给项目。许多都是以主题形式贡献的。
|
||||
|
||||
网站的主题会设置颜色、布局选项等。尝试一个新主题非常容易,你可以在 [Pelican 主题][8]中预览其中的许多内容。
|
||||
|
||||
首先,克隆 GitHub 仓库:
|
||||
|
||||
```
|
||||
$ cd ..
|
||||
$ git clone --recursive https://github.com/getpelican/pelicanthemes
|
||||
Cloning into 'pelicanthemes'...
|
||||
```
|
||||
|
||||
我喜欢蓝色,那么试试 [blueidea][9]。
|
||||
|
||||
编辑 `pelicanconf.py`,添加以下行:
|
||||
|
||||
```
|
||||
THEME = '/Users/craig/tmp/pelican/pelican-themes/blueidea/'
|
||||
```
|
||||
|
||||
开发服务器将重新生成你的输出。在浏览器中刷新网页来查看新主题。
|
||||
|
||||

|
||||
|
||||
主题控制布局的方方面面。例如,在默认主题中,你可以看到文章旁边带有元标记的栏目(Intro),但这个栏目并未显示在 blueidea 主题中。
|
||||
|
||||
### 其他考虑因素
|
||||
|
||||
本文是对 Pelican 的快速介绍,所以我并没有涉及一些重要的主题。
|
||||
|
||||
首先,我对迁移到静态站点犹豫不决的一个原因是它无法对文章评论。幸运的是,有一些第三方服务商将为你提供评论功能。我目前正在关注的是 [Disqus][10]。
|
||||
|
||||
接下来,上面的所有内容都是在我的本地机器上完成的。如果我希望其他人查看我的网站,我将不得不将预先生成的 HTML 文件上传到某个地方。如果你查看 `pelican-quickstart` 输出,你将看到使用 FTP、 SSH、S3 甚至 GitHub 页面的选项,每个选项都有其优点和缺点。但是,如果我必须选择一个,那么我可能会选择发布到 GitHub 页面。
|
||||
|
||||
Pelican 还有许多其他功能,我每天都在学习它。如果你想自托管一个网站或博客,内容简单并且是静态内容,同时你想使用 Python,那么 Pelican 是一个很好的选择。它有一个活跃的用户社区,可以修复 bug,添加特性,而且还会创建新的和有趣的主题。试试看吧!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/1/getting-started-pelican
|
||||
|
||||
作者:[Craig Sebenik][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/craig5
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/resources/python
|
||||
[2]: https://opensource.com/sitewide-search?search_api_views_fulltext=static%20site%20generator
|
||||
[3]: http://docs.getpelican.com/en/stable/
|
||||
[4]: http://docutils.sourceforge.net/rst.html
|
||||
[5]: https://daringfireball.net/projects/markdown/
|
||||
[6]: https://virtualenv.pypa.io/en/latest/
|
||||
[7]: http://jinja.pocoo.org/docs/2.10/
|
||||
[8]: http://www.pelicanthemes.com/
|
||||
[9]: https://github.com/nasskach/pelican-blueidea/tree/58fb13112a2707baa7d65075517c40439ab95c0a
|
||||
[10]: https://disqus.com/
|
||||
78
published/20190109 Bash 5.0 Released with New Features.md
Normal file
78
published/20190109 Bash 5.0 Released with New Features.md
Normal file
@@ -0,0 +1,78 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10477-1.html)
|
||||
[#]: subject: (Bash 5.0 Released with New Features)
|
||||
[#]: via: (https://itsfoss.com/bash-5-release)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
|
||||
Bash 5.0 发布及其新功能
|
||||
======
|
||||
|
||||
[邮件列表][1]证实最近发布了 Bash-5.0。而且,令人兴奋的是它还有新的功能和变量。
|
||||
|
||||
如果你一直在使用 Bash 4.4.XX,那么你一定会喜欢 [Bash][2] 的第五个主要版本。
|
||||
|
||||
第五个版本侧重于新的 shell 变量和许多重大漏洞修复。它还引入了一些新功能,以及一些与 bash-4.4 不兼容的更改。
|
||||
|
||||
![Bash logo][3]
|
||||
|
||||
### 新功能怎么样?
|
||||
|
||||
在邮件列表解释了此版本中修复的 bug:
|
||||
|
||||
> 此版本修复了 bash-4.4 中的几个主要错误,并引入了几个新功能。最重要的 bug 修复是对 nameref 变量的解析以及通过模糊测试发现的许多潜在的内存越界错误。在为了符合 Posix 标准解释而不进行单词拆分的上下文中,对 `$@` 和 `$*` 的展开做了许多改变,另外还有解决极端情况中 Posix 一致性的修改。
|
||||
|
||||
它还引入了一些新功能。根据其发布说明,最值得注意的新功能是几个新的 shell 变量:
|
||||
|
||||
> `BASH_ARGV0`、`EPOCHSECONDS` 和 `EPOCHREALTIME`。内置命令 `history` 可以删除指定范围的条目,并能将负数理解为从历史末端开始的偏移量。有一个选项允许局部变量继承前一个范围内具有相同名称的变量的值。有一个新的 shell 选项,在启用它时,会导致 shell 只尝试一次扩展关联数组下标(这在算术表达式中使用时会出现问题)。`globasciiranges` 这个 shell 选项现在默认启用。可以在配置时默认关闭它。
|
||||
|
||||
### Bash-4.4 和 Bash-5.0 之间有哪些变化?
|
||||
|
||||
其更新日志提到了不兼容的更改和所支持的 readline 版本历史记录。它是这么说的:
|
||||
|
||||
> bash-4.4 和 bash-5.0 之间存在一些不兼容的变化。尽管我已经尽量最小化兼容性问题,但是对 `nameref` 变量解析的更改意味着对变量名引用的某些使用会有不同的行为。默认情况下,如果启用了扩展调试模式,shell 仅在启动时设置 `BASH_ARGC` 和 `BASH_ARGV`。它被无条件地设置是一个疏忽,并且在脚本传递大量参数时会导致性能问题。
|
||||
>
|
||||
> 如果需要,可以将 Bash 链接到已安装的 Readline 库,而不是 `lib/readline` 中的私有版本。只有 readline-8.0 及更高版本能够提供 bash-5.0 所需的所有符号。早期版本的 Readline 库无法正常工作。
|
||||
|
||||
我相信一些添加的功能/变量非常有用。我最喜欢的一些是:
|
||||
|
||||
* 有一个新的(默认情况下禁用,文档中没有说明)shell 选项,用于在运行时启用/禁用向 syslog 发送历史记录。
|
||||
* 正如文档一直所说的那样,除非 shell 处于调试模式,否则它不会在启动时自动设置 `BASH_ARGC` 和 `BASH_ARGV`,但如果脚本在上层引用它们且没有启用调试模式,那么 shell 将动态创建它们。
|
||||
* 现在可以使用 `-d start-end` 删除指定范围的 `history` 条目。
|
||||
* 如果启用了作业控制的非交互式 shell 检测到前台作业因 SIGINT 而死亡,则其行为就像接收到 SIGINT 一样。
|
||||
* `BASH_ARGV0`:一个新变量,扩展为 `$0`,并在赋值时设置为 `$0`。
|
||||
|
||||
要查看完整的更改和功能列表,请参阅[邮件列表文章][1]。
|
||||
|
||||
### 总结
|
||||
|
||||
你可以使用下面的命令检查你当前的 Bash 版本:
|
||||
|
||||
```
|
||||
bash --version
|
||||
```
|
||||
|
||||
你很可能安装了 Bash 4.4。如果你想获得新版本,我建议等待你的发行版提供它。
|
||||
|
||||
你怎么看待 Bash-5.0 发布?你在使用其他 bash 的替代品么?如果有的话,这个更新会改变你的想法么?
|
||||
|
||||
请在下面的评论中告诉我们你的想法。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/bash-5-release
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/ankush/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://lists.gnu.org/archive/html/bug-bash/2019-01/msg00063.html
|
||||
[2]: https://www.gnu.org/software/bash/
|
||||
[3]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/01/bash-logo.jpg?resize=800%2C450&ssl=1
|
||||
@@ -1,8 +1,8 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (MjSeven)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10460-1.html)
|
||||
[#]: subject: (Understanding /etc/services file in Linux)
|
||||
[#]: via: (https://kerneltalks.com/linux/understanding-etc-services-file-in-linux/)
|
||||
[#]: author: (kerneltalks https://kerneltalks.com)
|
||||
@@ -10,12 +10,13 @@
|
||||
理解 Linux 中的 /etc/services 文件
|
||||
======
|
||||
|
||||
这篇文章将帮助你了解 Linux 中 /etc/services 文件,包括它的内容,格式以及重要性。
|
||||
这篇文章将帮助你了解 Linux 中 `/etc/services` 文件,包括它的内容,格式以及重要性。
|
||||
|
||||
![/etc/services file in Linux][1]
|
||||
Linux 中的 /etc/services 文件
|
||||
|
||||
网络守护程序是 Linux 世界中的重要服务。它借助 `/etc/services` 文件来处理所有网络服务。在本文中,我们将向你介绍这个文件的内容,格式以及它对于 Linux 系统的意义。
|
||||
*Linux 中的 /etc/services 文件*
|
||||
|
||||
Internet 守护程序(`ineted`)是 Linux 世界中的重要服务。它借助 `/etc/services` 文件来处理所有网络服务。在本文中,我们将向你介绍这个文件的内容,格式以及它对于 Linux 系统的意义。
|
||||
|
||||
`/etc/services` 文件包含网络服务和它们映射端口的列表。`inetd` 或 `xinetd` 会查看这些细节,以便在数据包到达各自的端口或服务有需求时,它会调用特定的程序。
|
||||
|
||||
@@ -26,7 +27,7 @@ $ ll /etc/services
|
||||
-rw-r--r--. 1 root root 670293 Jun 7 2013 /etc/services
|
||||
```
|
||||
|
||||
### `/etc/services` 文件格式
|
||||
### /etc/services 文件格式
|
||||
|
||||
```
|
||||
service-name port/protocol [aliases..] [#comment]
|
||||
@@ -36,12 +37,12 @@ service-name port/protocol [aliases..] [#comment]
|
||||
|
||||
其中:
|
||||
|
||||
* service-name 是网络服务的名称。例如 [telnet][2], [ftp][3] 等。
|
||||
* port/protocol 是网络服务使用的端口(一个数值)和服务通信使用的协议(TCP/UDP)。
|
||||
* alias 是服务的别名。
|
||||
* comment 是你可以添加到服务的注释或说明。以 `#` 标记开头。
|
||||
* `service-name` 是网络服务的名称。例如 [telnet][2]、[ftp][3] 等。
|
||||
* `port/protocol` 是网络服务使用的端口(一个数值)和服务通信使用的协议(TCP/UDP)。
|
||||
* `alias` 是服务的别名。
|
||||
* `comment` 是你可以添加到服务的注释或说明。以 `#` 标记开头。
|
||||
|
||||
### `/etc/services` 文件示例
|
||||
### /etc/services 文件示例
|
||||
|
||||
```
|
||||
# 每行描述一个服务,形式如下:
|
||||
@@ -63,7 +64,7 @@ via: https://kerneltalks.com/linux/understanding-etc-services-file-in-linux/
|
||||
作者:[kerneltalks][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10476-1.html)
|
||||
[#]: subject: (Get started with Joplin, a note-taking app)
|
||||
[#]: via: (https://opensource.com/article/19/1/productivity-tool-joplin)
|
||||
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney (Kevin Sonney))
|
||||
|
||||
开始使用 Joplin 吧,一款开源笔记应用
|
||||
======
|
||||
|
||||
> 了解开源工具如何帮助你在 2019 年提高工作效率。先从 Joplin 开始。
|
||||
|
||||

|
||||
|
||||
每年年初似乎都有疯狂的冲动想提高工作效率。新年的决心,渴望开启新的一年,当然,“抛弃旧的,拥抱新的”的态度促成了这一切。通常这时的建议严重偏向闭源和专有软件,但事实上并不用这样。
|
||||
|
||||
这是我挑选出的 19 个新的(或者对你而言新的)开源项目来帮助你在 2019 年更有效率。
|
||||
|
||||
### Joplin
|
||||
|
||||
在生产力工具领域,笔记应用**非常**方便。是的,你可以使用开源 [NixNote][1] 访问 [Evernote][2] 笔记,但它仍然与 Evernote 服务器相关联,并且仍然依赖于第三方的安全性。虽然你**可以**从 NixNote 导出 Evernote 笔记,但可选格式只有 NixNote XML 或 PDF。
|
||||
|
||||

|
||||
|
||||
*Joplin 的图形界面*
|
||||
|
||||
看看 [Joplin][3]。Joplin 是一个 NodeJS 应用,它在本地运行和存储笔记,它允许你加密笔记并支持多种同步方法。Joplin 可在 Windows、Mac 和 Linux 上作为控制台应用或图形应用运行。Joplin 还有适用于 Android 和 iOS 的移动应用,这意味着你可以随身携带笔记而不会有任何麻烦。Joplin 甚至允许你使用 Markdown、HTML 或纯文本格式笔记。
|
||||
|
||||

|
||||
|
||||
*Joplin 的 Android 应用*
|
||||
|
||||
关于 Joplin 很棒的一件事是它支持两种类型笔记:普通笔记和待办事项笔记。普通笔记是你所想的包含文本的文档。另一个,待办事项笔记在笔记列表中有一个复选框,允许你将其标记为“已完成”。由于待办事项仍然是一个笔记,因此你可以在待办事项中添加列表、文档和其他待办事项。
|
||||
|
||||
当使用图形界面时,你可以在纯文本、WYSIWYG 和同时显示源文本和渲染视图的分屏之间切换编辑器视图。你还可以在图形界面中指定外部编辑器,以便使用 Vim、Emacs 或任何其他能够处理文本文档的编辑器轻松更新笔记。
|
||||
|
||||
![Joplin console version][5]
|
||||
|
||||
*控制台中的 Joplin*
|
||||
|
||||
控制台界面非常棒。虽然它缺少 WYSIWYG 编辑器,但默认登录使用文本编辑器。它还有强大的命令模式,它允许执行在图形版本中几乎所有的操作。并且能够在视图中正确渲染 Markdown。
|
||||
|
||||
你可以将笔记本中的笔记分组,还能为笔记打上标记,以便于在笔记本中进行分组。它甚至还有内置的搜索功能,因此如果你忘了笔记在哪,你可以通过它找到它们。
|
||||
|
||||
总的来说,Joplin 是一款一流的笔记应用([还是 Evernote 的一个很好的替代品][6]),它能帮助你在明年组织化并提高工作效率。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/1/productivity-tool-joplin
|
||||
|
||||
作者:[Kevin Sonney][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/ksonney (Kevin Sonney)
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: http://nixnote.org/NixNote-Home/
|
||||
[2]: https://evernote.com/
|
||||
[3]: https://joplin.cozic.net/
|
||||
[4]: https://opensource.com/article/19/1/file/419776
|
||||
[5]: https://opensource.com/sites/default/files/uploads/joplin-2_0.png (Joplin console version)
|
||||
[6]: https://opensource.com/article/17/12/joplin-open-source-evernote-alternative
|
||||
@@ -0,0 +1,94 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (MjSeven)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10464-1.html)
|
||||
[#]: subject: (How To Move Multiple File Types Simultaneously From Commandline)
|
||||
[#]: via: (https://www.ostechnix.com/how-to-move-multiple-file-types-simultaneously-from-commandline/)
|
||||
[#]: author: (SK https://www.ostechnix.com/author/sk/)
|
||||
|
||||
如何从命令行同时移动多种文件类型
|
||||
======
|
||||
|
||||

|
||||
|
||||
前几天,我想知道如何将多个文件类型从一个目录移动(不复制)到另一个目录。我已经知道如何[查找并将某些类型的文件从一个目录复制到另一个目录][1]。但是,我不知道如何同时移动多种文件类型。如果你曾遇到这样的情况,我知道在类 Unix 系统中从命令行执行该操作的一个简单方法。
|
||||
|
||||
### 同时移动多种文件类型
|
||||
|
||||
想象一下这种场景,你在名为 `dir1` 的目录中有多种类型的文件,例如 .pdf、 .doc、 .mp3、 .mp4、 .txt 等等。我们来看看 `dir1` 的内容:
|
||||
|
||||
```
|
||||
$ ls dir1
|
||||
file.txt image.jpg mydoc.doc personal.pdf song.mp3 video.mp4
|
||||
```
|
||||
|
||||
你希望将某些文件类型(不是所有文件类型)移动到另一个位置。例如,假设你想将 .doc、 .pdf 和 .txt 文件一次性移动到名为 `dir2` 的另一个目录中。
|
||||
|
||||
要同时将 .doc、 .pdf 和 .txt 文件从 `dir1` 移动到 `dir2`,命令是:
|
||||
|
||||
```
|
||||
$ mv dir1/*.{doc,pdf,txt} dir2/
|
||||
```
|
||||
|
||||
很容易,不是吗?
|
||||
|
||||
现在让我们来查看一下 `dir2` 的内容:
|
||||
|
||||
```
|
||||
$ ls dir2/
|
||||
file.txt mydoc.doc personal.pdf
|
||||
```
|
||||
|
||||
看到了吗?只有 .doc、 .pdf 和 .txt 从 `dir1` 移到了 `dir2`。
|
||||
|
||||
![][3]
|
||||
|
||||
在上面的命令中,你可以在花括号内添加任意数量的文件类型,以将它们移动到不同的目录中。它在 Bash 上非常适合我。
|
||||
|
||||
另一种移动多种文件类型的方法是转到源目录,在我们的例子中即为 `dir1`:
|
||||
|
||||
```
|
||||
$ cd ~/dir1
|
||||
```
|
||||
|
||||
将你选择的文件类型移动到目的地(即 `dir2`),如下所示:
|
||||
|
||||
```
|
||||
$ mv *.doc *.txt *.pdf /home/sk/dir2/
|
||||
```
|
||||
|
||||
要移动具有特定扩展名的所有文件,例如 .doc,运行:
|
||||
|
||||
```
|
||||
$ mv dir1/*.doc dir2/
|
||||
```
|
||||
|
||||
更多细节,参考 man 页:
|
||||
|
||||
```
|
||||
$ man mv
|
||||
```
|
||||
|
||||
移动一些相同或不同的文件类型很容易!你可以在 GUI 模式下单击几下鼠标,或在 CLI 模式下使用一行命令来完成。但是,如果目录中有数千种不同的文件类型,并且希望一次将多种文件类型移动到不同的目录,这将是一项繁琐的任务。对我来说,上面的方法很容易完成工作!如果你知道任何其它一行命令可以一次移动多种文件类型,请在下面的评论部分与我们分享。我会核对并更新指南。
|
||||
|
||||
这些就是全部了,希望这很有用。更多好东西将要来了,敬请关注!
|
||||
|
||||
共勉!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-move-multiple-file-types-simultaneously-from-commandline/
|
||||
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.ostechnix.com/author/sk/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.ostechnix.com/find-copy-certain-type-files-one-directory-another-linux/
|
||||
[2]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[3]: http://www.ostechnix.com/wp-content/uploads/2019/01/mv-command.gif
|
||||
627
published/20190114 How to Build a Netboot Server, Part 4.md
Normal file
627
published/20190114 How to Build a Netboot Server, Part 4.md
Normal file
@@ -0,0 +1,627 @@
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "qhwdw"
|
||||
[#]: reviewer: "wxy"
|
||||
[#]: publisher: "wxy"
|
||||
[#]: url: "https://linux.cn/article-10470-1.html"
|
||||
[#]: subject: "How to Build a Netboot Server, Part 4"
|
||||
[#]: via: "https://fedoramagazine.org/how-to-build-a-netboot-server-part-4/"
|
||||
[#]: author: "Gregory Bartholomew https://fedoramagazine.org/author/glb/"
|
||||
|
||||
如何构建一台网络引导服务器(四)
|
||||
======
|
||||

|
||||
|
||||
在本系列教程中所构建的网络引导服务器有一个很重要的限制,那就是所提供的操作系统镜像是只读的。一些使用场景或许要求终端用户能够修改操作系统镜像。例如,一些教师或许希望学生能够安装和配置一些像 MariaDB 和 Node.js 这样的包来做为他们课程练习的一部分。
|
||||
|
||||
可写镜像的另外的好处是,终端用户“私人定制”的操作系统,在下次不同的工作站上使用时能够“跟着”他们。
|
||||
|
||||
### 修改 Bootmenu 应用程序以使用 HTTPS
|
||||
|
||||
为 bootmenu 应用程序创建一个自签名的证书:
|
||||
|
||||
```
|
||||
$ sudo -i
|
||||
# MY_NAME=$(</etc/hostname)
|
||||
# MY_TLSD=/opt/bootmenu/tls
|
||||
# mkdir $MY_TLSD
|
||||
# openssl req -newkey rsa:2048 -nodes -keyout $MY_TLSD/$MY_NAME.key -x509 -days 3650 -out $MY_TLSD/$MY_NAME.pem
|
||||
```
|
||||
|
||||
验证你的证书的值。确保 `Subject` 行中 `CN` 的值与你的 iPXE 客户端连接你的网络引导服务器所使用的 DNS 名字是相匹配的:
|
||||
|
||||
```
|
||||
# openssl x509 -text -noout -in $MY_TLSD/$MY_NAME.pem
|
||||
```
|
||||
|
||||
接下来,更新 bootmenu 应用程序去监听 HTTPS 端口和新创建的证书及密钥:
|
||||
|
||||
```
|
||||
# sed -i "s#listen => .*#listen => ['https://$MY_NAME:443?cert=$MY_TLSD/$MY_NAME.pem\&key=$MY_TLSD/$MY_NAME.key\&ciphers=AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA'],#" /opt/bootmenu/bootmenu.conf
|
||||
```
|
||||
|
||||
注意 [iPXE 当前支持的][1] 加密算法是有限制的。
|
||||
|
||||
GnuTLS 要求 “CAP_DAC_READ_SEARCH” 能力,因此将它添加到 bootmenu 应用程序的 systemd 服务:
|
||||
|
||||
```
|
||||
# sed -i '/^AmbientCapabilities=/ s/$/ CAP_DAC_READ_SEARCH/' /etc/systemd/system/bootmenu.service
|
||||
# sed -i 's/Serves iPXE Menus over HTTP/Serves iPXE Menus over HTTPS/' /etc/systemd/system/bootmenu.service
|
||||
# systemctl daemon-reload
|
||||
```
|
||||
|
||||
现在,在防火墙中为 bootmenu 服务添加一个例外规则并重启动该服务:
|
||||
|
||||
```
|
||||
# MY_SUBNET=192.0.2.0
|
||||
# MY_PREFIX=24
|
||||
# firewall-cmd --add-rich-rule="rule family='ipv4' source address='$MY_SUBNET/$MY_PREFIX' service name='https' accept"
|
||||
# firewall-cmd --runtime-to-permanent
|
||||
# systemctl restart bootmenu.service
|
||||
```
|
||||
|
||||
使用 `wget` 去验证是否工作正常:
|
||||
|
||||
```
|
||||
$ MY_NAME=server-01.example.edu
|
||||
$ MY_TLSD=/opt/bootmenu/tls
|
||||
$ wget -q --ca-certificate=$MY_TLSD/$MY_NAME.pem -O - https://$MY_NAME/menu
|
||||
```
|
||||
|
||||
### 添加 HTTPS 到 iPXE
|
||||
|
||||
更新 `init.ipxe` 去使用 HTTPS。接着使用选项重新编译 ipxe 引导加载器,以便它包含和信任你为 bootmenu 应用程序创建的自签名证书:
|
||||
|
||||
```
|
||||
$ echo '#define DOWNLOAD_PROTO_HTTPS' >> $HOME/ipxe/src/config/local/general.h
|
||||
$ sed -i 's/^chain http:/chain https:/' $HOME/ipxe/init.ipxe
|
||||
$ cp $MY_TLSD/$MY_NAME.pem $HOME/ipxe
|
||||
$ cd $HOME/ipxe/src
|
||||
$ make clean
|
||||
$ make bin-x86_64-efi/ipxe.efi EMBED=../init.ipxe CERT="../$MY_NAME.pem" TRUST="../$MY_NAME.pem"
|
||||
```
|
||||
|
||||
你现在可以将启用了 HTTPS 的 iPXE 引导加载器复制到你的客户端上,并测试它能否正常工作:
|
||||
|
||||
```
|
||||
$ cp $HOME/ipxe/src/bin-x86_64-efi/ipxe.efi $HOME/esp/efi/boot/bootx64.efi
|
||||
```
|
||||
|
||||
### 添加用户验证到 Mojolicious 中
|
||||
|
||||
为 bootmenu 应用程序创建一个 PAM 服务定义:
|
||||
|
||||
```
|
||||
# dnf install -y pam_krb5
|
||||
# echo 'auth required pam_krb5.so' > /etc/pam.d/bootmenu
|
||||
```
|
||||
|
||||
添加一个库到 bootmenu 应用程序中,它使用 Authen-PAM 的 Perl 模块去执行用户验证:
|
||||
|
||||
```
|
||||
# dnf install -y perl-Authen-PAM;
|
||||
# MY_MOJO=/opt/bootmenu
|
||||
# mkdir $MY_MOJO/lib
|
||||
# cat << 'END' > $MY_MOJO/lib/PAM.pm
|
||||
package PAM;
|
||||
|
||||
use Authen::PAM;
|
||||
|
||||
sub auth {
|
||||
my $success = 0;
|
||||
|
||||
my $username = shift;
|
||||
my $password = shift;
|
||||
|
||||
my $callback = sub {
|
||||
my @res;
|
||||
while (@_) {
|
||||
my $code = shift;
|
||||
my $msg = shift;
|
||||
my $ans = "";
|
||||
|
||||
$ans = $username if ($code == PAM_PROMPT_ECHO_ON());
|
||||
$ans = $password if ($code == PAM_PROMPT_ECHO_OFF());
|
||||
|
||||
push @res, (PAM_SUCCESS(), $ans);
|
||||
}
|
||||
push @res, PAM_SUCCESS();
|
||||
|
||||
return @res;
|
||||
};
|
||||
|
||||
my $pamh = new Authen::PAM('bootmenu', $username, $callback);
|
||||
|
||||
{
|
||||
last unless ref $pamh;
|
||||
last unless $pamh->pam_authenticate() == PAM_SUCCESS;
|
||||
$success = 1;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
return 1;
|
||||
END
|
||||
```
|
||||
|
||||
以上的代码是一字不差是从 Authen::PAM::FAQ 的 man 页面中复制来的。
|
||||
|
||||
重定义 bootmenu 应用程序,以使它仅当提供了有效的用户名和密码之后返回一个网络引导模板:
|
||||
|
||||
```
|
||||
# cat << 'END' > $MY_MOJO/bootmenu.pl
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use lib 'lib';
|
||||
|
||||
use PAM;
|
||||
use Mojolicious::Lite;
|
||||
use Mojolicious::Plugins;
|
||||
use Mojo::Util ('url_unescape');
|
||||
|
||||
plugin 'Config';
|
||||
|
||||
get '/menu';
|
||||
get '/boot' => sub {
|
||||
my $c = shift;
|
||||
|
||||
my $instance = $c->param('instance');
|
||||
my $username = $c->param('username');
|
||||
my $password = $c->param('password');
|
||||
|
||||
my $template = 'menu';
|
||||
|
||||
{
|
||||
last unless $instance =~ /^fc[[:digit:]]{2}$/;
|
||||
last unless $username =~ /^[[:alnum:]]+$/;
|
||||
last unless PAM::auth($username, url_unescape($password));
|
||||
$template = $instance;
|
||||
}
|
||||
|
||||
return $c->render(template => $template);
|
||||
};
|
||||
|
||||
app->start;
|
||||
END
|
||||
```
|
||||
|
||||
bootmenu 应用程序现在查找 `lib` 命令去找到相应的 `WorkingDirectory`。但是,默认情况下,对于 systemd 单元它的工作目录设置为服务器的 root 目录。因此,你必须更新 systemd 单元去设置 `WorkingDirectory` 为 bootmenu 应用程序的根目录:
|
||||
|
||||
```
|
||||
# sed -i "/^RuntimeDirectory=/ a WorkingDirectory=$MY_MOJO" /etc/systemd/system/bootmenu.service
|
||||
# systemctl daemon-reload
|
||||
```
|
||||
|
||||
更新模块去使用重定义后的 bootmenu 应用程序:
|
||||
|
||||
```
|
||||
# cd $MY_MOJO/templates
|
||||
# MY_BOOTMENU_SERVER=$(</etc/hostname)
|
||||
# MY_FEDORA_RELEASES="28 29"
|
||||
# for i in $MY_FEDORA_RELEASES; do echo '#!ipxe' > fc$i.html.ep; grep "^kernel\|initrd" menu.html.ep | grep "fc$i" >> fc$i.html.ep; echo "boot || chain https://$MY_BOOTMENU_SERVER/menu" >> fc$i.html.ep; sed -i "/^:f$i$/,/^boot /c :f$i\nlogin\nchain https://$MY_BOOTMENU_SERVER/boot?instance=fc$i\&username=\${username}\&password=\${password:uristring} || goto failed" menu.html.ep; done
|
||||
```
|
||||
|
||||
上面的最后的命令将生成类似下面的三个文件:
|
||||
|
||||
`menu.html.ep`:
|
||||
|
||||
```
|
||||
#!ipxe
|
||||
|
||||
set timeout 5000
|
||||
|
||||
:menu
|
||||
menu iPXE Boot Menu
|
||||
item --key 1 lcl 1. Microsoft Windows 10
|
||||
item --key 2 f29 2. RedHat Fedora 29
|
||||
item --key 3 f28 3. RedHat Fedora 28
|
||||
choose --timeout ${timeout} --default lcl selected || goto shell
|
||||
set timeout 0
|
||||
goto ${selected}
|
||||
|
||||
:failed
|
||||
echo boot failed, dropping to shell...
|
||||
goto shell
|
||||
|
||||
:shell
|
||||
echo type 'exit' to get the back to the menu
|
||||
set timeout 0
|
||||
shell
|
||||
goto menu
|
||||
|
||||
:lcl
|
||||
exit
|
||||
|
||||
:f29
|
||||
login
|
||||
chain https://server-01.example.edu/boot?instance=fc29&username=${username}&password=${password:uristring} || goto failed
|
||||
|
||||
:f28
|
||||
login
|
||||
chain https://server-01.example.edu/boot?instance=fc28&username=${username}&password=${password:uristring} || goto failed
|
||||
```
|
||||
|
||||
`fc29.html.ep`:
|
||||
|
||||
```
|
||||
#!ipxe
|
||||
kernel --name kernel.efi ${prefix}/vmlinuz-4.19.5-300.fc29.x86_64 initrd=initrd.img ro ip=dhcp rd.peerdns=0 nameserver=192.0.2.91 nameserver=192.0.2.92 root=/dev/disk/by-path/ip-192.0.2.158:3260-iscsi-iqn.edu.example.server-01:fc29-lun-1 netroot=iscsi:192.0.2.158::::iqn.edu.example.server-01:fc29 console=tty0 console=ttyS0,115200n8 audit=0 selinux=0 quiet
|
||||
initrd --name initrd.img ${prefix}/initramfs-4.19.5-300.fc29.x86_64.img
|
||||
boot || chain https://server-01.example.edu/menu
|
||||
```
|
||||
|
||||
`fc28.html.ep`:
|
||||
|
||||
```
|
||||
#!ipxe
|
||||
kernel --name kernel.efi ${prefix}/vmlinuz-4.19.3-200.fc28.x86_64 initrd=initrd.img ro ip=dhcp rd.peerdns=0 nameserver=192.0.2.91 nameserver=192.0.2.92 root=/dev/disk/by-path/ip-192.0.2.158:3260-iscsi-iqn.edu.example.server-01:fc28-lun-1 netroot=iscsi:192.0.2.158::::iqn.edu.example.server-01:fc28 console=tty0 console=ttyS0,115200n8 audit=0 selinux=0 quiet
|
||||
initrd --name initrd.img ${prefix}/initramfs-4.19.3-200.fc28.x86_64.img
|
||||
boot || chain https://server-01.example.edu/menu
|
||||
```
|
||||
|
||||
现在,重启动 bootmenu 应用程序,并验证用户认证是否正常工作:
|
||||
|
||||
```
|
||||
# systemctl restart bootmenu.service
|
||||
```
|
||||
|
||||
### 使得 iSCSI Target 可写
|
||||
|
||||
现在,用户验证通过 iPXE 可以正常工作,在用户连接时,你可以按需在只读镜像的上面创建每用户可写的<ruby>overlay<rt>叠加层</rt></ruby>。使用一个 [写时复制][2] 的叠加层与简单地为每个用户复制原始镜像相比有三个好处:
|
||||
|
||||
1. 副本创建非常快。这样就可以按需创建。
|
||||
2. 副本并不增加服务器上的磁盘使用。除了原始镜像之外,仅存储用户写入个人镜像的内容。
|
||||
3. 由于每个副本的扇区大多都是服务器的存储器上的相同扇区,在随后的用户访问这些操作系统的副本时,它们可能已经加载到内存中,这样就提升了服务器的性能,因为对内存的访问速度要比磁盘 I/O 快得多。
|
||||
|
||||
使用写时复制的一个潜在隐患是,一旦叠加层创建后,叠加层之下的镜像就不能再改变。如果它们改变,所有它们之上的叠加层将出错。因此,叠加层必须被删除并用新的、空白的进行替换。即便只是简单地以读写模式加载的镜像,也可能因为某些文件系统更新导致叠加层出错。
|
||||
|
||||
由于这个隐患,如果原始镜像被修改将导致叠加层出错,因此运行下列的命令,将原始镜像标记为不可改变:
|
||||
|
||||
```
|
||||
# chattr +i </path/to/file>
|
||||
```
|
||||
|
||||
你可以使用 `lsattr </path/to/file>` 去查看不可改变标志,并可以使用 `chattr -i </path/to/file>` 取消设置不可改变标志。在设置了不可改变标志之后,即便是 root 用户或以 root 运行的系统进程也不修改或删除这个文件。
|
||||
|
||||
停止 tgtd.service 之后,你就可以改变镜像文件:
|
||||
|
||||
```
|
||||
# systemctl stop tgtd.service
|
||||
```
|
||||
|
||||
当仍有连接打开的时候,运行这个命令一般需要一分钟或更长的时间。
|
||||
|
||||
现在,移除只读的 iSCSI 出口。然后更新模板中的 `readonly-root` 配置文件,以使镜像不再是只读的:
|
||||
|
||||
```
|
||||
# MY_FC=fc29
|
||||
# rm -f /etc/tgt/conf.d/$MY_FC.conf
|
||||
# TEMP_MNT=$(mktemp -d)
|
||||
# mount /$MY_FC.img $TEMP_MNT
|
||||
# sed -i 's/^READONLY=yes$/READONLY=no/' $TEMP_MNT/etc/sysconfig/readonly-root
|
||||
# sed -i 's/^Storage=volatile$/#Storage=auto/' $TEMP_MNT/etc/systemd/journald.conf
|
||||
# umount $TEMP_MNT
|
||||
```
|
||||
|
||||
将 journald 日志从发送到内存修改回缺省值(如果 `/var/log/journal` 存在的话记录到磁盘),因为一个用户报告说,他的客户端由于应用程序生成了大量的系统日志而产生内存溢出错误,导致它的客户端被卡住。而将日志记录到磁盘的负面影响是客户端产生了额外的写入流量,这将在你的网络引导服务器上可能增加一些没有必要的 I/O。你应该去决定到底使用哪个选择 —— 记录到内存还是记录到硬盘 —— 哪个更合适取决于你的环境。
|
||||
|
||||
因为你的模板镜像在以后不能做任何的更改,因此在它上面设置不可更改标志,然后重启动 tgtd.service:
|
||||
|
||||
```
|
||||
# chattr +i /$MY_FC.img
|
||||
# systemctl start tgtd.service
|
||||
```
|
||||
|
||||
现在,更新 bootmenu 应用程序:
|
||||
|
||||
```
|
||||
# cat << 'END' > $MY_MOJO/bootmenu.pl
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use lib 'lib';
|
||||
|
||||
use PAM;
|
||||
use Mojolicious::Lite;
|
||||
use Mojolicious::Plugins;
|
||||
use Mojo::Util ('url_unescape');
|
||||
|
||||
plugin 'Config';
|
||||
|
||||
get '/menu';
|
||||
get '/boot' => sub {
|
||||
my $c = shift;
|
||||
|
||||
my $instance = $c->param('instance');
|
||||
my $username = $c->param('username');
|
||||
my $password = $c->param('password');
|
||||
|
||||
my $chapscrt;
|
||||
my $template = 'menu';
|
||||
|
||||
{
|
||||
last unless $instance =~ /^fc[[:digit:]]{2}$/;
|
||||
last unless $username =~ /^[[:alnum:]]+$/;
|
||||
last unless PAM::auth($username, url_unescape($password));
|
||||
last unless $chapscrt = `sudo scripts/mktgt $instance $username`;
|
||||
$template = $instance;
|
||||
}
|
||||
|
||||
return $c->render(template => $template, username => $username, chapscrt => $chapscrt);
|
||||
};
|
||||
|
||||
app->start;
|
||||
END
|
||||
```
|
||||
|
||||
新版本的 bootmenu 应用程序调用一个定制的 `mktgt` 脚本,如果成功,它将为每个它自己创建的新的 iSCSI 目标返回一个随机的 [CHAP][3] 密码。这个 CHAP 密码可以防止其它用户的 iSCSI 目标以间接方式挂载这个用户的目标。这个应用程序只有在用户密码认证成功之后才返回一个正确的 iSCSI 目标密码。
|
||||
|
||||
`mktgt` 脚本要加 `sudo` 前缀来运行,因为它需要 root 权限去创建目标。
|
||||
|
||||
`$username` 和 `$chapscrt` 变量也传递给 `render` 命令,因此在需要的时候,它们也能够被纳入到模板中返回给用户。
|
||||
|
||||
接下来,更新我们的引导模板,以便于它们能够读取用户名和 `chapscrt` 变量,并传递它们到所属的终端用户。也要更新模板以 rw(读写)模式加载根文件系统:
|
||||
|
||||
```
|
||||
# cd $MY_MOJO/templates
|
||||
# sed -i "s/:$MY_FC/:$MY_FC-<%= \$username %>/g" $MY_FC.html.ep
|
||||
# sed -i "s/ netroot=iscsi:/ netroot=iscsi:<%= \$username %>:<%= \$chapscrt %>@/" $MY_FC.html.ep
|
||||
# sed -i "s/ ro / rw /" $MY_FC.html.ep
|
||||
```
|
||||
|
||||
运行上面的命令后,你应该会看到如下的引导模板:
|
||||
|
||||
```
|
||||
#!ipxe
|
||||
kernel --name kernel.efi ${prefix}/vmlinuz-4.19.5-300.fc29.x86_64 initrd=initrd.img rw ip=dhcp rd.peerdns=0 nameserver=192.0.2.91 nameserver=192.0.2.92 root=/dev/disk/by-path/ip-192.0.2.158:3260-iscsi-iqn.edu.example.server-01:fc29-<%= $username %>-lun-1 netroot=iscsi:<%= $username %>:<%= $chapscrt %>@192.0.2.158::::iqn.edu.example.server-01:fc29-<%= $username %> console=tty0 console=ttyS0,115200n8 audit=0 selinux=0 quiet
|
||||
initrd --name initrd.img ${prefix}/initramfs-4.19.5-300.fc29.x86_64.img
|
||||
boot || chain https://server-01.example.edu/menu
|
||||
```
|
||||
|
||||
注意:如果在 [插入][4] 变量后需要查看引导模板,你可以在 `boot` 命令之前,在它自己的行中插入 `shell` 命令。然后在你网络引导你的客户端时,iPXE 将在那里给你提供一个用于交互的 shell,你可以在 shell 中输入 `imgstat` 去查看传递到内核的参数。如果一切正确,你可以输入 `exit` 去退出 shell 并继续引导过程。
|
||||
|
||||
现在,通过 `sudo` 允许 bootmenu 用户以 root 权限去运行 `mktgt` 脚本(仅这个脚本):
|
||||
|
||||
```
|
||||
# echo "bootmenu ALL = NOPASSWD: $MY_MOJO/scripts/mktgt *" > /etc/sudoers.d/bootmenu
|
||||
```
|
||||
|
||||
bootmenu 用户不应该写访问 `mktgt` 脚本或在它的家目录下的任何其它文件。在 `/opt/bootmenu` 目录下的所有文件的属主应该是 root,并且不应该被其它任何 root 以外的用户可写。
|
||||
|
||||
`sudo` 在使用 systemd 的 `DynamicUser` 选项下不能正常工作,因此创建一个普通用户帐户,并设置 systemd 服务以那个用户运行:
|
||||
|
||||
```
|
||||
# useradd -r -c 'iPXE Boot Menu Service' -d /opt/bootmenu -s /sbin/nologin bootmenu
|
||||
# sed -i 's/^DynamicUser=true$/User=bootmenu/' /etc/systemd/system/bootmenu.service
|
||||
# systemctl daemon-reload
|
||||
```
|
||||
|
||||
最后,为写时复制覆盖创建一个目录,并创建管理 iSCSI 目标的 `mktgt` 脚本和它们的覆盖支持存储:
|
||||
|
||||
```
|
||||
# mkdir /$MY_FC.cow
|
||||
# mkdir $MY_MOJO/scripts
|
||||
# cat << 'END' > $MY_MOJO/scripts/mktgt
|
||||
#!/usr/bin/env perl
|
||||
|
||||
# if another instance of this script is running, wait for it to finish
|
||||
"$ENV{FLOCKER}" eq 'MKTGT' or exec "env FLOCKER=MKTGT flock /tmp $0 @ARGV";
|
||||
|
||||
# use "RETURN" to print to STDOUT; everything else goes to STDERR by default
|
||||
open(RETURN, '>&', STDOUT);
|
||||
open(STDOUT, '>&', STDERR);
|
||||
|
||||
my $instance = shift or die "instance not provided";
|
||||
my $username = shift or die "username not provided";
|
||||
|
||||
my $img = "/$instance.img";
|
||||
my $dir = "/$instance.cow";
|
||||
my $top = "$dir/$username";
|
||||
|
||||
-f "$img" or die "'$img' is not a file";
|
||||
-d "$dir" or die "'$dir' is not a directory";
|
||||
|
||||
my $base;
|
||||
die unless $base = `losetup --show --read-only --nooverlap --find $img`;
|
||||
chomp $base;
|
||||
|
||||
my $size;
|
||||
die unless $size = `blockdev --getsz $base`;
|
||||
chomp $size;
|
||||
|
||||
# create the per-user sparse file if it does not exist
|
||||
if (! -e "$top") {
|
||||
die unless system("dd if=/dev/zero of=$top status=none bs=512 count=0 seek=$size") == 0;
|
||||
}
|
||||
|
||||
# create the copy-on-write overlay if it does not exist
|
||||
my $cow="$instance-$username";
|
||||
my $dev="/dev/mapper/$cow";
|
||||
if (! -e "$dev") {
|
||||
my $over;
|
||||
die unless $over = `losetup --show --nooverlap --find $top`;
|
||||
chomp $over;
|
||||
die unless system("echo 0 $size snapshot $base $over p 8 | dmsetup create $cow") == 0;
|
||||
}
|
||||
|
||||
my $tgtadm = '/usr/sbin/tgtadm --lld iscsi';
|
||||
|
||||
# get textual representations of the iscsi targets
|
||||
my $text = `$tgtadm --op show --mode target`;
|
||||
my @targets = $text =~ /(?:^T.*\n)(?:^ .*\n)*/mg;
|
||||
|
||||
# convert the textual representations into a hash table
|
||||
my $targets = {};
|
||||
foreach (@targets) {
|
||||
my $tgt;
|
||||
my $sid;
|
||||
|
||||
foreach (split /\n/) {
|
||||
/^Target (\d+)(?{ $tgt = $targets->{$^N} = [] })/;
|
||||
/I_T nexus: (\d+)(?{ $sid = $^N })/;
|
||||
/Connection: (\d+)(?{ push @{$tgt}, [ $sid, $^N ] })/;
|
||||
}
|
||||
}
|
||||
|
||||
my $hostname;
|
||||
die unless $hostname = `hostname`;
|
||||
chomp $hostname;
|
||||
|
||||
my $target = 'iqn.' . join('.', reverse split('\.', $hostname)) . ":$cow";
|
||||
|
||||
# find the target id corresponding to the provided target name and
|
||||
# close any existing connections to it
|
||||
my $tid = 0;
|
||||
foreach (@targets) {
|
||||
next unless /^Target (\d+)(?{ $tid = $^N }): $target$/m;
|
||||
foreach (@{$targets->{$tid}}) {
|
||||
die unless system("$tgtadm --op delete --mode conn --tid $tid --sid $_->[0] --cid $_->[1]") == 0;
|
||||
}
|
||||
}
|
||||
|
||||
# create a new target if an existing one was not found
|
||||
if ($tid == 0) {
|
||||
# find an available target id
|
||||
my @ids = (0, sort keys %{$targets});
|
||||
$tid = 1; while ($ids[$tid]==$tid) { $tid++ }
|
||||
|
||||
# create the target
|
||||
die unless -e "$dev";
|
||||
die unless system("$tgtadm --op new --mode target --tid $tid --targetname $target") == 0;
|
||||
die unless system("$tgtadm --op new --mode logicalunit --tid $tid --lun 1 --backing-store $dev") == 0;
|
||||
die unless system("$tgtadm --op bind --mode target --tid $tid --initiator-address ALL") == 0;
|
||||
}
|
||||
|
||||
# (re)set the provided target's chap password
|
||||
my $password = join('', map(chr(int(rand(26))+65), 1..8));
|
||||
my $accounts = `$tgtadm --op show --mode account`;
|
||||
if ($accounts =~ / $username$/m) {
|
||||
die unless system("$tgtadm --op delete --mode account --user $username") == 0;
|
||||
}
|
||||
die unless system("$tgtadm --op new --mode account --user $username --password $password") == 0;
|
||||
die unless system("$tgtadm --op bind --mode account --tid $tid --user $username") == 0;
|
||||
|
||||
# return the new password to the iscsi target on stdout
|
||||
print RETURN $password;
|
||||
END
|
||||
# chmod +x $MY_MOJO/scripts/mktgt
|
||||
```
|
||||
|
||||
上面的脚本将做以下五件事情:
|
||||
|
||||
1. 创建 `/<instance>.cow/<username>` 稀疏文件(如果不存在的话)。
|
||||
2. 创建 `/dev/mapper/<instance>-<username>` 设备节点作为 iSCSI 目标的写时复制支持存储(如果不存在的话)。
|
||||
3. 创建 `iqn.<reverse-hostname>:<instance>-<username>` iSCSI 目标(如果不存在的话)。或者,如果已存在了,它将关闭任何已存在的连接,因为在任何时刻,镜像只能以只读模式从一个地方打开。
|
||||
4. 它在 `iqn.<reverse-hostname>:<instance>-<username>` iSCSI 目标上(重新)设置 chap 密码为一个新的随机值。
|
||||
5. (如果前面的所有任务都成功的话)它在 [标准输出][5] 上显示新的 chap 密码。
|
||||
|
||||
你应该可以在命令行上通过使用有效的测试参数来运行它,以测试 `mktgt` 脚本能否正常工作。例如:
|
||||
|
||||
```
|
||||
# echo `$MY_MOJO/scripts/mktgt fc29 jsmith`
|
||||
```
|
||||
|
||||
当你从命令行上运行时,`mktgt` 脚本应该会输出 iSCSI 目标的一个随意的八字符随机密码(如果成功的话)或者是出错位置的行号(如果失败的话)。
|
||||
|
||||
有时候,你可能需要在不停止整个服务的情况下删除一个 iSCSI 目标。例如,一个用户可能无意中损坏了他的个人镜像,在那种情况下,你可能需要按步骤撤销上面的 `mktgt` 脚本所做的事情,以便于他下次登入时他将得到一个原始镜像。
|
||||
|
||||
下面是用于撤销的 `rmtgt` 脚本,它以相反的顺序做了上面 `mktgt` 脚本所做的事情:
|
||||
|
||||
```
|
||||
# mkdir $HOME/bin
|
||||
# cat << 'END' > $HOME/bin/rmtgt
|
||||
#!/usr/bin/env perl
|
||||
|
||||
@ARGV >= 2 or die "usage: $0 <instance> <username> [+d|+f]\n";
|
||||
|
||||
my $instance = shift;
|
||||
my $username = shift;
|
||||
|
||||
my $rmd = ($ARGV[0] eq '+d'); #remove device node if +d flag is set
|
||||
my $rmf = ($ARGV[0] eq '+f'); #remove sparse file if +f flag is set
|
||||
my $cow = "$instance-$username";
|
||||
|
||||
my $hostname;
|
||||
die unless $hostname = `hostname`;
|
||||
chomp $hostname;
|
||||
|
||||
my $tgtadm = '/usr/sbin/tgtadm';
|
||||
my $target = 'iqn.' . join('.', reverse split('\.', $hostname)) . ":$cow";
|
||||
|
||||
my $text = `$tgtadm --op show --mode target`;
|
||||
my @targets = $text =~ /(?:^T.*\n)(?:^ .*\n)*/mg;
|
||||
|
||||
my $targets = {};
|
||||
foreach (@targets) {
|
||||
my $tgt;
|
||||
my $sid;
|
||||
|
||||
foreach (split /\n/) {
|
||||
/^Target (\d+)(?{ $tgt = $targets->{$^N} = [] })/;
|
||||
/I_T nexus: (\d+)(?{ $sid = $^N })/;
|
||||
/Connection: (\d+)(?{ push @{$tgt}, [ $sid, $^N ] })/;
|
||||
}
|
||||
}
|
||||
|
||||
my $tid = 0;
|
||||
foreach (@targets) {
|
||||
next unless /^Target (\d+)(?{ $tid = $^N }): $target$/m;
|
||||
foreach (@{$targets->{$tid}}) {
|
||||
die unless system("$tgtadm --op delete --mode conn --tid $tid --sid $_->[0] --cid $_->[1]") == 0;
|
||||
}
|
||||
die unless system("$tgtadm --op delete --mode target --tid $tid") == 0;
|
||||
print "target $tid deleted\n";
|
||||
sleep 1;
|
||||
}
|
||||
|
||||
my $dev = "/dev/mapper/$cow";
|
||||
if ($rmd or ($rmf and -e $dev)) {
|
||||
die unless system("dmsetup remove $cow") == 0;
|
||||
print "device node $dev deleted\n";
|
||||
}
|
||||
|
||||
if ($rmf) {
|
||||
my $sf = "/$instance.cow/$username";
|
||||
die "sparse file $sf not found" unless -e "$sf";
|
||||
die unless system("rm -f $sf") == 0;
|
||||
die unless not -e "$sf";
|
||||
print "sparse file $sf deleted\n";
|
||||
}
|
||||
END
|
||||
# chmod +x $HOME/bin/rmtgt
|
||||
```
|
||||
|
||||
例如,使用上面的脚本去完全删除 fc29-jsmith 目标,包含它的支持存储设备节点和稀疏文件,可以按下列方式运行命令:
|
||||
|
||||
```
|
||||
# rmtgt fc29 jsmith +f
|
||||
```
|
||||
|
||||
一旦你验证 `mktgt` 脚本工作正常,你可以重启动 bootmenu 服务。下次有人从网络引导时,他们应该能够接收到一个他们可以写入的、可”私人定制“的网络引导镜像的副本:
|
||||
|
||||
```
|
||||
# systemctl restart bootmenu.service
|
||||
```
|
||||
|
||||
现在,就像下面的截屏示范的那样,用户应该可以修改根文件系统了:
|
||||
|
||||
![][6]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/how-to-build-a-netboot-server-part-4/
|
||||
|
||||
作者:[Gregory Bartholomew][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/glb/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: http://ipxe.org/crypto
|
||||
[2]: https://en.wikipedia.org/wiki/Copy-on-write
|
||||
[3]: https://en.wikipedia.org/wiki/Challenge-Handshake_Authentication_Protocol
|
||||
[4]: https://en.wikipedia.org/wiki/String_interpolation
|
||||
[5]: https://en.wikipedia.org/wiki/Standard_streams
|
||||
[6]: https://fedoramagazine.org/wp-content/uploads/2018/11/netboot-fix-pam_mount-1024x819.png
|
||||
82
published/20190114 You (probably) don-t need Kubernetes.md
Normal file
82
published/20190114 You (probably) don-t need Kubernetes.md
Normal file
@@ -0,0 +1,82 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (beamrolling)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10469-1.html)
|
||||
[#]: subject: (You (probably) don't need Kubernetes)
|
||||
[#]: via: (https://arp242.net/weblog/dont-need-k8s.html)
|
||||
[#]: author: (Martin Tournoij https://arp242.net/)
|
||||
|
||||
你(多半)不需要 Kubernetes
|
||||
======
|
||||
|
||||
这也许是一个不太受欢迎的观点,但大多数主流公司最好不要再使用 k8s 了。
|
||||
|
||||
你知道那个古老的“以程序员技能写 Hello world ”笑话吗?—— 从一个新手程序员的 `printf("hello, world\n")` 语句开始,最后结束于高级软件架构工程师令人费解的 Java OOP 模式设计。使用 k8s 就有点像这样。
|
||||
|
||||
* 新手系统管理员:
|
||||
|
||||
`./binary`
|
||||
* 有经验的系统管理员:
|
||||
|
||||
在 EC2 上的 `./binary`
|
||||
* DevOp:
|
||||
|
||||
在 EC2 上自部署的 CI 管道运行 `./binary`
|
||||
* 高级云编排工程师:
|
||||
|
||||
在 EC2 上通过 k8s 编排的自部署 CI 管道运行 `./binary`
|
||||
|
||||
`¯\\_(ツ)_/¯`
|
||||
|
||||
这不意味着 Kubernetes 或者任何这样的东西本身都是*坏的*,就像 Java 或者 OOP 设计本身并不是坏的一样,但是,在很多情况下,它们被严重地误用,就像在一个 hello world 的程序中可怕地误用 Java 面向对象设计模式一样。对大多数公司而言,系统运维从根本上来说并不十分复杂,此时在这上面应用 k8s 起效甚微。
|
||||
|
||||
复杂性本质上来说创造了工作,我十分怀疑使用 k8s 对大多数使用者来说是省时的这一说法。这就好像花一天时间来写一个脚本,用来自动完成一些你一个月进行一次,每次只花 10 分钟完成的工作。这不是一个好的时间投资(特别是你可能会在未来由于扩展或调试这个脚本而进一步投入的更多时间)。
|
||||
|
||||
你的部署大概应该*需要*自动化 – 以免你 [最终像 Knightmare][1] 那样 —— 但 k8s 通常可以被一个简单的 shell 脚本所替代。
|
||||
|
||||
在我们公司,系统运维团队用了很多时间来设置 k8s 。他们还不得不用了很大一部分时间来更新到新一点的版本(1.6 ➙ 1.8)。结果是如果没有真正深入理解 k8s ,有些东西就没人会真的明白,甚至连深入理解 k8s 这一点也很难(那些 YAML 文件,哦呦!)
|
||||
|
||||
在我能自己调试和修复部署问题之前 —— 现在这更难了,我理解基本概念,但在真正调试实际问题的时候,它们并不是那么有用。我不经常用 k8s 足以证明这点。
|
||||
|
||||
---
|
||||
|
||||
k8s 真的很难这点并不是什么新看法,这也是为什么现在会有这么多 “k8s 简单用”的解决方案。在 k8s 上再添一层来“让它更简单”的方法让我觉得,呃,不明智。复杂性并没有消失,你只是把它藏起来了。
|
||||
|
||||
以前我说过很多次:在确定一样东西是否“简单”时,我最关心的不是写东西的时候有多简单,而是当失败的时候调试起来有多容易。包装 k8s 并不会让调试更加简单,恰恰相反,它让事情更加困难了。
|
||||
|
||||
---
|
||||
|
||||
Blaise Pascal 有一句名言:
|
||||
|
||||
> 几乎所有的痛苦都来自于我们不善于在房间里独处。
|
||||
|
||||
k8s —— 略微拓展一下,Docker —— 似乎就是这样的例子。许多人似乎迷失在当下的兴奋中,觉得 “k8s 就是这么回事!”,就像有些人迷失在 Java OOP 刚出来时的兴奋中一样,所以一切都必须从“旧”方法转为“新”方法,即使“旧”方法依然可行。
|
||||
|
||||
有时候 IT 产业挺蠢的。
|
||||
|
||||
或者用 [一条推特][2] 来总结:
|
||||
|
||||
> - 2014 - 我们必须采用 #微服务 来解决独石应用的所有问题
|
||||
> - 2016 - 我们必须采用 #docker 来解决微服务的所有问题
|
||||
> - 2018 - 我们必须采用 #kubernetes 来解决 docker 的所有问题
|
||||
|
||||
你可以通过 [martin@arp242.net][3] 给我发邮件或者 [创建 GitHub issue][4] 来给我反馈或提出问题等。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://arp242.net/weblog/dont-need-k8s.html
|
||||
|
||||
作者:[Martin Tournoij][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[beamrolling](https://github.com/beamrolling)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://arp242.net/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://dougseven.com/2014/04/17/knightmare-a-devops-cautionary-tale/
|
||||
[2]: https://twitter.com/sahrizv/status/1018184792611827712
|
||||
[3]: mailto:martin@arp242.net
|
||||
[4]: https://github.com/Carpetsmoker/arp242.net/issues/new
|
||||
185
published/20190115 Linux Tools- The Meaning of Dot.md
Normal file
185
published/20190115 Linux Tools- The Meaning of Dot.md
Normal file
@@ -0,0 +1,185 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (asche910)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-10465-1.html)
|
||||
[#]: subject: (Linux Tools: The Meaning of Dot)
|
||||
[#]: via: (https://www.linux.com/blog/learn/2019/1/linux-tools-meaning-dot)
|
||||
[#]: author: (Paul Brown https://www.linux.com/users/bro66)
|
||||
|
||||
Linux 工具:点的含义
|
||||
======
|
||||
|
||||
> Paul Brown 解释了 Linux shell 命令中那个不起眼的“点”的各种意思和用法。
|
||||
|
||||

|
||||
|
||||
在现实情况中,使用 shell 命令编写的单行命令或脚本可能会令人很困惑。你使用的很多工具的名称与它们的实际功能相差甚远(`grep`、`tee` 和 `awk`,还有吗?),而当你将两个或更多个组合起来时,所组成的 “句子” 看起来更像某种外星人的天书。
|
||||
|
||||
因此,上面说的这些对于你并无帮助,因为你用来编写一连串的指令所使用的符号根据你使用的场景有着不同的意义。
|
||||
|
||||
### 位置、位置、位置
|
||||
|
||||
就拿这个不起眼的点(`.`)来说吧。当它放在一个需要一个目录名称的命令的参数处时,表示“当前目录”:
|
||||
|
||||
```
|
||||
find . -name "*.jpg"
|
||||
```
|
||||
|
||||
意思就是“在当前目录(包括子目录)中寻找以 `.jpg` 结尾的文件”。
|
||||
|
||||
`ls .` 和 `cd .` 结果也如你想的那样,它们分别列举和“进入”到当前目录,虽然在这两种情况下这个点都是多余的。
|
||||
|
||||
而一个紧接着另一个的两个点呢,在同样的场景下(即当你的命令期望一个文件目录的时候)表示“当前目录的父目录”。如果你当前在 `/home/your_directory` 下并且运行:
|
||||
|
||||
```
|
||||
cd ..
|
||||
```
|
||||
|
||||
你就会进入到 `/home`。所以,你可能认为这仍然适合“点代表附近目录”的叙述,并且毫不复杂,对吧?
|
||||
|
||||
那下面这样会怎样呢?如果你在一个文件或目录的开头加上点,它表示这个文件或目录会被隐藏:
|
||||
|
||||
```
|
||||
$ touch somedir/file01.txt somedir/file02.txt somedir/.secretfile.txt
|
||||
$ ls -l somedir/
|
||||
total 0
|
||||
-rw-r--r-- 1 paul paul 0 Jan 13 19:57 file01.txt
|
||||
-rw-r--r-- 1 paul paul 0 Jan 13 19:57 file02.txt
|
||||
$ # 注意上面列举的文件中没有 .secretfile.txt
|
||||
$ ls -la somedir/
|
||||
total 8
|
||||
drwxr-xr-x 2 paul paul 4096 Jan 13 19:57 .
|
||||
drwx------ 48 paul paul 4096 Jan 13 19:57 ..
|
||||
-rw-r--r-- 1 paul paul 0 Jan 13 19:57 file01.txt
|
||||
-rw-r--r-- 1 paul paul 0 Jan 13 19:57 file02.txt
|
||||
-rw-r--r-- 1 paul paul 0 Jan 13 19:57 .secretfile.txt
|
||||
$ # 这个 -a 选项告诉 ls 去展示“all”文件,包括那些隐藏的
|
||||
```
|
||||
|
||||
然后就是你可以将 `.` 当作命令。是的,你听我说:`.` 是个真真正正的命令。它是 `source` 命令的代名词,所以你可以用它在当前 shell 中执行一个文件,而不是以某种其它的方式去运行一个脚本文件(这通常指的是 Bash 会产生一个新的 shell 去运行它)
|
||||
|
||||
很困惑?别担心 —— 试试这个:创建一个名为 `myscript` 的脚本,内容包含下面一行:
|
||||
|
||||
```
|
||||
myvar="Hello"
|
||||
```
|
||||
|
||||
然后通过常规的方法执行它,也就是用 `sh myscript`(或者通过 `chmod a+x myscript` 命令让它可执行,然后运行 `./myscript`)。现在尝试并且观察 `myvar` 的内容,通过 `echo $myvar`(理所当然你什么也得不到)。那是因为,当你的脚本赋值 `"Hello"` 给 `myvar` 时,它是在一个隔离的bash shell 实例中进行的。当脚本运行结束时,这个新产生的实例会消失并且将控制权转交给原来的shell,而原来的 shell 里甚至都不存在 `myvar` 变量。
|
||||
|
||||
然而,如果你这样运行 `myscript`:
|
||||
|
||||
```
|
||||
. myscript
|
||||
```
|
||||
|
||||
`echo $myvar` 就会打印 `Hello` 到命令行上。
|
||||
|
||||
当你的 `.bashrc` 文件发生变化后,你经常会用到 `.`(或 `source`)命令,[就像当你要扩展 `PATH` 变量那样][1]。在你的当前 shell 实例中,你可以使用 `.` 来让变化立即生效。
|
||||
|
||||
### 双重麻烦
|
||||
|
||||
就像看似无关紧要的一个点有多个含义一样,两个点也是如此。除了指向当前目录的父级之外,两个点(`..`)也用于构建序列。
|
||||
|
||||
尝试下这个:
|
||||
|
||||
```
|
||||
echo {1..10}
|
||||
```
|
||||
|
||||
它会打印出从 1 到 10 的序列。在这种场景下,`..` 表示 “从左边的值开始,计数到右边的值”。
|
||||
|
||||
现在试下这个:
|
||||
|
||||
```
|
||||
echo {1..10..2}
|
||||
```
|
||||
|
||||
你会得到 `1 3 5 7 9`。`..2` 这部分命令告诉 Bash 输出这个序列,不过不是每个相差 1,而是相差 2。换句话说,就是你会得到从 1 到 10 之间的奇数。
|
||||
|
||||
它反着也仍然有效:
|
||||
|
||||
```
|
||||
echo {10..1..2}
|
||||
```
|
||||
|
||||
你也可以用多个 0 填充你的数字。这样:
|
||||
|
||||
```
|
||||
echo {000..121..2}
|
||||
```
|
||||
|
||||
会这样打印出从 0 到 121 之间的偶数(填充了前置 0):
|
||||
|
||||
```
|
||||
000 002 004 006 ... 050 052 054 ... 116 118 120
|
||||
```
|
||||
|
||||
不过这样的序列发生器有啥用呢?当然,假设您的新年决心之一是更加谨慎控制您的帐户花销。作为决心的一部分,您需要创建目录,以便对过去 10 年的数字发票进行分类:
|
||||
|
||||
```
|
||||
mkdir {2009..2019}_Invoices
|
||||
```
|
||||
|
||||
工作完成。
|
||||
|
||||
或者你可能有数百个带编号的文件,比如从视频剪辑中提取的帧,或许因为某种原因,你只想从第 43 帧到第 61 帧每隔三帧删除一帧:
|
||||
|
||||
```
|
||||
rm frame_{043..61..3}
|
||||
```
|
||||
|
||||
很可能,如果你有超过 100 个帧,它们将以填充 0 命名,如下所示:
|
||||
|
||||
```
|
||||
frame_000 frame_001 frame_002 ...
|
||||
```
|
||||
|
||||
那就是为什么你在命令中要用 `043`,而不是`43` 的原因。
|
||||
|
||||
### 花括号花招
|
||||
|
||||
说实话,序列的神奇之处不在于双点,而是花括号(`{}`)的巫术。看看它对于字母是如何工作的。这样做:
|
||||
|
||||
```
|
||||
touch file_{a..z}.txt
|
||||
```
|
||||
|
||||
它创建了从 `file_a.txt` 到 `file_z.txt` 的文件。
|
||||
|
||||
但是,你必须小心。使用像 `{Z..a}` 这样的序列将产生一大堆大写字母和小写字母之间的非字母、数字的字符(既不是数字或字母的字形)。其中一些字形是不可打印的或具有自己的特殊含义。使用它们来生成文件名称可能会导致一系列意外和可能令人不快的影响。
|
||||
|
||||
最后一件值得指出的事:包围在 `{...}` 的序列,它们也可以包含字符串列表:
|
||||
|
||||
```
|
||||
touch {blahg, splurg, mmmf}_file.txt
|
||||
```
|
||||
|
||||
将创建了 `blahg_file.txt`、`splurg_file.txt` 和 `mmmf_file.txt`。
|
||||
|
||||
当然,在别的场景中,大括号也有不同的含义(惊喜吗!)。不过那是别的文章的内容了。
|
||||
|
||||
### 总结
|
||||
|
||||
Bash 以及运行于其中的各种工具已经被寻求解决各种特定问题的系统管理员们把玩了数十年。要说这种有自己之道的系统管理员是一种特殊物种的话,那是有点轻描淡写。总而言之,与其他语言相反,Bash 的设计目标并不是为了用户友好、简单、甚至合乎逻辑。
|
||||
|
||||
但这并不意味着它不强大 —— 恰恰相反。Bash 的语法和 shell 工具可能不一致且很庞大,但它们也提供了一系列令人眼花缭乱的方法来完成您可能想象到的一切。就像有一个工具箱,你可以从中找到从电钻到勺子的所有东西,以及橡皮鸭、一卷胶带和一些指甲钳。
|
||||
|
||||
除了引人入胜之外,探明你可以直接在 shell 中达成的所有能力也很有趣,所以下次我们将深入探讨如何构建更大更好的 Bash 命令行。
|
||||
|
||||
在那之前,玩得开心!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/blog/learn/2019/1/linux-tools-meaning-dot
|
||||
|
||||
作者:[Paul Brown][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[asche910](https://github.com/asche910)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.linux.com/users/bro66
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.linux.com/blog/learn/2018/12/bash-variables-environmental-and-otherwise
|
||||
@@ -1,60 +0,0 @@
|
||||
translated by lixinyuxx
|
||||
6 common questions about agile development practices for teams
|
||||
======
|
||||
|
||||

|
||||
"Any questions?"
|
||||
|
||||
You’ve probably heard a speaker ask this question at the end of their presentation. This is the most important part of the presentation—after all, you didn't attend just to hear a lecture but to participate in a conversation and a community.
|
||||
|
||||
Recently I had the opportunity to hear my fellow Red Hatters present a session called "[Agile in Practice][1]" to a group of technical students at a local university. During the session, software engineer Tomas Tomecek and agile practitioners Fernando Colleone and Pavel Najman collaborated to explain the foundations of agile methodology and showcase best practices for day-to-day activities.
|
||||
|
||||
### 1\. What is the perfect team size?
|
||||
|
||||
Knowing that students attended this session to learn what agile practice is and how to apply it to projects, I wondered how the students' questions would compare to those I hear every day as an agile practitioner at Red Hat. It turns out that the students asked the same questions as my colleagues. These questions drive straight into the core of agile in practice.
|
||||
|
||||
Students wanted to know the size of a small team versus a large team. This issue is relevant to anyone who has ever teamed up to work on a project. Based on Tomas's experience as a tech leader, 12 people working on a project would be considered a large team. In the real world, team size is not often directly correlated to productivity. In some cases, a smaller team located in a single location or time zone might be more productive than a larger team that's spread around the world. Ultimately, the presenters suggested that the ideal team size is probably five people (which aligns with scrum 7, +-2).
|
||||
|
||||
### 2\. What operational challenges do teams face?
|
||||
|
||||
The presenters compared projects supported by local teams (teams with all members in one office or within close proximity to each other) with distributed teams (teams located in different time zones). Engineers prefer local teams when the project requires close cooperation among team members because delays caused by time differences can destroy the "flow" of writing software. At the same time, distributed teams can bring together skill sets that may not be available locally and are great for certain development use cases. Also, there are various best practices to improve cooperation in distributed teams.
|
||||
|
||||
### 3\. How much time is needed to groom the backlog?
|
||||
|
||||
Because this was an introductory talk targeting students who were new to agile, the speakers focused on [Scrum][2] and [Kanban][3] as ways to make agile specific for them. They used the Scrum framework to illustrate a method of writing software and Kanban for a communication and work planning system. On the question of time needed to groom a project's backlog, the speakers explained that there is no fixed rule. Rather, practice makes perfect: During the early stages of development, when a project is new—and especially if some members of the team are new to agile—grooming can consume several hours per week. Over time and with practice, it becomes more efficient.
|
||||
|
||||
### 4\. Is a product owner necessary? What is their role?
|
||||
|
||||
Product owners help facilitate scaling; however, what matters is not the job title, but that you have someone on your team who represents the customer's voice and goals. In many teams, especially those that are part of a larger group of engineering teams working on a single output, a lead engineer can serve as the product owner.
|
||||
|
||||
### 5\. What agile tools do you suggest using? Is specific software necessary to implement Scrum or Kanban in practice?
|
||||
|
||||
Although using proprietary software such as Jira or Trello can be helpful, especially when working with large numbers of contributors working on big enterprise projects, they are not required. Scrum and Kanban can be done with tools as simple as paper cards. The key is to have a clear source of information and strong communication across the entire team. That said, two excellent open source kanban tools are [Taiga][4] and [Wekan][5]. For more information, see [5 open source alternatives to Trello][6] and [Top 7 open source project management tools for agile teams][7].
|
||||
|
||||
### 6\. How can students use agile techniques for school projects?
|
||||
|
||||
The presenters encouraged students to use kanban to visualize and outline tasks to be completed before the end of the project. The key is to create a common board so the entire team can see the status of the project. By using kanban or a similar high-visibility strategy, students won’t get to the end of the project and discover that any particular team member has not been keeping up.
|
||||
|
||||
Scrum practices such as sprints and daily standups are also excellent ways to ensure that everyone is making progress and that the various parts of the project will work together at the end. Regular check-ins and information-sharing are also essential. To learn more about Scrum, see [What is scrum?][8].
|
||||
|
||||
Remember that Kanban and Scrum are just two of many tools and frameworks that make up agile. They may not be the best approach for every situation.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/3/agile-mindset
|
||||
|
||||
作者:[Dominika Bula][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/dominika
|
||||
[1]:http://zijemeit.cz/sessions/agile-in-practice/
|
||||
[2]:https://www.scrum.org/resources/what-is-scrum
|
||||
[3]:https://en.wikipedia.org/wiki/Kanban
|
||||
[4]:https://taiga.io/
|
||||
[5]:https://wekan.github.io/
|
||||
[6]:https://opensource.com/alternatives/trello
|
||||
[7]:https://opensource.com/article/18/2/agile-project-management-tools
|
||||
[8]:https://opensource.com/resources/scrum
|
||||
@@ -1,128 +0,0 @@
|
||||
zhs852 is translating.
|
||||
|
||||
Dawn of the Microcomputer: The Altair 8800
|
||||
======
|
||||
Subscribers to Popular Electronics were a sophisticated group. The magazine’s editor, Arthur Salsberg, felt compelled to point out as much in the editorial section of the [December 1974 issue][1]. The magazine had received letters complaining that a recent article, titled “How to Set Up a Home TV Service Shop,” would inspire a horde of amateur TV technicians to go out and undercut professional repairmen, doing great damage to everyone’s TVs in the process. Salsberg thought this concern was based on a misunderstanding about who read Popular Electronics. He explained that, according to the magazine’s own surveys, 52% of Popular Electronics subscribers were electronics professionals of some kind and 150,000 of them had repaired a TV in the last 60 days. Moreover, the average Popular Electronics subscriber had spent $470 on electronics equipment ($3578 in 2018) and possessed such necessities as VOMs, VTVMs, tube testers, transistor testers, r-f signal generators, and scopes. “Popular Electronics readers are not largely neophytes,” Salsberg concluded.
|
||||
|
||||
I am surprised that anyone familiar with Popular Electronics could ever have doubted its subscribers. I certainly haven’t repaired a TV in the last 60 days. My computer is a block of aluminum that I have never seen the inside of. Yet the December 1974 issue of Popular Electronics features articles such as “Standing Wave Ratio: What It Is and How to Deal with It” and “Test Scene: Uses for Your Multimeter.” Even the ads are intimidating. One of them, which seems to be for some kind of stereo system, boldly proclaims that “no piece of audio equipment is as eagerly awaited as the ‘one four-channel unit that does everything—i.e. the receiver with built-in circuitry for SQ, RM and CD-4 record decoding.’” The mere hobbyists subscribed to Popular Electronics, let alone the professionals, must have been very knowledgeable indeed.
|
||||
|
||||
But Popular Electronics readers were introduced to something in the [January 1975 issue][2] that they had never encountered before. Below a heading that read “PROJECT BREAKTHROUGH,” the magazine’s cover showed a large gray and black box whose front panel bore a complicated array of lights and toggles. This was the Altair 8800, the “world’s first minicomputer kit to rival commercial models,” available for under $400. Though advertised as a “minicomputer,” the Altair would actually be the first commercially successful member of a new class of computers, first known as “microcomputers” and then eventually as PCs. The Altair was small enough and cheap enough that the average family could have one at home. Its appearance in Popular Electronics magazine meant that, as Salsberg wrote in that issue, “the home computer age is here—finally.”
|
||||
|
||||
![January 1975 cover of Popular Electronics][3]
|
||||
|
||||
I have written briefly about [the Altair before][4], but I think the Altair is worth revisiting. It was not an especially powerful computer compared to others available at the time (though it cost significantly less money). Nor was it the first general-purpose computer to incorporate a microprocessor chip—at least three microprocessor-based computers preceded it. But the Altair was and is a kind of Ur-Computer for all of us. It was the first popular computer in a lineage that includes our own devices, whereas the mainframes and bulky minicomputers that predated the Altair were an entirely different kind of machine, programmed by punched card or else rarely interacted with directly. The Altair was also a radically simple computer, without any kind of operating system or even a bootloader. Unless you bought peripherals for it, the Altair was practically a bank of RAM with switches and lights on the front. The Altair’s simplicity makes learning about it a great way to reacquaint yourself with the basic concepts of computing, exactly as they were encountered by the denizens of the old analog world as they first ventured into our digital one.
|
||||
|
||||
### Roberts and Co.
|
||||
|
||||
The Altair was designed and manufactured by a company called Micro Instrumentation and Telemetry Systems (MITS), based in Albuquerque, New Mexico. MITS was run by a man named H. Edward Roberts. The company had started off making telemetry systems for model rocket kits before moving into the calculator market, which in the early 1970s was booming. Integrated circuits were bringing the cost of a calculator down dramatically and suddenly every working American professional had to have one. But the calculator market was ruthlessly competitive and, by the beginning of 1974, MITS was deeply in debt.
|
||||
|
||||
The year 1974 would prove to be an “annus mirabilis” in computing. In January, Hewlett-Packard introduced the HP-65, the world’s first programmable handheld calculator. In April, Intel released the Intel 8080, its second 8-bit microprocessor and the first microprocessor to become widely popular. Then, in July, Radio Electronics magazine advertised a build-it-yourself minicomputer called the Mark-8, which employed the Intel 8008 microprocessor that Intel had released in 1972. The Mark-8 was only the third computer ever built using a microprocessor and it was the first to be appear on the cover of a magazine. The Mark-8’s appearance in Radio Electronics pushed Popular Electronics to look for a minicomputer project of their own to feature.
|
||||
|
||||
Popular Electronics subscribers actually received their copies of the January 1975 issue in the mail in December of 1974. So the announcement of the Altair closed out the “annus mirabilis” that was that year. The Altair’s introduction was so momentous because never before had such a fully capable computer been offered to the public at an affordable price. The PDP-8, one the most popular minicomputers at the time, could only be bought for several thousand dollars. Yet the Intel 8080 chip at the heart of the Altair made it almost as capable as the PDP-8, if not more so; the 8080 supported a wider instruction set and the Altair could be expanded to have up to 64kb of memory, while the stock PDP-8 typically only had 4kb. The Altair was also more powerful than the Mark-8, which, because it was based on the Intel 8008, could only address 16kb of memory. And whereas the Mark-8 had to be built from scratch by customers with only a booklet and printed circuit boards to guide them, the Altair could be purchased fully assembled, though MITS soon became so inundated with orders that the only real way to get an Altair was to order the construction kit.
|
||||
|
||||
For many Popular Electronics readers, the Altair was their first window into the world of digital computing. The article introducing the Altair in the January 1975 issue was written by Roberts and the Altair’s co-designer, William Yates. Roberts and Yates took pains to explain, in terms familiar to the electricians and radio enthusiasts in their audience, the basic concepts underlying digital hardware and computer programming. “A computer,” they wrote, “is basically a piece of variable hardware. By changing the bit pattern stored in the memory, the hardware can be altered from one type of device to another.” Of programming, meanwhile, Roberts and Yates wrote that the basic concepts are “simple enough to master in a relatively short time,” but that becoming “an efficient programmer requires a lot of experience and a large amount of creativity,” which sounds about right to me. The article included a detailed diagram explaining all the constituent circuits of the Intel 8080 CPU, even though readers would receive at least that part fully assembled. It explained the difference between a CPU and a computer’s memory unit, the uses of a stack pointer, and the enormous advantages offered by assembly languages and higher-level languages like FORTRAN and BASIC over manual entry of machine code.
|
||||
|
||||
Popular Electronics had in fact been running a series written by Roberts for several issues before January 1975. The series was billed as a short course in “digital logic.” In the December 1974 issue, Roberts walked readers through building a “very low cost computer terminal,” which was basically an octal keypad that could input values into an 8-bit computer. In the course of describing the keypad, Roberts explained how transistor-to-transistor logic works and also how to construct a flip-flop, a kind of circuit capable of “remembering” digital values. The keypad, Roberts promised, could be used with the Altair computer, to be announced the following month.
|
||||
|
||||
It’s unclear how many Popular Electronics readers actually built the keypad, but it would have been a very useful thing to have. Without a keypad or some other input mechanism, the only way to input values into the Altair was through the switches on the front panel. The front panel had a row of 16 switches that could be used to set an address and a lower row of eight switches that could be used to control the operation of the computer. The eight right-most switches in the row of 16 could also be used to specify a value to be stored in memory. This made sense because the Intel 8080 used 16-bit values to address 8-bit words. The 16 switches on the front panel each represented a bit—the up position represented a one, while the down position represented a zero. Interacting with a computer this way is a revelation (more on that in a minute), because the Altair’s front panel is a true binary interface. It’s as close as you can get to the bare metal.
|
||||
|
||||
As alien as the Altair’s interface is to us today, it was not unusual for its time. The PDP-8, for example, had a similar binary input mechanism on its front panel, though the PDP-8’s switches were nicer and colored in that attractive orange and yellow color scheme that really ought to make a comeback. The PDP-8, however, was often paired with a paper-tape reader or a teletype machine, which made program entry much easier. These I/O devices were expensive, meaning that most Altair users in the early days were stuck with the front panel. As you might imagine, entering long programs via the switches was a chore. Eventually the Altair could be hooked up to a cassette recorder and programs could be loaded that way. Bill Gates and Paul Allen, in what would become Microsoft’s first ever commercial venture, also wrote a version of BASIC for the Altair that MITS licensed and released in the middle of 1975. Users that could afford a teletype could then [load BASIC into the Altair via paper tape][5] and interact with their Altair through text. BASIC, which had become everyone’s favorite introductory programming language in schools, would go on to become the standard interface to the machines produced in the early microcomputer era.
|
||||
|
||||
### z80pack
|
||||
|
||||
Thanks to the efforts of several internet people, in particular a person named Udo Munk, you can run a simulation of the Altair on your computer. The simulation is built on top of some software that emulates the Zilog Z80 CPU, a CPU designed to be software-compatible with the Intel 8080. The Altair simulation allows you to input programs entirely via the front panel switches like early users of the Altair had to do. Though clicking on switches does not offer the same tactile satisfaction as flipping real switches, playing with the Altair simulation is a great way to appreciate how a binary human/computer interface was both horribly inefficient and, at least in my opinion, charmingly straightforward.
|
||||
|
||||
z80pack, Udo Munk’s Z80 emulation package, can be downloaded from the z80pack website. There are instructions in [my last Altair post][4] explaining how to get it set up on Mac OS. If you are able to compile both the FrontPanel library and the `altairsim` executable, you should be able to run `altairsim` and see the following window:
|
||||
|
||||
![Simulated Altair Front Panel][6]
|
||||
|
||||
By default, at least with the version of z80pack that I am using (1.36), the Altair is configured with something called Tarbell boot ROM, which I think is used to load disk images. In practice, what this means is that you can’t write values into the first several words in RAM. If you edit the file `/altairsim/conf/system.conf`, you can instead set up a simple Altair that has 16 pages of RAM and no ROM or bootloader software at all. You can also use this configuration file to increase the size of the window the simulation runs in, which is handy.
|
||||
|
||||
The front panel of the Altair is intimidating, but in reality there isn’t that much going on. The [Altair manual][7] does a good job of explaining the many switches and status lights, as does this [YouTube video][8]. To enter and run a simple program, you only really need to know a few things. The lights labeled D0 through D7 near the top right of the Altair indicate the contents of the currently addressed word. The lights labeled A0 through A15 indicate the current address. The 16 switches below the address lights can be used to set a new address; when the “EXAMINE” switch is pressed upward, the data lights update to show the contents of the newly addressed word. In this way, you can “peek” at all the words in memory. You can also press the “EXAMINE” switch down to the “EXAMINE NEXT” position, which automatically examines the next memory address, which makes peeking at sequential words significantly easier.
|
||||
|
||||
To save a bit pattern to a word, you have to set the bit pattern using the right-most eight switches labeled 0 through 7. You then press the “DEPOSIT” switch upward.
|
||||
|
||||
In the [February 1975 issue][9] of Popular Electronics, Roberts and Yates walked Altair owners through inputting a small sample program to ensure that their Altair was functioning. The program loads two integers from memory, adds them, and saves the sum back into memory. The program consists of only six instructions, but those six instructions involve 14 words of memory altogether, which takes some time to input correctly. The sample program also appears in the Altair manual in table form, which I’ve reproduced here:
|
||||
|
||||
Address Mnemonic Bit Pattern Octal Equivalent 0 LDA 00 111 010 0 7 2 1 (address) 10 000 000 2 0 0 2 (address) 00 000 000 0 0 0 3 MOV B, A 01 000 111 1 0 7 4 LDA 00 111 010 0 7 2 5 (address) 10 000 001 2 0 1 6 (address) 00 000 000 0 0 0 7 ADD B 10 000 000 2 0 0 8 STA 00 110 010 0 6 2 9 (address) 10 000 010 2 0 2 10 (address) 00 000 000 0 0 0 11 JMP 11 000 011 3 0 3 12 (address) 00 000 000 0 0 0 13 (address) 00 000 000 0 0 0
|
||||
|
||||
If you input each word in the above table into the Altair via the switches, you end up with a program that loads the value in word 128, adds it to the value in the word 129, and finally saves it into word 130. The addresses that accompany each instruction taking an address are given with the least-significant bits first, which is why the second byte is always zeroed out (no addresses are higher than 255). Once you’ve input the program and entered some values into words 128 and 129, you can press the “RUN” switch into the down position briefly before pushing it into the “STOP” position. Since the program loops, it repeatedly adds those values and saves the sum thousands of times a second. The sum is always the same though, so if you peek at word 130 after stopping the program, you should find the correct answer.
|
||||
|
||||
I don’t know whether any regular users of the Altair ever had access to an assembler, but z80pack includes one. The z80pack assembler, `z80asm`, is meant for Z80 assembly, so it uses a different set of mnemonics altogether. But since the Z80 was designed to be compatible with software written for the Intel 8080, the opcodes are all the same, even if the mnemonics are different. So just to illustrate what it might have been like to write the same program in assembly, here is a version that can be assembled by `z80asm` and loaded into the Altair:
|
||||
|
||||
```
|
||||
ORG 0000H
|
||||
START: LD A,(80H) ;Load from address 128.
|
||||
LD B,A ;Move loaded value from accumulator (A) to reg B.
|
||||
LD A,(81H) ;Load from address 129.
|
||||
ADD A,B ;Add A and B.
|
||||
LD (82H),A ;Store A at address 130.
|
||||
JP START ;Jump to start.
|
||||
```
|
||||
|
||||
You can turn this into something called an Intel HEX file by invoking the assembler like so (after you have compiled it):
|
||||
|
||||
```
|
||||
$ ./z80asm -fh -oadd.hex add.asm
|
||||
```
|
||||
|
||||
The `-f` flag, here taking `h` as an argument, specifies that a HEX file should be output. You can then load the program into the Altair by passing the HEX file in using the `-x` flag:
|
||||
|
||||
```
|
||||
$ ./altairsim -x add.hex
|
||||
```
|
||||
|
||||
This sets up the first 14 words in memory as if you had input the values manually via the switches. Instead of doing all that again, you can just run the program by using the “RUN” switch as before. Much easier!
|
||||
|
||||
As I said, I don’t think many Altair users wrote software this way. Once Altair BASIC became available, writing BASIC programs was probably the easiest way to program the Altair. z80pack also includes several HEX files containing different versions of Altair BASIC; the one I’ve been able to get working is version 4.0 of 4K BASIC, which you can load into the simulator like so:
|
||||
|
||||
```
|
||||
$ ./altairsim -x basic4k40.hex
|
||||
```
|
||||
|
||||
If you turn the simulated machine on and hit the “RUN” switch, you should see that BASIC has started talking to you in your terminal window. It first prompts you to enter the amount of memory you have available, which should be 4000 bytes. It then asks you a few more questions before presenting you with the “OK” prompt, which Gates and Allen used instead of the standard “READY” to save memory. From there, you can just use BASIC:
|
||||
|
||||
```
|
||||
OK
|
||||
PRINT 3 + 4
|
||||
7
|
||||
```
|
||||
|
||||
Though running BASIC with only 4kb of memory didn’t give you a lot of room, you can see how it would have been a significant step up from using the front panel.
|
||||
|
||||
The Altair, of course, was nowhere near as capable as the home desktops and laptops we have available to us today. Even something like the Macintosh, released less than a decade later, seems like a quantum leap forward over the spartan Altair. But to those first Popular Electronics readers that bought the kit and assembled it, the Altair was a real, fully capable computer that they could own for themselves, all for the low cost of $400 and half the surface space of the credenza. This would have been an amazing thing for people that had thus far only been able to interact with computers by handing [a stack of cards][10] or a roll of tape to another human being entrusted with the actual operation of the computer. Subsequent microcomputers would improve upon what the Altair offered and quickly become much easier to use, but they were all, in some sense, just more complicated Altairs. The Altair—almost Brutalist in its minimalism—was the bare-essentials blueprint for all that would follow.
|
||||
|
||||
If you enjoyed this post, more like it come out every two weeks! Follow [@TwoBitHistory][11] on Twitter or subscribe to the [RSS feed][12] to make sure you know when a new post is out.
|
||||
|
||||
Previously on TwoBitHistory…
|
||||
|
||||
> "I invite you to come along with me on an exciting journey and spend the next ten minutes of your life learning about a piece of software nobody has used in the last decade." <https://t.co/R9zA5ibFMs>
|
||||
>
|
||||
> — TwoBitHistory (@TwoBitHistory) [July 7, 2018][13]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://twobithistory.org/2018/07/22/dawn-of-the-microcomputer.html
|
||||
|
||||
作者:[Two-Bit History][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://twobithistory.org
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1974/Poptronics-1974-12.pdf
|
||||
[2]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1975/Poptronics-1975-01.pdf
|
||||
[3]: https://twobithistory.org/images/jan1975-altair.jpg
|
||||
[4]: https://twobithistory.org/2017/12/02/simulating-the-altair.html
|
||||
[5]: https://www.youtube.com/watch?v=qv5b1Xowxdk
|
||||
[6]: https://www.autometer.de/unix4fun/z80pack/altair.png
|
||||
[7]: http://www.classiccmp.org/dunfield/altair/d/88opman.pdf
|
||||
[8]: https://www.youtube.com/watch?v=suyiMfzmZKs
|
||||
[9]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1975/Poptronics-1975-02.pdf
|
||||
[10]: https://twobithistory.org/2018/06/23/ibm-029-card-punch.html
|
||||
[11]: https://twitter.com/TwoBitHistory
|
||||
[12]: https://twobithistory.org/feed.xml
|
||||
[13]: https://twitter.com/TwoBitHistory/status/1015647820353867776?ref_src=twsrc%5Etfw
|
||||
@@ -1,86 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Two Years With Emacs as a CEO (and now CTO))
|
||||
[#]: via: (https://www.fugue.co/blog/2018-08-09-two-years-with-emacs-as-a-cto.html)
|
||||
[#]: author: (Josh Stella https://www.fugue.co/blog/author/josh-stella)
|
||||
|
||||
Two Years With Emacs as a CEO (and now CTO)
|
||||
======
|
||||
|
||||
Two years ago, I wrote [a blog post][1] that got some notice, which surprised me. It was a piece about going back to Emacs as my primary content creation tool, first as a CEO, and now as a CTO. A brief recap is that I spent most of my career as a programmer and a software architect, and preferred Emacs as my code editor for much of that time. Reconsidering Emacs was an experiment that I was excited about, but wasn't sure how it would work out. On the Internet, the post was met with roughly equal parts disdain and appreciation, but tens of thousands of people read it, so it seems that I touched on something interesting. Some of the more challenging and funny posts on [Reddit][2] and [HackerNews][3] predicted that I'd have hands shaped like claws or that I'd have lost my eyesight because I use white backgrounds. I'm pleased to report that no dire consequences resulted, and in fact my wrists are thanking me for the decision. Some folks worried that using Emacs would be a cognitive drain on a CEO. Having taken Fugue from an idea in my backyard to a powerful product with great and enthusiastic customers, I find Emacs to be a solace from things that are actually difficult. I still use white backgrounds.
|
||||
|
||||
Recently, the post was rediscovered and posted to [HackerNews][4]. I got a number of requests to follow up with a post on how things have gone since, so this is that report. In this post, I will also focus on why Emacs and functional programming are highly relevant now; and how Emacs works with our product, Fugue, that uses functional programming to automate cloud computing. I received a lot of feedback that the level of detail and color commentary were useful, so this post is also fairly verbose and I do spend some effort on explaining my thinking. I've recently moved from the CEO to CTO role here at Fugue, but the content of this post reflects the work I have been doing as CEO. I expect to do more work in code with Emacs going forward, so I have some yak shaving ahead. As always, YMMV, caveat emptor, etc.
|
||||
|
||||
### It worked out better than I suspected it would
|
||||
|
||||
My time is filled with nearly constant communication outside of and within the company. Communication is how things get done in the world, and the enemy of reflection and real contemplation of difficult or complex problems. The rarest commodity for me as a startup CEO is time to focus without distraction. Emacs is particularly good for this, once you've invested the time to learn a handful of commands. Other applications call out to be noticed, but a well configured Emacs gets out of the way both visually and mentally. It doesn't change unless you want it to, and there is no cleaner interface than a blank screen and beautiful typography. In my world of constant interruption, this simplicity allows me to focus solely on what I am thinking rather than the computer. The best programs provide access to the computer without demanding attention.
|
||||
|
||||
A few folks pointed out that the original post was as much a criticism of modern computer interfaces as a recommendation of Emacs. I agree and disagree. Modern interfaces, and particularly their application-centric approach (vs. content-centric), are not user focused or task oriented. Emacs avoids this fallacy, which is part of why I like it so much, but it brings other merits to the table as well. Emacs is a portal into the power of the computer itself, and that is a rabbit hole worth descending. Its idioms are paths to discovering and creating your own, and that for me is the definition of creativity. One of the sad things about modern computing is that it is largely made up of black boxes with shiny interfaces that provide momentary gratification rather than real satisfaction. This makes us into consumers rather than creators/makers of technology. I don't care who you are or what your background is; you can understand your computer, and you can make things with it. It's fun, satisfying, and not as hard as you think to get started!
|
||||
|
||||
We often underappreciate the effects of our environments on our psychology. Emacs imparts a feeling of calm and freedom, rather than of urgency, annoyance, or excitement - the latter of which are enemies of thought and contemplation. I like things that last, get out of the way, and provide insight when I do take the time to pay attention to them. Emacs meets all these criteria for me. I use Emacs every day for content creation, and I'm very pleased with how little I think about it. Emacs does have a learning curve, but it's no steeper than a bicycle, and has a similar payoff in that once you are through it, you don't have to think about it anymore, and it imparts a feeling of freedom that other tools don't. It's an elegant tool, from a more civilized age. I'm happy that we seem to be entering another civilized age in computing, and so Emacs is gaining in popularity.
|
||||
|
||||
### I gave up on using Org-mode for schedules and to-do lists
|
||||
|
||||
I spent some words in the original post on using Org-mode for schedules. I gave up on using Org-mode for to dos and the like, as I have to coordinate many meetings and calls every day with dozens of people, and I cannot ask the rest of the world to adapt to my choice of tools, nor do I have the time to transcribe or automate moving things to Org. We are primarily a Mac shop, use Google Calendar etc., and the native Mac OS/iOS tools do a good job for collaboration. I also use a plain old pen for note-taking during meetings, as I find laptop/keyboard use in meetings to be rude and limiting to my ability to listen and think. Therefore I've largely abandoned the idea that Emacs/org can help me with my schedule or organizing my life. Org-mode is great for lots of other things too though, and is my go-to for writing documents, including this one. In other words, I use it largely in ways the author didn't intend, and it's great at them. I hope someone says the same of our work at Fugue someday.
|
||||
|
||||
### Emacs use has spread at Fugue
|
||||
|
||||
I started the original post with an admonition that you may love Emacs, but will probably hate it. I was therefore a little concerned when the documentation team at Fugue picked it as their standard tool, as I thought perhaps they were influenced by my appreciation for it. A couple years later, I'm pretty sure that it was a good call for them. The leader of the team at the time was a very bright programmer, but the two writers we hired to make the Fugue documentation had less technical backgrounds. I figured that if it was a case of a manager imposing the wrong tool, I'd hear about it and it would resolve itself, as Fugue has an anti-authoritarian culture where people are unafraid to call bullshit on anything or anyone, including me. The original manager left Fugue last year, but the docs team now has a slick, integrated CI/CD toolchain for [docs.fugue.co][5], and they've become enthusiastic Emacs users. There is a learning curve for Emacs, but it's not that tall even if it is steep, and climbing it has real benefits in productivity and general happiness. It was also a reminder that liberal arts focused people are every bit as smart and capable with technology as programmers, and perhaps less prone to technology religions and tribalism.
|
||||
|
||||
### My wrists are thanking me
|
||||
|
||||
I've been spending 12 hours a day or so at a computer since the mid-eighties, and it has taken a toll on my wrists (as well as my back, for which I unreservedly recommend the Tag Capisco chair). The combination of Emacs and an ergonomic keyboard has made the RSI wrist issues go away to the point that I haven't thought about it in over a year. Prior to that, I was having daily pain, particularly in my right wrist, and if you've had this issue, you know it can be very distracting and worrying. A few folks asked about keyboards and mice, so if you're interested I'm currently using a [keyboard.io][6] though I've mainly used a Truly Ergonomic keyboard over the last couple years. I'm a few weeks into using the keyboard.io, and I absolutely love it. The shaped key caps are amazing for knowing where you are without looking, and the thumb keys seem obvious in retrospect, particularly for Emacs, where Control and Meta are your constant companions. No more using the pinkie for highly repetitive tasks!
|
||||
|
||||
The amount of mousing I do is much lower than when using Office and IDEs, and that has helped a lot, but I do still need a mouse. I've been using the rather dated looking but highly functional and ergonomic Clearly Superior trackball, which lives up to its name.
|
||||
|
||||
Specific tools aside, the main point is that a great keyboard combined with mouse avoidance has proved very effective at reducing wear and tear on my body. Emacs is central to this because I don't have to mouse around menus to get things done, and the navigation keys are right under my fingers. I'm pretty convinced now that hand movement away from the standard typing position causes a lot of tendon stress for me. YMMV, I'm not a doctor, etc.
|
||||
|
||||
### I haven't done much to my config...
|
||||
|
||||
Some predicted that I'd spend a lot of time yak shaving my configuration. I wondered if they were right, so I paid attention. Not only have I left my config largely alone, paying attention to the issue has made me realize just how much the other tools I use demand my attention and time. Emacs is easily the lowest maintenance piece of software I use. Mac OS and Windows are constantly demanding that I update them, but that's far less intrusive than Adobe Suite and Office's update intrusions in my world. I do occasionally update my Emacs, but it still works the same way, so it's largely a near zero cost operation for me, and one I can choose to do when I please.
|
||||
|
||||
I'm sorry to disappoint, as a number of folks wanted to know what I've done to keep up with a renewed Emacs community and its output, but I've only added a few things to my config over the last two years. I consider this a success, as Emacs is a tool, not a hobby for me. That said, I'd love to hear about new things if you want to share.
|
||||
|
||||
### ...Except for controlling the cloud
|
||||
|
||||
We have a lot of Emacs fans at Fugue, so we've had a [Ludwig-mode][7] for a while now. Ludwig is our declarative, functional DSL for automating cloud infrastructure and services. Recently, Alex Schoof took some flight and evening hours to build fugue-mode, which acts as an Emacs console over the Fugue CLI. If you aren't familiar with Fugue, we make a cloud automation and governance tool that leverages functional programming to give users a great experience of interacting with cloud APIs. Well, it does a lot more than that, but it does that too. Fugue-mode is cool for a number of reasons. It allows me to have a buffer that is constantly reporting on the status of my cloud infrastructure, and since I often modify that infrastructure, I can quickly see the effects of my coding. Fugue organizes cloud workloads into processes, and Fugue-mode is a lot like top for cloud workloads. It also allows me to perform operations like creating new infrastructure or deleting stuff that isn't needed anymore, without much typing. Fugue-mode is a prototype, but it's pretty handy and I now use it regularly.
|
||||
|
||||
![fugue-mode-edited.gif][8]
|
||||
|
||||
### Modes and monitors
|
||||
|
||||
I have added a few modes and integrations, but not really for work/CEO functions. I've been hacking around in Haskell and Scheme on the weekends for fun, so I've added haskell-mode and geiser. Emacs is great for languages that have a REPL, as you can divide up your screen into different "windows" that are running different modes, including REPLs or shells. Geiser is great for Scheme, and if you've not done so, working through SICP is a joy and possibly a revelation in an age that has lots of examples of cargo cult programming. Install MIT Scheme and geiser and you've got something that feels a bit like the Symbolics environments of lore.
|
||||
|
||||
This brings up another topic I didn't cover in the 2015 post: screen management. I like to use a single portrait mode monitor for writing, and I have this configuration at my home and at my primary office. For programming or mixed use, I like the new ultra-wide monitors that we provide to all Fuguers. For these, I prefer to divide my screen into three columns, with the center having my main editing buffer, the left side having a shell and a fugue-mode buffer divided horizontally, and the right having either a documentation buffer or another editing buffer or two. This is easily done by first using 'Ctl-x 3' twice, then 'Ctl-x =' to make the windows equal in width. This will give you three equal columns that you can further subdivide as you like with 'Ctl-x 2' for horizontal divisions. Here's a screenshot of what this looks like.
|
||||
|
||||
![Emacs Screen Shot][9]
|
||||
|
||||
### This will be my last CEO/Emacs post...
|
||||
|
||||
The first reason for this is that I'm now the CTO of Fugue, but also because there are so many topics I'm looking forward to blogging about and now I should have time to do so. I'm planning on doing some deeper dive posts on topics like functional programming, type safety for infrastructure-as-code, and as we roll out some awesome new Fugue capabilities, some posts on what is achievable on the cloud using Fugue.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.fugue.co/blog/2018-08-09-two-years-with-emacs-as-a-cto.html
|
||||
|
||||
作者:[Josh Stella][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.fugue.co/blog/author/josh-stella
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://blog.fugue.co/2015-11-11-guide-to-emacs.html
|
||||
[2]: https://www.reddit.com/r/emacs/comments/7efpkt/a_ceos_guide_to_emacs/
|
||||
[3]: https://news.ycombinator.com/item?id=10642088
|
||||
[4]: https://news.ycombinator.com/item?id=15753150
|
||||
[5]: https://docs.fugue.co/
|
||||
[6]: https://shop.keyboard.io/
|
||||
[7]: https://github.com/fugue/ludwig-mode
|
||||
[8]: https://www.fugue.co/hubfs/Imported_Blog_Media/fugue-mode-edited-1.gif
|
||||
[9]: https://www.fugue.co/hs-fs/hubfs/Emacs%20Screen%20Shot.png?width=929&name=Emacs%20Screen%20Shot.png
|
||||
54
sources/talk/20190121 Booting Linux faster.md
Normal file
54
sources/talk/20190121 Booting Linux faster.md
Normal file
@@ -0,0 +1,54 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Booting Linux faster)
|
||||
[#]: via: (https://opensource.com/article/19/1/booting-linux-faster)
|
||||
[#]: author: (Stewart Smith https://opensource.com/users/stewart-ibm)
|
||||
|
||||
Booting Linux faster
|
||||
======
|
||||
Doing Linux kernel and firmware development leads to lots of reboots and lots of wasted time.
|
||||

|
||||
Of all the computers I've ever owned or used, the one that booted the quickest was from the 1980s; by the time your hand moved from the power switch to the keyboard, the BASIC interpreter was ready for your commands. Modern computers take anywhere from 15 seconds for a laptop to minutes for a small home server to boot. Why is there such a difference in boot times?
|
||||
|
||||
A microcomputer from the 1980s that booted straight to a BASIC prompt had a very simple CPU that started fetching and executing instructions from a memory address immediately upon getting power. Since these systems had BASIC in ROM, there was no loading time—you got to the BASIC prompt really quickly. More complex systems of that same era, such as the IBM PC or Macintosh, took a significant time to boot (~30 seconds), although this was mostly due to having to read the operating system (OS) off a floppy disk. Only a handful of seconds were spent in firmware before being able to load an OS.
|
||||
|
||||
Modern servers typically spend minutes, rather than seconds, in firmware before getting to the point of booting an OS from disk. This is largely due to modern systems' increased complexity. No longer can a CPU just come up and start executing instructions at full speed; we've become accustomed to CPU frequency scaling, idle states that save a lot of power, and multiple CPU cores. In fact, inside modern CPUs are a surprising number of simpler CPUs that help start the main CPU cores and provide runtime services such as throttling the frequency when it gets too hot. On most CPU architectures, the code running on these cores inside your CPU is provided as opaque binary blobs.
|
||||
|
||||
On OpenPOWER systems, every instruction executed on every core inside the CPU is open source software. On machines with [OpenBMC][1] (such as IBM's AC922 system and Raptor's TALOS II and Blackbird systems), this extends to the code running on the Baseboard Management Controller as well. This means we can get a tremendous amount of insight into what takes so long from the time you plug in a power cable to the time a familiar login prompt is displayed.
|
||||
|
||||
If you're part of a team that works on the Linux kernel, you probably boot a lot of kernels. If you're part of a team that works on firmware, you're probably going to boot a lot of different firmware images, followed by an OS to ensure your firmware still works. If we can reduce the hardware's boot time, these teams can become more productive, and end users may be grateful when they're setting up systems or rebooting to install firmware or OS updates.
|
||||
|
||||
Over the years, many improvements have been made to Linux distributions' boot time. Modern init systems deal well with doing things concurrently and on-demand. On a modern system, once the kernel starts executing, it can take very few seconds to get to a login prompt. This handful of seconds are not the place to optimize boot time; we have to go earlier: before we get to the OS.
|
||||
|
||||
On OpenPOWER systems, the firmware loads an OS by booting a Linux kernel stored in the firmware flash chip that runs a userspace program called [Petitboot][2] to find the disk that holds the OS the user wants to boot and [kexec][3][()][3] to it. This code reuse leverages the efforts that have gone into making Linux boot quicker. Even so, we found places in our kernel config and userspace where we could improve and easily shave seconds off boot time. With these optimizations, booting the Petitboot environment is a single-digit percentage of boot time, so we had to find more improvements elsewhere.
|
||||
|
||||
Before the Petitboot environment starts, there's a prior bit of firmware called [Skiboot][4], and before that there's [Hostboot][5]. Prior to Hostboot is the [Self-Boot Engine][6], a separate core on the die that gets a single CPU core up and executing instructions out of Level 3 cache. These components are where we can make the most headway in reducing boot time, as they take up the overwhelming majority of it. Perhaps some of these components aren't optimized enough or doing as much in parallel as they could be?
|
||||
|
||||
Another avenue of attack is reboot time rather than boot time. On a reboot, do we really need to reinitialize all the hardware?
|
||||
|
||||
Like any modern system, the solutions to improving boot (and reboot) time have been a mixture of doing more in parallel, dealing with legacy, and (arguably) cheating.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/1/booting-linux-faster
|
||||
|
||||
作者:[Stewart Smith][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/stewart-ibm
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://en.wikipedia.org/wiki/OpenBMC
|
||||
[2]: https://github.com/open-power/petitboot
|
||||
[3]: https://en.wikipedia.org/wiki/Kexec
|
||||
[4]: https://github.com/open-power/skiboot
|
||||
[5]: https://github.com/open-power/hostboot
|
||||
[6]: https://github.com/open-power/sbe
|
||||
[7]: https://linux.conf.au/schedule/presentation/105/
|
||||
[8]: https://linux.conf.au/
|
||||
@@ -0,0 +1,494 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Computer Laboratory – Raspberry Pi: Lesson 10 Input01)
|
||||
[#]: via: (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/input01.html)
|
||||
[#]: author: (Alex Chadwick https://www.cl.cam.ac.uk)
|
||||
|
||||
Computer Laboratory – Raspberry Pi: Lesson 10 Input01
|
||||
======
|
||||
|
||||
Welcome to the Input lesson series. In this series, you will learn how to receive inputs to the Raspberry Pi using the keyboard. We will start with just revealing the input, and then move to a more traditional text prompt.
|
||||
|
||||
This first input lesson teaches some theory about drivers and linking, as well as about keyboards and ends up displaying text on the screen.
|
||||
|
||||
### 1 Getting Started
|
||||
|
||||
It is expected that you have completed the OK series, and it would be helpful to have completed the Screen series. Many of the files from that series will be called, without comment. If you do not have these files, or prefer to use a correct implementation, download the template for this lesson from the [Downloads][1] page. If you're using your own implementation, please remove everything after your call to SetGraphicsAddress.
|
||||
|
||||
### 2 USB
|
||||
|
||||
```
|
||||
The USB standard was designed to make simple hardware in exchange for complex software.
|
||||
```
|
||||
|
||||
As you are no doubt aware, the Raspberry Pi model B has two USB ports, commonly used for connecting a mouse and keyboard. This was a very good design decision, USB is a very generic connector, and many different kinds of device use it. It's simple to build new devices for, simple to write device drivers for, and is highly extensible thanks to USB hubs. Could it get any better? Well, no, in fact for an Operating Systems developer this is our worst nightmare. The USB standard is huge. I really mean it this time, it is over 700 pages, before you've even thought about connecting a device.
|
||||
|
||||
I spoke to a number of other hobbyist Operating Systems developers about this and they all say one thing: don't bother. "It will take too long to implement", "You won't be able to write a tutorial on it" and "It will be of little benefit". In many ways they are right, I'm not able to write a tutorial on the USB standard, as it would take weeks. I also can't teach how to write device drivers for all the different devices, so it is useless on its own. However, I can do the next best thing: Get a working USB driver, get a keyboard driver, and then teach how to use these in an Operating System. I set out searching for a free driver that would run in an operating system that doesn't even know what a file is yet, but I couldn't find one. They were all too high level. So, I attempted to write one. Everybody was right, this took weeks to do. However, I'm pleased to say I did get one that works with no external help from the Operating System, and can talk to a mouse and keyboard. It is by no means complete, efficient, or correct, but it does work. It has been written in C and the full source code can be found on the downloads page for those interested.
|
||||
|
||||
So, this tutorial won't be a lesson on the USB standard (at all). Instead we'll look at how to work with other people's code.
|
||||
|
||||
### 3 Linking
|
||||
|
||||
```
|
||||
Linking allows us to make reusable code 'libraries' that anyone can use in their program.
|
||||
```
|
||||
|
||||
Since we're about to incorporate external code into the Operating System, we need to talk about linking. Linking is a process which is applied to programs or Operating System to link in functions. What this means is that when a program is made, we don't necessarily code every function (almost certainly not in fact). Linking is what we do to make our program link to functions in other people's code. This has actually been going on all along in our Operating Systems, as the linker links together all of the different files, each of which is compiled separately.
|
||||
|
||||
```
|
||||
Programs often just call libraries, which call other libraries and so on until eventually they call an Operating System library which we would write.
|
||||
```
|
||||
|
||||
There are two types of linking: static and dynamic. Static linking is like what goes on when we make our Operating Systems. The linker finds all the addresses of the functions, and writes them into the code, before the program is finished. Dynamic linking is linking that occurs after the program is 'complete'. When it is loaded, the dynamic linker goes through the program and links any functions which are not in the program to libraries in the Operating System. This is one of the jobs our Operating System should eventually be capable of, but for now everything will be statically linked.
|
||||
|
||||
The USB driver I have written is suitable for static linking. This means I give you the compiled code for each of my files, and then the linker finds functions in your code which are not defined in your code, and links them to functions in my code. On the [Downloads][1] page for this lesson is a makefile and my USB driver, which you will need to continue. Download them and replace the makefile in your code with this one, and also put the driver in the same folder as that makefile.
|
||||
|
||||
### 4 Keyboards
|
||||
|
||||
In order to get input into our Operating System, we need to understand at some level how keyboards actually work. Keyboards have two types of keys: Normal and Modifier keys. The normal keys are the letters, numbers, function keys, etc. They constitute almost every key on the keyboard. The modifiers are up to 8 special keys. These are left shift, right shift, left control, right control, left alt, right alt, left GUI and right GUI. The keyboard can detect any combination of the modifier keys being held, as well as up to 6 normal keys. Every time a key changes (i.e. is pushed or released), it reports this to the computer. Typically, keyboards also have three LEDs for Caps Lock, Num Lock and Scroll Lock, which are controlled by the computer, not the keyboard itself. Keyboards may have many more lights such as power, mute, etc.
|
||||
|
||||
In order to help standardise USB keyboards, a table of values was produced, such that every keyboard key ever is given a unique number, as well as every conceivable LED. The table below lists the first 126 of values.
|
||||
|
||||
Table 4.1 USB Keyboard Keys
|
||||
| Number | Description | Number | Description | Number | Description | Number | Description | |
|
||||
| ------ | ---------------- | ------- | ---------------------- | -------- | -------------- | --------------- | -------------------- | |
|
||||
| 4 | a and A | 5 | b and B | 6 | c and C | 7 | d and D | |
|
||||
| 8 | e and E | 9 | f and F | 10 | g and G | 11 | h and H | |
|
||||
| 12 | i and I | 13 | j and J | 14 | k and K | 15 | l and L | |
|
||||
| 16 | m and M | 17 | n and N | 18 | o and O | 19 | p and P | |
|
||||
| 20 | q and Q | 21 | r and R | 22 | s and S | 23 | t and T | |
|
||||
| 24 | u and U | 25 | v and V | 26 | w and W | 27 | x and X | |
|
||||
| 28 | y and Y | 29 | z and Z | 30 | 1 and ! | 31 | 2 and @ | |
|
||||
| 32 | 3 and # | 33 | 4 and $ | 34 | 5 and % | 35 | 6 and ^ | |
|
||||
| 36 | 7 and & | 37 | 8 and * | 38 | 9 and ( | 39 | 0 and ) | |
|
||||
| 40 | Return (Enter) | 41 | Escape | 42 | Delete (Backspace) | 43 | Tab | |
|
||||
| 44 | Spacebar | 45 | - and _ | 46 | = and + | 47 | [ and { | |
|
||||
| 48 | ] and } | 49 | \ and | | 50 | # and ~ | 51 | ; and : |
|
||||
| 52 | ' and " | 53 | ` and ~ | 54 | , and < | 55 | . and > | |
|
||||
| 56 | / and ? | 57 | Caps Lock | 58 | F1 | 59 | F2 | |
|
||||
| 60 | F3 | 61 | F4 | 62 | F5 | 63 | F6 | |
|
||||
| 64 | F7 | 65 | F8 | 66 | F9 | 67 | F10 | |
|
||||
| 68 | F11 | 69 | F12 | 70 | Print Screen | 71 | Scroll Lock | |
|
||||
| 72 | Pause | 73 | Insert | 74 | Home | 75 | Page Up | |
|
||||
| 76 | Delete forward | 77 | End | 78 | Page Down | 79 | Right Arrow | |
|
||||
| 80 | Left Arrow | 81 | Down Arrow | 82 | Up Arrow | 83 | Num Lock | |
|
||||
| 84 | Keypad / | 85 | Keypad * | 86 | Keypad - | 87 | Keypad + | |
|
||||
| 88 | Keypad Enter | 89 | Keypad 1 and End | 90 | Keypad 2 and Down Arrow | 91 | Keypad 3 and Page Down | |
|
||||
| 92 | Keypad 4 and Left Arrow | 93 | Keypad 5 | 94 | Keypad 6 and Right Arrow | 95 | Keypad 7 and Home | |
|
||||
| 96 | Keypad 8 and Up Arrow | 97 | Keypad 9 and Page Up | 98 | Keypad 0 and Insert | 99 | Keypad . and Delete | |
|
||||
| 100 | \ and | | 101 | Application | 102 | Power | 103 | Keypad = |
|
||||
| 104 | F13 | 105 | F14 | 106 | F15 | 107 | F16 | |
|
||||
| 108 | F17 | 109 | F18 | 110 | F19 | 111 | F20 | |
|
||||
| 112 | F21 | 113 | F22 | 114 | F23 | 115 | F24 | |
|
||||
| 116 | Execute | 117 | Help | 118 | Menu | 119 | Select | |
|
||||
| 120 | Stop | 121 | Again | 122 | Undo | 123 | Cut | |
|
||||
| 124 | Copy | 125 | Paste | 126 | Find | 127 | Mute | |
|
||||
| 128 | Volume Up | 129 | Volume Down | | | | | |
|
||||
|
||||
The full list can be found in section 10, page 53 of [HID Usage Tables 1.12][2].
|
||||
|
||||
### 5 The Nut Behind the Wheel
|
||||
|
||||
```
|
||||
These summaries and the code they describe form an API - Application Product Interface.
|
||||
```
|
||||
|
||||
Normally, when you work with someone else's code, they provide a summary of their methods, what they do and roughly how they work, as well as how they can go wrong. Here is a table of the relevant instructions required to use my USB driver.
|
||||
|
||||
Table 5.1 Keyboard related functions in CSUD
|
||||
| Function | Arguments | Returns | Description |
|
||||
| ----------------------- | ----------------------- | ----------------------- | ----------------------- |
|
||||
| UsbInitialise | None | r0 is result code | This method is the all-in-one method that loads the USB driver, enumerates all devices and attempts to communicate with them. This method generally takes about a second to execute, though with a few USB hubs plugged in this can be significantly longer. After this method is completed methods in the keyboard driver become available, regardless of whether or not a keyboard is indeed inserted. Result code explained below. |
|
||||
| UsbCheckForChange | None | None | Essentially provides the same effect as UsbInitialise, but does not provide the same one time initialisation. This method checks every port on every connected hub recursively, and adds new devices if they have been added. This should be very quick if there are no changes, but can take up to a few seconds if a hub with many devices is attached. |
|
||||
| KeyboardCount | None | r0 is count | Returns the number of keyboards currently connected and detected. UsbCheckForChange may update this. Up to 4 keyboards are supported by default. Up to this many keyboards may be accessed through this driver. |
|
||||
| KeyboardGetAddress | r0 is index | r0 is address | Retrieves the address of a given keyboard. All other functions take a keyboard address in order to know which keyboard to access. Thus, to communicate with a keyboard, first check the count, then retrieve the address, then use other methods. Note, the order of keyboards that this method returns may change after calls to UsbCheckForChange. |
|
||||
| KeyboardPoll | r0 is address | r0 is result code | Reads in the current key state from the keyboard. This operates via polling the device directly, contrary to the best practice. This means that if this method is not called frequently enough, a key press could be missed. All reading methods simply return the value as of the last poll. |
|
||||
| KeyboardGetModifiers | r0 is address | r0 is modifier state | Retrieves the status of the modifier keys as of the last poll. These are the shift, alt control and GUI keys on both sides. This is returned as a bit field, such that a 1 in the bit 0 means left control is held, bit 1 means left shift, bit 2 means left alt, bit 3 means left GUI and bits 4 to 7 mean the right versions of those previous. If there is a problem r0 contains 0. |
|
||||
| KeyboardGetKeyDownCount | r0 is address | r0 is count | Retrieves the number of keys currently held down on the keyboard. This excludes modifier keys. Normally, this cannot go above 6. If there is an error this method returns 0. |
|
||||
| KeyboardGetKeyDown | r0 is address, r1 is key number | r0 is scan code | Retrieves the scan code (see Table 4.1) of a particular held down key. Normally, to work out which keys are down, call KeyboardGetKeyDownCount and then call KeyboardGetKeyDown up to that many times with increasing values of r1 to determine which keys are down. Returns 0 if there is a problem. It is safe (but not recommended) to call this method without calling KeyboardGetKeyDownCount and interpret 0s as keys not held. Note, the order or scan codes can change randomly (some keyboards sort numerically, some sort temporally, no guarantees are made). |
|
||||
| KeyboardGetKeyIsDown | r0 is address, r1 is scan code | r0 is status | Alternative to KeyboardGetKeyDown, checks if a particular scan code is among the held down keys. Returns 0 if not, or a non-zero value if so. Faster when detecting particular scan codes (e.g. looking for ctrl+c). On error, returns 0. |
|
||||
| KeyboardGetLedSupport | r0 is address | r0 is LEDs | Checks which LEDs a particular keyboard supports. Bit 0 being 1 represents Number Lock, bit 1 represents Caps Lock, bit 2 represents Scroll Lock, bit 3 represents Compose, bit 4 represents Kana, bit 5 represents Power, bit 6 represents Mute and bit 7 represents Compose. As per the USB standard, none of these LEDs update automatically (e.g. Caps Lock must be set manually when the Caps Lock scan code is detected). |
|
||||
| KeyboardSetLeds | r0 is address, r1 is LEDs | r0 is result code | Attempts to turn on/off the specified LEDs on the keyboard. See below for result code values. See KeyboardGetLedSupport for LEDs' values. |
|
||||
|
||||
```
|
||||
Result codes are an easy way to handle errors, but often more elegant solutions exist in higher level code.
|
||||
```
|
||||
|
||||
Several methods return 'result codes'. These are commonplace in C code, and are just numbers which represent what happened in a method call. By convention, 0 always indicates success. The following result codes are used by this driver.
|
||||
|
||||
Table 5.2 - CSUD Result Codes
|
||||
| Code | Description |
|
||||
| ---- | ----------------------------------------------------------------------- |
|
||||
| 0 | Method completed successfully. |
|
||||
| -2 | Argument: A method was called with an invalid argument. |
|
||||
| -4 | Device: The device did not respond correctly to the request. |
|
||||
| -5 | Incompatible: The driver is not compatible with this request or device. |
|
||||
| -6 | Compiler: The driver was compiled incorrectly, and is broken. |
|
||||
| -7 | Memory: The driver ran out of memory. |
|
||||
| -8 | Timeout: The device did not respond in the expected time. |
|
||||
| -9 | Disconnect: The device requested has disconnected, and cannot be used. |
|
||||
|
||||
The general usage of the driver is as follows:
|
||||
|
||||
1. Call UsbInitialise
|
||||
2. Call UsbCheckForChange
|
||||
3. Call KeyboardCount
|
||||
4. If this is 0, go to 2.
|
||||
5. For each keyboard you support:
|
||||
1. Call KeyboardGetAddress
|
||||
2. Call KeybordGetKeyDownCount
|
||||
3. For each key down:
|
||||
1. Check whether or not it has just been pushed
|
||||
2. Store that the key is down
|
||||
4. For each key stored:
|
||||
1. Check whether or not key is released
|
||||
2. Remove key if released
|
||||
6. Perform actions based on keys pushed/released
|
||||
7. Go to 2.
|
||||
|
||||
|
||||
|
||||
Ultimately, you may do whatever you wish to with the keyboard, and these methods should allow you to access all of its functionality. Over the next 2 lessons, we shall look at completing the input side of a text terminal, similarly to most command line computers, and interpreting the commands. In order to do this, we're going to need to have keyboard inputs in a more useful form. You may notice that my driver is (deliberately) unhelpful, because it doesn't have methods to deduce whether or not a key has just been pushed down or released, it only has methods about what is currently held down. This means we'll need to write such methods ourselves.
|
||||
|
||||
### 6 Updates Available
|
||||
|
||||
Repeatedly checking for updates is called 'polling'. This is in contrast to interrupt driven IO, where the device sends a signal when data is ready.
|
||||
|
||||
First of all, let's implement a method KeyboardUpdate which detects the first keyboard and uses its poll method to get the current input, as well as saving the last inputs for comparison. We can then use this data with other methods to translate scan codes to keys. The method should do precisely the following:
|
||||
|
||||
1. Retrieve a stored keyboard address (initially 0).
|
||||
2. If this is not 0, go to 9.
|
||||
3. Call UsbCheckForChange to detect new keyboards.
|
||||
4. Call KeyboardCount to detect how many keyboards are present.
|
||||
5. If this is 0 store the address as 0 and return; we can't do anything with no keyboard.
|
||||
6. Call KeyboardGetAddress with parameter 0 to get the first keyboard's address.
|
||||
7. Store this address.
|
||||
8. If this is 0, return; there is some problem.
|
||||
9. Call KeyboardGetKeyDown 6 times to get each key currently down and store them
|
||||
10. Call KeyboardPoll
|
||||
11. If the result is non-zero go to 3. There is some problem (such as disconnected keyboard).
|
||||
|
||||
|
||||
|
||||
To store the values mentioned above, we will need the following values in the .data section.
|
||||
|
||||
```
|
||||
.section .data
|
||||
.align 2
|
||||
KeyboardAddress:
|
||||
.int 0
|
||||
KeyboardOldDown:
|
||||
.rept 6
|
||||
.hword 0
|
||||
.endr
|
||||
```
|
||||
|
||||
```
|
||||
.hword num inserts the half word constant num into the file directly.
|
||||
```
|
||||
|
||||
```
|
||||
.rept num [commands] .endr copies the commands commands to the output num times.
|
||||
```
|
||||
|
||||
Try to implement the method yourself. My implementation for this is as follows:
|
||||
|
||||
1.
|
||||
```
|
||||
.section .text
|
||||
.globl KeyboardUpdate
|
||||
KeyboardUpdate:
|
||||
push {r4,r5,lr}
|
||||
|
||||
kbd .req r4
|
||||
ldr r0,=KeyboardAddress
|
||||
ldr kbd,[r0]
|
||||
```
|
||||
We load in the keyboard address.
|
||||
2.
|
||||
```
|
||||
teq kbd,#0
|
||||
bne haveKeyboard$
|
||||
```
|
||||
If the address is non-zero, we have a keyboard. Calling UsbCheckForChanges is slow, and so if everything works we avoid it.
|
||||
3.
|
||||
```
|
||||
getKeyboard$:
|
||||
bl UsbCheckForChange
|
||||
```
|
||||
If we don't have a keyboard, we have to check for new devices.
|
||||
4.
|
||||
```
|
||||
bl KeyboardCount
|
||||
```
|
||||
Now we see if a new keyboard has been added.
|
||||
5.
|
||||
```
|
||||
teq r0,#0
|
||||
ldreq r1,=KeyboardAddress
|
||||
streq r0,[r1]
|
||||
beq return$
|
||||
```
|
||||
There are no keyboards, so we have no keyboard address.
|
||||
6.
|
||||
```
|
||||
mov r0,#0
|
||||
bl KeyboardGetAddress
|
||||
```
|
||||
Let's just get the address of the first keyboard. You may want to allow more.
|
||||
7.
|
||||
```
|
||||
ldr r1,=KeyboardAddress
|
||||
str r0,[r1]
|
||||
```
|
||||
Store the keyboard's address.
|
||||
8.
|
||||
```
|
||||
teq r0,#0
|
||||
beq return$
|
||||
mov kbd,r0
|
||||
```
|
||||
If we have no address, there is nothing more to do.
|
||||
9.
|
||||
```
|
||||
saveKeys$:
|
||||
mov r0,kbd
|
||||
mov r1,r5
|
||||
bl KeyboardGetKeyDown
|
||||
|
||||
ldr r1,=KeyboardOldDown
|
||||
add r1,r5,lsl #1
|
||||
strh r0,[r1]
|
||||
add r5,#1
|
||||
cmp r5,#6
|
||||
blt saveKeys$
|
||||
```
|
||||
Loop through all the keys, storing them in KeyboardOldDown. If we ask for too many, this returns 0 which is fine.
|
||||
|
||||
10.
|
||||
```
|
||||
mov r0,kbd
|
||||
bl KeyboardPoll
|
||||
```
|
||||
Now we get the new keys.
|
||||
|
||||
11.
|
||||
```
|
||||
teq r0,#0
|
||||
bne getKeyboard$
|
||||
|
||||
return$:
|
||||
pop {r4,r5,pc}
|
||||
.unreq kbd
|
||||
```
|
||||
Finally we check if KeyboardPoll worked. If not, we probably disconnected.
|
||||
|
||||
|
||||
With our new KeyboardUpdate method, checking for inputs becomes as simple as calling this method at regular intervals, and it will even check for disconnections etc. This is a useful method to have, as our actual key processing may differ based on the situation, and so being able to get the current input in its raw form with one method call is generally applicable. The next method we ideally want is KeyboardGetChar, a method that simply returns the next key pressed as an ASCII character, or returns 0 if no key has just been pressed. This could be extended to support typing a key multiple times if it is held for a certain duration, and to support the 'lock' keys as well as modifiers.
|
||||
|
||||
To make this method it is useful if we have a method KeyWasDown, which simply returns 0 if a given scan code is not in the KeyboardOldDown values, and returns a non-zero value otherwise. Have a go at implementing this yourself. As always, a solution can be found on the downloads page.
|
||||
|
||||
### 7 Look Up Tables
|
||||
|
||||
```
|
||||
In many areas of programming, the larger the program, the faster it is. Look up tables are large, but are very fast. Some problems can be solved by a mixture of look up tables and normal functions.
|
||||
```
|
||||
|
||||
The KeyboardGetChar method could be quite complex if we write it poorly. There are 100s of scan codes, each with different effects depending on the presence or absence of the shift key or other modifiers. Not all of the keys can be translated to a character. For some characters, multiple keys can produce the same character. A useful trick in situations with such vast arrays of possibilities is look up tables. A look up table, much like in the physical sense, is a table of values and their results. For some limited functions, the simplest way to deduce the answer is just to precompute every answer, and just return the correct one by retrieving it. In this case, we could build up a sequence of values in memory such that the nth value into the sequence is the ASCII character code for the scan code n. This means our method would simply have to detect if a key was pressed, and then retrieve its value from the table. Further, we could have a separate table for the values when shift is held, so that the shift key simply changes which table we're working with.
|
||||
|
||||
After the .section .data command, copy the following tables:
|
||||
|
||||
```
|
||||
.align 3
|
||||
KeysNormal:
|
||||
.byte 0x0, 0x0, 0x0, 0x0, 'a', 'b', 'c', 'd'
|
||||
.byte 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'
|
||||
.byte 'm', 'n', 'o', 'p', 'q', 'r', 's', 't'
|
||||
.byte 'u', 'v', 'w', 'x', 'y', 'z', '1', '2'
|
||||
.byte '3', '4', '5', '6', '7', '8', '9', '0'
|
||||
.byte '\n', 0x0, '\b', '\t', ' ', '-', '=', '['
|
||||
.byte ']', '\\\', '#', ';', '\'', '`', ',', '.'
|
||||
.byte '/', 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
|
||||
.byte 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
|
||||
.byte 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
|
||||
.byte 0x0, 0x0, 0x0, 0x0, '/', '*', '-', '+'
|
||||
.byte '\n', '1', '2', '3', '4', '5', '6', '7'
|
||||
.byte '8', '9', '0', '.', '\\\', 0x0, 0x0, '='
|
||||
|
||||
.align 3
|
||||
KeysShift:
|
||||
.byte 0x0, 0x0, 0x0, 0x0, 'A', 'B', 'C', 'D'
|
||||
.byte 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'
|
||||
.byte 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T'
|
||||
.byte 'U', 'V', 'W', 'X', 'Y', 'Z', '!', '"'
|
||||
.byte '£', '$', '%', '^', '&', '*', '(', ')'
|
||||
.byte '\n', 0x0, '\b', '\t', ' ', '_', '+', '{'
|
||||
.byte '}', '|', '~', ':', '@', '¬', '<', '>'
|
||||
.byte '?', 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
|
||||
.byte 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
|
||||
.byte 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
|
||||
.byte 0x0, 0x0, 0x0, 0x0, '/', '*', '-', '+'
|
||||
.byte '\n', '1', '2', '3', '4', '5', '6', '7'
|
||||
.byte '8', '9', '0', '.', '|', 0x0, 0x0, '='
|
||||
```
|
||||
|
||||
```
|
||||
.byte num inserts the byte constant num into the file directly.
|
||||
```
|
||||
|
||||
```
|
||||
Most assemblers and compilers recognise escape sequences; character sequences such as \t which insert special characters instead.
|
||||
```
|
||||
|
||||
These tables map directly the first 104 scan codes onto the ASCII characters as a table of bytes. We also have a separate table describing the effects of the shift key on those scan codes. I've used the ASCII null character (0) for all keys without direct mappings in ASCII (such as the function keys). Backspace is mapped to the ASCII backspace character (8 denoted \b), enter is mapped to the ASCII new line character (10 denoted \n) and tab is mapped to the ASCII horizontal tab character (9 denoted \t).
|
||||
|
||||
The KeyboardGetChar method will need to do the following:
|
||||
|
||||
1. Check if KeyboardAddress is 0. If so, return 0.
|
||||
2. Call KeyboardGetKeyDown up to 6 times. Each time:
|
||||
1. If key is 0, exit loop.
|
||||
2. Call KeyWasDown. If it was, go to the next key.
|
||||
3. If the scan code is more than 103, go to the next key.
|
||||
4. Call KeyboardGetModifiers
|
||||
5. If shift is held, load the address of KeysShift. Otherwise load KeysNormal.
|
||||
6. Read the ASCII value from the table.
|
||||
7. If it is 0, go to the next key otherwise return this ASCII code and exit.
|
||||
3. Return 0.
|
||||
|
||||
|
||||
|
||||
Try to implement this yourself. My implementation is presented below:
|
||||
|
||||
1.
|
||||
```
|
||||
.globl KeyboardGetChar
|
||||
KeyboardGetChar:
|
||||
ldr r0,=KeyboardAddress
|
||||
ldr r1,[r0]
|
||||
teq r1,#0
|
||||
moveq r0,#0
|
||||
moveq pc,lr
|
||||
```
|
||||
Simple check to see if we have a keyboard.
|
||||
|
||||
2.
|
||||
```
|
||||
push {r4,r5,r6,lr}
|
||||
kbd .req r4
|
||||
key .req r6
|
||||
mov r4,r1
|
||||
mov r5,#0
|
||||
keyLoop$:
|
||||
mov r0,kbd
|
||||
mov r1,r5
|
||||
bl KeyboardGetKeyDown
|
||||
```
|
||||
r5 will hold the index of the key, r4 holds the keyboard address.
|
||||
|
||||
1.
|
||||
```
|
||||
teq r0,#0
|
||||
beq keyLoopBreak$
|
||||
```
|
||||
If a scan code is 0, it either means there is an error, or there are no more keys.
|
||||
|
||||
2.
|
||||
```
|
||||
mov key,r0
|
||||
bl KeyWasDown
|
||||
teq r0,#0
|
||||
bne keyLoopContinue$
|
||||
```
|
||||
If a key was already down it is uninteresting, we only want ot know about key presses.
|
||||
|
||||
3.
|
||||
```
|
||||
cmp key,#104
|
||||
bge keyLoopContinue$
|
||||
```
|
||||
If a key has a scan code higher than 104, it will be outside our table, and so is not relevant.
|
||||
|
||||
4.
|
||||
```
|
||||
mov r0,kbd
|
||||
bl KeyboardGetModifiers
|
||||
```
|
||||
We need to know about the modifier keys in order to deduce the character.
|
||||
|
||||
5.
|
||||
```
|
||||
tst r0,#0b00100010
|
||||
ldreq r0,=KeysNormal
|
||||
ldrne r0,=KeysShift
|
||||
```
|
||||
We detect both a left and right shift key as changing the characters to their shift variants. Remember, a tst instruction computes the logical AND and then compares it to zero, so it will be equal to 0 if and only if both of the shift bits are zero.
|
||||
|
||||
6.
|
||||
```
|
||||
ldrb r0,[r0,key]
|
||||
```
|
||||
Now we can load in the key from the look up table.
|
||||
|
||||
7.
|
||||
```
|
||||
teq r0,#0
|
||||
bne keyboardGetCharReturn$
|
||||
keyLoopContinue$:
|
||||
add r5,#1
|
||||
cmp r5,#6
|
||||
blt keyLoop$
|
||||
```
|
||||
If the look up code contains a zero, we must continue. To continue, we increment the index, and check if we've reached 6.
|
||||
|
||||
3.
|
||||
```
|
||||
keyLoopBreak$:
|
||||
mov r0,#0
|
||||
keyboardGetCharReturn$:
|
||||
pop {r4,r5,r6,pc}
|
||||
.unreq kbd
|
||||
.unreq key
|
||||
```
|
||||
We return our key here, if we reach keyLoopBreak$, then we know there is no key held, so return 0.
|
||||
|
||||
|
||||
|
||||
|
||||
### 8 Notepad OS
|
||||
|
||||
Now we have our KeyboardGetChar method, we can make an operating system that just types what the user writes to the screen. For simplicity we'll ignore all the unusual keys. In 'main.s' delete all code after bl SetGraphicsAddress. Call UsbInitialise, set r4 and r5 to 0, then loop forever over the following commands:
|
||||
|
||||
1. Call KeyboardUpdate
|
||||
2. Call KeyboardGetChar
|
||||
3. If it is 0, got to 1
|
||||
4. Copy r4 and r5 to r1 and r2 then call DrawCharacter
|
||||
5. Add r0 to r4
|
||||
6. If r4 is 1024, add r1 to r5 and set r4 to 0
|
||||
7. If r5 is 768 set r5 to 0
|
||||
8. Go to 1
|
||||
|
||||
|
||||
|
||||
Now compile this and test it on the Pi. You should almost immediately be able to start typing text to the screen when the Pi starts. If not, please see our troubleshooting page.
|
||||
|
||||
When it works, congratulations, you've achieved an interface with the computer. You should now begin to realise that you've almost got a primitive operating system together. You can now interface with the computer, issuing it commands, and receive feedback on screen. In the next tutorial, [Input02][3] we will look at producing a full text terminal, in which the user types commands, and the computer executes them.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/input01.html
|
||||
|
||||
作者:[Alex Chadwick][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.cl.cam.ac.uk
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/downloads.html
|
||||
[2]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/downloads/hut1_12v2.pdf
|
||||
[3]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/input02.html
|
||||
@@ -0,0 +1,911 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Computer Laboratory – Raspberry Pi: Lesson 11 Input02)
|
||||
[#]: via: (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/input02.html)
|
||||
[#]: author: (Alex Chadwick https://www.cl.cam.ac.uk)
|
||||
|
||||
Computer Laboratory – Raspberry Pi: Lesson 11 Input02
|
||||
======
|
||||
|
||||
The Input02 lesson builds on Input01, by building a simple command line interface where the user can type commands and the computer interprets and displays them. It is assumed you have the code for the [Lesson 11: Input01][1] operating system as a basis.
|
||||
|
||||
### 1 Terminal 1
|
||||
|
||||
```
|
||||
In the early days of computing, there would usually be one large computer in a building, and many 'terminals' which sent commands to it. The computer would take it in turns to execute different incoming commands.
|
||||
```
|
||||
|
||||
Almost every operating system starts life out as a text terminal. This is typically a black screen with white writing, where you type commands for the computer to execute on the keyboard, and it explains how you've mistyped them, or very occasionally, does what you want. This approach has two main advantages: it provides a simple, robust control mechanism for the computer using only a keyboard and monitor, and it is done by almost every operating system, so is widely understood by system administrators.
|
||||
|
||||
Let's analyse what we want to do precisely:
|
||||
|
||||
1. Computer turns on, displays some sort of welcome message
|
||||
2. Computer indicates its ready for input
|
||||
3. User types a command, with parameters, on the keyboard
|
||||
4. User presses return or enter to commit the command
|
||||
5. Computer interprets command and performs actions if command is acceptable
|
||||
6. Computer displays messages to indicate if command was successful, and also what happened
|
||||
7. Loop back to 2
|
||||
|
||||
|
||||
|
||||
One defining feature of such terminals is that they are unified for both input and output. The same screen is used to enter inputs as is used to print outputs. This means it is useful to build an abstraction of a character based display. In a character based display, the smallest unit is a character, not a pixel. The screen is divided into a fixed number of characters which have varying colours. We can build this on top of our existing screen code, by storing the characters and their colours, and then using the DrawCharacter method to push them to the screen. Once we have a character based display, drawing text becomes a matter of drawing a line of characters.
|
||||
|
||||
In a new file called terminal.s copy the following code:
|
||||
```
|
||||
.section .data
|
||||
.align 4
|
||||
terminalStart:
|
||||
.int terminalBuffer
|
||||
terminalStop:
|
||||
.int terminalBuffer
|
||||
terminalView:
|
||||
.int terminalBuffer
|
||||
terminalColour:
|
||||
.byte 0xf
|
||||
.align 8
|
||||
terminalBuffer:
|
||||
.rept 128*128
|
||||
.byte 0x7f
|
||||
.byte 0x0
|
||||
.endr
|
||||
terminalScreen:
|
||||
.rept 1024/8 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 768/16
|
||||
.byte 0x7f
|
||||
.byte 0x0
|
||||
.endr
|
||||
```
|
||||
This sets up the data we need for the text terminal. We have two main storages: terminalBuffer and terminalScreen. terminalBuffer is storage for all of the text we have displayed. It stores up to 128 lines of text (each containing 128 characters). Each character consists of an ASCII character code and a colour, all of which are initially set to 0x7f (ASCII delete) and 0 (black on a black background). terminalScreen stores the characters that are currently displayed on the screen. It is 128 by 48 characters, similarly initialised. You may think that we only need this terminalScreen, not the terminalBuffer, but storing the buffer has 2 main advantages:
|
||||
|
||||
1. We can easily see which characters are different, so we only have to draw those.
|
||||
2. We can 'scroll' back through the terminal's history because it is stored (to a limit).
|
||||
|
||||
|
||||
|
||||
You should always try to design systems that do the minimum amount of work, as they run much faster for things which don't often change.
|
||||
|
||||
The differing trick is really common on low power Operating Systems. Drawing the screen is a slow operation, and so we only want to draw thing that we absolutely have to. In this system, we can freely alter the terminalBuffer, and then call a method which copies the bits that change to the screen. This means we don't have to draw each character as we go along, which may save time in the long run on very long sections of text that span many lines.
|
||||
|
||||
The other values in the .data section are as follows:
|
||||
|
||||
* terminalStart
|
||||
The first character which has been written in terminalBuffer.
|
||||
* terminalStop
|
||||
The last character which has been written in terminalBuffer.
|
||||
* terminalView
|
||||
The first character on the screen at present. We can use this to scroll the screen.
|
||||
* temrinalColour
|
||||
The colour to draw new characters with.
|
||||
|
||||
|
||||
|
||||
```
|
||||
Circular buffers are an example of an **data structure**. These are just ideas we have for organising data, that we sometimes implement in software.
|
||||
```
|
||||
|
||||
![Diagram showing hellow world being inserted into a circular buffer of size 5.][2]
|
||||
The reason why terminalStart needs to be stored is because termainlBuffer should be a circular buffer. This means that when the buffer is completely full, the end 'wraps' round to the start, and so the character after the very last one is the first one. Thus, we need to advance terminalStart so we know that we've done this. When wokring with the buffer this can easily be implemented by checking if the index goes beyond the end of the buffer, and setting it back to the beginning if it does. Circular buffers are a common and clever way of storing a lot of data, where only the most recent data is important. It allows us to keep writing indefinitely, while always being sure there is a certain amount of recent data available. They're often used in signal processing or compression algorithms. In this case, it allows us to store a 128 line history of the terminal, without any penalties for writing over 128 lines. If we didn't have this, we would have to copy 127 lines back a line very time we went beyond the 128th line, wasting valuable time.
|
||||
|
||||
I've mentioned the terminalColour here a few times. You can implement this however you, wish, however there is something of a standard on text terminals to have only 16 colours for foreground, and 16 colours for background (meaning there are 162 = 256 combinations). The colours on a CGA terminal are defined as follows:
|
||||
|
||||
Table 1.1 - CGA Colour Codes
|
||||
| Number | Colour (R, G, B) |
|
||||
| ------ | ------------------------|
|
||||
| 0 | Black (0, 0, 0) |
|
||||
| 1 | Blue (0, 0, ⅔) |
|
||||
| 2 | Green (0, ⅔, 0) |
|
||||
| 3 | Cyan (0, ⅔, ⅔) |
|
||||
| 4 | Red (⅔, 0, 0) |
|
||||
| 5 | Magenta (⅔, 0, ⅔) |
|
||||
| 6 | Brown (⅔, ⅓, 0) |
|
||||
| 7 | Light Grey (⅔, ⅔, ⅔) |
|
||||
| 8 | Grey (⅓, ⅓, ⅓) |
|
||||
| 9 | Light Blue (⅓, ⅓, 1) |
|
||||
| 10 | Light Green (⅓, 1, ⅓) |
|
||||
| 11 | Light Cyan (⅓, 1, 1) |
|
||||
| 12 | Light Red (1, ⅓, ⅓) |
|
||||
| 13 | Light Magenta (1, ⅓, 1) |
|
||||
| 14 | Yellow (1, 1, ⅓) |
|
||||
| 15 | White (1, 1, 1) |
|
||||
|
||||
```
|
||||
Brown was used as the alternative (dark yellow) was unappealing and not useful.
|
||||
```
|
||||
|
||||
We store the colour of each character by storing the fore colour in the low nibble of the colour byte, and the background colour in the high nibble. Apart from brown, all of these colours follow a pattern such that in binary, the top bit represents adding ⅓ to each component, and the other bits represent adding ⅔ to individual components. This makes it easy to convert to RGB colour values.
|
||||
|
||||
We need a method, TerminalColour, to read these 4 bit colour codes, and then call SetForeColour with the 16 bit equivalent. Try to implement this on your own. If you get stuck, or have not completed the Screen series, my implementation is given below:
|
||||
|
||||
```
|
||||
.section .text
|
||||
TerminalColour:
|
||||
teq r0,#6
|
||||
ldreq r0,=0x02B5
|
||||
beq SetForeColour
|
||||
|
||||
tst r0,#0b1000
|
||||
ldrne r1,=0x52AA
|
||||
moveq r1,#0
|
||||
tst r0,#0b0100
|
||||
addne r1,#0x15
|
||||
tst r0,#0b0010
|
||||
addne r1,#0x540
|
||||
tst r0,#0b0001
|
||||
addne r1,#0xA800
|
||||
mov r0,r1
|
||||
b SetForeColour
|
||||
```
|
||||
### 2 Showing the Text
|
||||
|
||||
The first method we really need for our terminal is TerminalDisplay, one that copies the current data from terminalBuffer to terminalScreen and the actual screen. As mentioned, this method should do a minimal amount of work, because we need to be able to call it often. It should compare the text in terminalBuffer with that in terminalDisplay, and copy it across if they're different. Remember, terminalBuffer is a circular buffer running, in this case, from terminalView to terminalStop or 128*48 characters, whichever comes sooner. If we hit terminalStop, we'll assume all characters after that point are 7f16 (ASCII delete), and have colour 0 (black on a black background).
|
||||
|
||||
Let's look at what we have to do:
|
||||
|
||||
1. Load in terminalView, terminalStop and the address of terminalDisplay.
|
||||
2. For each row:
|
||||
1. For each column:
|
||||
1. If view is not equal to stop, load the current character and colour from view
|
||||
2. Otherwise load the character as 0x7f and the colour as 0
|
||||
3. Load the current character from terminalDisplay
|
||||
4. If the character and colour are equal, go to 10
|
||||
5. Store the character and colour to terminalDisplay
|
||||
6. Call TerminalColour with the background colour in r0
|
||||
7. Call DrawCharacter with r0 = 0x7f (ASCII delete, a block), r1 = x, r2 = y
|
||||
8. Call TerminalColour with the foreground colour in r0
|
||||
9. Call DrawCharacter with r0 = character, r1 = x, r2 = y
|
||||
10. Increment the position in terminalDisplay by 2
|
||||
11. If view and stop are not equal, increment the view position by 2
|
||||
12. If the view position is at the end of textBuffer, set it to the start
|
||||
13. Increment the x co-ordinate by 8
|
||||
2. Increment the y co-ordinate by 16
|
||||
|
||||
|
||||
|
||||
Try to implement this yourself. If you get stuck, my solution is given below:
|
||||
|
||||
1.
|
||||
```
|
||||
.globl TerminalDisplay
|
||||
TerminalDisplay:
|
||||
push {r4,r5,r6,r7,r8,r9,r10,r11,lr}
|
||||
x .req r4
|
||||
y .req r5
|
||||
char .req r6
|
||||
col .req r7
|
||||
screen .req r8
|
||||
taddr .req r9
|
||||
view .req r10
|
||||
stop .req r11
|
||||
|
||||
ldr taddr,=terminalStart
|
||||
ldr view,[taddr,#terminalView - terminalStart]
|
||||
ldr stop,[taddr,#terminalStop - terminalStart]
|
||||
add taddr,#terminalBuffer - terminalStart
|
||||
add taddr,#128*128*2
|
||||
mov screen,taddr
|
||||
```
|
||||
|
||||
I go a little wild with variables here. I'm using taddr to store the location of the end of the textBuffer for ease.
|
||||
|
||||
2.
|
||||
```
|
||||
mov y,#0
|
||||
yLoop$:
|
||||
```
|
||||
Start off the y loop.
|
||||
|
||||
1.
|
||||
```
|
||||
mov x,#0
|
||||
xLoop$:
|
||||
```
|
||||
Start off the x loop.
|
||||
|
||||
1.
|
||||
```
|
||||
teq view,stop
|
||||
ldrneh char,[view]
|
||||
```
|
||||
I load both the character and the colour into char simultaneously for ease.
|
||||
|
||||
2.
|
||||
```
|
||||
moveq char,#0x7f
|
||||
```
|
||||
This line complements the one above by acting as though a black delete character was read.
|
||||
|
||||
3.
|
||||
```
|
||||
ldrh col,[screen]
|
||||
```
|
||||
For simplicity I load both the character and colour into col simultaneously.
|
||||
|
||||
4.
|
||||
```
|
||||
teq col,char
|
||||
beq xLoopContinue$
|
||||
```
|
||||
Now we can check if anything has changed with a teq.
|
||||
|
||||
5.
|
||||
```
|
||||
strh char,[screen]
|
||||
```
|
||||
We can also easily save the current value.
|
||||
|
||||
6.
|
||||
```
|
||||
lsr col,char,#8
|
||||
and char,#0x7f
|
||||
lsr r0,col,#4
|
||||
bl TerminalColour
|
||||
```
|
||||
I split up char into the colour in col and the character in char with a bitshift and an and, then use a bitshift to get the background colour to call TerminalColour.
|
||||
|
||||
7.
|
||||
```
|
||||
mov r0,#0x7f
|
||||
mov r1,x
|
||||
mov r2,y
|
||||
bl DrawCharacter
|
||||
```
|
||||
Write out a delete character which is a coloured block.
|
||||
|
||||
8.
|
||||
```
|
||||
and r0,col,#0xf
|
||||
bl TerminalColour
|
||||
```
|
||||
Use an and to get the low nibble of col then call TerminalColour.
|
||||
|
||||
9.
|
||||
```
|
||||
mov r0,char
|
||||
mov r1,x
|
||||
mov r2,y
|
||||
bl DrawCharacter
|
||||
```
|
||||
Write out the character we're supposed to write.
|
||||
|
||||
10.
|
||||
```
|
||||
xLoopContinue$:
|
||||
add screen,#2
|
||||
```
|
||||
Increment the screen pointer.
|
||||
|
||||
11.
|
||||
```
|
||||
teq view,stop
|
||||
addne view,#2
|
||||
```
|
||||
Increment the view pointer if necessary.
|
||||
|
||||
12.
|
||||
```
|
||||
teq view,taddr
|
||||
subeq view,#128*128*2
|
||||
```
|
||||
It's easy to check for view going past the end of the buffer because the end of the buffer's address is stored in taddr.
|
||||
|
||||
13.
|
||||
```
|
||||
add x,#8
|
||||
teq x,#1024
|
||||
bne xLoop$
|
||||
```
|
||||
We increment x and then loop back if there are more characters to go.
|
||||
|
||||
2.
|
||||
```
|
||||
add y,#16
|
||||
teq y,#768
|
||||
bne yLoop$
|
||||
```
|
||||
We increment y and then loop back if there are more characters to go.
|
||||
|
||||
```
|
||||
pop {r4,r5,r6,r7,r8,r9,r10,r11,pc}
|
||||
.unreq x
|
||||
.unreq y
|
||||
.unreq char
|
||||
.unreq col
|
||||
.unreq screen
|
||||
.unreq taddr
|
||||
.unreq view
|
||||
.unreq stop
|
||||
```
|
||||
Don't forget to clean up at the end!
|
||||
|
||||
|
||||
### 3 Printing Lines
|
||||
|
||||
Now we have our TerminalDisplay method, which will automatically display the contents of terminalBuffer to terminalScreen, so theoretically we can draw text. However, we don't actually have any drawing routines that work on a character based display. A quick method that will come in handy first of all is TerminalClear, which completely clears the terminal. This can actually very easily be achieved with no loops. Try to deduce why the following method suffices:
|
||||
|
||||
```
|
||||
.globl TerminalClear
|
||||
TerminalClear:
|
||||
ldr r0,=terminalStart
|
||||
add r1,r0,#terminalBuffer-terminalStart
|
||||
str r1,[r0]
|
||||
str r1,[r0,#terminalStop-terminalStart]
|
||||
str r1,[r0,#terminalView-terminalStart]
|
||||
mov pc,lr
|
||||
```
|
||||
|
||||
Now we need to make a basic method for character based displays; the Print function. This takes in a string address in r0, and a length in r1, and simply writes it to the current location at the screen. There are a few special characters to be wary of, as well as special behaviour to ensure that terminalView is kept up to date. Let's analyse what it has to do:
|
||||
|
||||
1. Check if string length is 0, if so return
|
||||
2. Load in terminalStop and terminalView
|
||||
3. Deduce the x-coordinate of terminalStop
|
||||
4. For each character:
|
||||
1. Check if the character is a new line
|
||||
2. If so, increment bufferStop to the end of the line storing a black on black delete character.
|
||||
3. Otherwise, copy the character in the current terminalColour
|
||||
4. Check if we're at the end of a line
|
||||
5. If so, check if the number of characters between terminalView and terminalStop is more than one screen
|
||||
6. If so, increment terminalView by one line
|
||||
7. Check if terminalView is at the end of the buffer, replace it with the start if so
|
||||
8. Check if terminalStop is at the end of the buffer, replace it with the start if so
|
||||
9. Check if terminalStop equals terminalStart, increment terminalStart by one line if so
|
||||
10. Check if terminalStart is at the end of the buffer, replace it with the start if so
|
||||
5. Store back terminalStop and terminalView.
|
||||
|
||||
|
||||
|
||||
See if you can implement this yourself. My solution is provided below:
|
||||
|
||||
1.
|
||||
```
|
||||
.globl Print
|
||||
Print:
|
||||
teq r1,#0
|
||||
moveq pc,lr
|
||||
```
|
||||
This quick check at the beginning makes a call to Print with a string of length 0 almost instant.
|
||||
|
||||
2.
|
||||
```
|
||||
push {r4,r5,r6,r7,r8,r9,r10,r11,lr}
|
||||
bufferStart .req r4
|
||||
taddr .req r5
|
||||
x .req r6
|
||||
string .req r7
|
||||
length .req r8
|
||||
char .req r9
|
||||
bufferStop .req r10
|
||||
view .req r11
|
||||
|
||||
mov string,r0
|
||||
mov length,r1
|
||||
|
||||
ldr taddr,=terminalStart
|
||||
ldr bufferStop,[taddr,#terminalStop-terminalStart]
|
||||
ldr view,[taddr,#terminalView-terminalStart]
|
||||
ldr bufferStart,[taddr]
|
||||
add taddr,#terminalBuffer-terminalStart
|
||||
add taddr,#128*128*2
|
||||
```
|
||||
I do a lot of setup here. bufferStart contains terminalStart, bufferStop contains terminalStop, view contains terminalView, taddr is the address of the end of terminalBuffer.
|
||||
|
||||
3.
|
||||
```
|
||||
and x,bufferStop,#0xfe
|
||||
lsr x,#1
|
||||
```
|
||||
As per usual, a sneaky alignment trick makes everything easier. Because of the aligment of terminalBuffer, the x-coordinate of any character address is simply the last 8 bits divided by 2.
|
||||
|
||||
4.
|
||||
1.
|
||||
```
|
||||
charLoop$:
|
||||
ldrb char,[string]
|
||||
and char,#0x7f
|
||||
teq char,#'\n'
|
||||
bne charNormal$
|
||||
```
|
||||
We need to check for new lines.
|
||||
|
||||
2.
|
||||
```
|
||||
mov r0,#0x7f
|
||||
clearLine$:
|
||||
strh r0,[bufferStop]
|
||||
add bufferStop,#2
|
||||
add x,#1
|
||||
teq x,#128 blt clearLine$
|
||||
|
||||
b charLoopContinue$
|
||||
```
|
||||
Loop until the end of the line, writing out 0x7f; a delete character in black on a black background.
|
||||
|
||||
3.
|
||||
```
|
||||
charNormal$:
|
||||
strb char,[bufferStop]
|
||||
ldr r0,=terminalColour
|
||||
ldrb r0,[r0]
|
||||
strb r0,[bufferStop,#1]
|
||||
add bufferStop,#2
|
||||
add x,#1
|
||||
```
|
||||
Store the current character in the string and the terminalColour to the end of the terminalBuffer and then increment it and x.
|
||||
|
||||
4.
|
||||
```
|
||||
charLoopContinue$:
|
||||
cmp x,#128
|
||||
blt noScroll$
|
||||
```
|
||||
Check if x is at the end of a line; 128.
|
||||
|
||||
5.
|
||||
```
|
||||
mov x,#0
|
||||
subs r0,bufferStop,view
|
||||
addlt r0,#128*128*2
|
||||
cmp r0,#128*(768/16)*2
|
||||
```
|
||||
Set x back to 0 and check if we're currently showing more than one screen. Remember, we're using a circular buffer, so if the difference between bufferStop and view is negative, we're actually wrapping around the buffer.
|
||||
|
||||
6.
|
||||
```
|
||||
addge view,#128*2
|
||||
```
|
||||
Add one lines worth of bytes to the view address.
|
||||
|
||||
7.
|
||||
```
|
||||
teq view,taddr
|
||||
subeq view,taddr,#128*128*2
|
||||
```
|
||||
If the view address is at the end of the buffer we subtract the buffer length from it to move it back to the start. I set taddr to the address of the end of the buffer at the beginning.
|
||||
|
||||
8.
|
||||
```
|
||||
noScroll$:
|
||||
teq bufferStop,taddr
|
||||
subeq bufferStop,taddr,#128*128*2
|
||||
```
|
||||
If the stop address is at the end of the buffer we subtract the buffer length from it to move it back to the start. I set taddr to the address of the end of the buffer at the beginning.
|
||||
|
||||
9.
|
||||
```
|
||||
teq bufferStop,bufferStart
|
||||
addeq bufferStart,#128*2
|
||||
```
|
||||
Check if bufferStop equals bufferStart. If so, add one line to bufferStart.
|
||||
|
||||
10.
|
||||
```
|
||||
teq bufferStart,taddr
|
||||
subeq bufferStart,taddr,#128*128*2
|
||||
```
|
||||
If the start address is at the end of the buffer we subtract the buffer length from it to move it back to the start. I set taddr to the address of the end of the buffer at the beginning.
|
||||
|
||||
```
|
||||
subs length,#1
|
||||
add string,#1
|
||||
bgt charLoop$
|
||||
```
|
||||
Loop until the string is done.
|
||||
|
||||
5.
|
||||
```
|
||||
charLoopBreak$:
|
||||
sub taddr,#128*128*2
|
||||
sub taddr,#terminalBuffer-terminalStart
|
||||
str bufferStop,[taddr,#terminalStop-terminalStart]
|
||||
str view,[taddr,#terminalView-terminalStart]
|
||||
str bufferStart,[taddr]
|
||||
|
||||
pop {r4,r5,r6,r7,r8,r9,r10,r11,pc}
|
||||
.unreq bufferStart
|
||||
.unreq taddr
|
||||
.unreq x
|
||||
.unreq string
|
||||
.unreq length
|
||||
.unreq char
|
||||
.unreq bufferStop
|
||||
.unreq view
|
||||
```
|
||||
Store back the variables and return.
|
||||
|
||||
|
||||
This method allows us to print arbitrary text to the screen. Throughout, I've been using the colour variable, but no where have we actually set it. Normally, terminals use special combinations of characters to change the colour. For example ASCII Escape (1b16) followed by a number 0 to f in hexadecimal could set the foreground colour to that CGA colour number. You can try implementing this yourself; my version is in the further examples section on the download page.
|
||||
|
||||
### 4 Standard Input
|
||||
|
||||
```
|
||||
By convention, in many programming languages, every program has access to stdin and stdout, which are an input and and output stream linked to the terminal. This is still true on graphical programs, though many don't use it.
|
||||
```
|
||||
|
||||
Now we have an output terminal that in theory can print out text and display it. That is only half the story however, we want input. We want to implement a method, ReadLine, which stores the next line of text a user types to a location given in r0, up to a maximum length given in r1, and returns the length of the string read in r0. The tricky thing is, the user annoyingly wants to see what they're typing as they type it, they want to use backspace to delete mistakes and they want to use return to submit commands. They probably even want a flashing underscore character to indicate the computer would like input! These perfectly reasonable requests make this method a real challenge. One way to achieve all of this is to store the text they type in memory somewhere along with its length, and then after every character, move the terminalStop address back to where it started when ReadLine was called and calling Print. This means we only have to be able to manipulate a string in memory, and then make use of our Print function.
|
||||
|
||||
Lets have a look at what ReadLine will do:
|
||||
|
||||
1. If the maximum length is 0, return 0
|
||||
2. Retrieve the current values of terminalStop and terminalView
|
||||
3. If the maximum length is bigger than half the buffer size, set it to half the buffer size
|
||||
4. Subtract one from maximum length to ensure it can store our flashing underscore or a null terminator
|
||||
5. Write an underscore to the string
|
||||
6. Write the stored terminalView and terminalStop addresses back to the memory
|
||||
7. Call Print on the current string
|
||||
8. Call TerminalDisplay
|
||||
9. Call KeyboardUpdate
|
||||
10. Call KeyboardGetChar
|
||||
11. If it is a new line character go to 16
|
||||
12. If it is a backspace character, subtract 1 from the length of the string (if it is > 0)
|
||||
13. If it is an ordinary character, write it to the string (if the length < maximum length)
|
||||
14. If the string ends in an underscore, write a space, otherwise write an underscore
|
||||
15. Go to 6
|
||||
16. Write a new line character to the end of the string
|
||||
17. Call Print and TerminalDisplay
|
||||
18. Replace the new line with a null terminator
|
||||
19. Return the length of the string
|
||||
|
||||
|
||||
|
||||
Convince yourself that this will work, and then try to implement it yourself. My implementation is given below:
|
||||
|
||||
1.
|
||||
```
|
||||
.globl ReadLine
|
||||
ReadLine:
|
||||
teq r1,#0
|
||||
moveq r0,#0
|
||||
moveq pc,lr
|
||||
```
|
||||
Quick special handling for the zero case, which is otherwise difficult.
|
||||
|
||||
2.
|
||||
```
|
||||
string .req r4
|
||||
maxLength .req r5
|
||||
input .req r6
|
||||
taddr .req r7
|
||||
length .req r8
|
||||
view .req r9
|
||||
|
||||
push {r4,r5,r6,r7,r8,r9,lr}
|
||||
|
||||
mov string,r0
|
||||
mov maxLength,r1
|
||||
ldr taddr,=terminalStart
|
||||
ldr input,[taddr,#terminalStop-terminalStart]
|
||||
ldr view,[taddr,#terminalView-terminalStart]
|
||||
mov length,#0
|
||||
```
|
||||
As per the general theme, I do a lot of initialisations early. input contains the value of terminalStop and view contains terminalView. Length starts at 0.
|
||||
|
||||
3.
|
||||
```
|
||||
cmp maxLength,#128*64
|
||||
movhi maxLength,#128*64
|
||||
```
|
||||
We have to check for unusually large reads, as we can't process them beyond the size of the terminalBuffer (I suppose we CAN, but it would be very buggy, as terminalStart could move past the stored terminalStop).
|
||||
|
||||
4.
|
||||
```
|
||||
sub maxLength,#1
|
||||
```
|
||||
Since the user wants a flashing cursor, and we ideally want to put a null terminator on this string, we need 1 spare character.
|
||||
|
||||
5.
|
||||
```
|
||||
mov r0,#'_'
|
||||
strb r0,[string,length]
|
||||
```
|
||||
Write out the underscore to let the user know they can input.
|
||||
|
||||
6.
|
||||
```
|
||||
readLoop$:
|
||||
str input,[taddr,#terminalStop-terminalStart]
|
||||
str view,[taddr,#terminalView-terminalStart]
|
||||
```
|
||||
Save the stored terminalStop and terminalView. This is important to reset the terminal after each call to Print, which changes these variables. Strictly speaking it can change terminalStart too, but this is irreversible.
|
||||
|
||||
7.
|
||||
```
|
||||
mov r0,string
|
||||
mov r1,length
|
||||
add r1,#1
|
||||
bl Print
|
||||
```
|
||||
Write the current input. We add 1 to the length for the underscore.
|
||||
|
||||
8.
|
||||
```
|
||||
bl TerminalDisplay
|
||||
```
|
||||
Copy the new text to the screen.
|
||||
|
||||
9.
|
||||
```
|
||||
bl KeyboardUpdate
|
||||
```
|
||||
Fetch the latest keyboard input.
|
||||
|
||||
10.
|
||||
```
|
||||
bl KeyboardGetChar
|
||||
```
|
||||
Retrieve the key pressed.
|
||||
|
||||
11.
|
||||
```
|
||||
teq r0,#'\n'
|
||||
beq readLoopBreak$
|
||||
teq r0,#0
|
||||
beq cursor$
|
||||
teq r0,#'\b'
|
||||
bne standard$
|
||||
```
|
||||
|
||||
Break out of the loop if we have an enter key. Also skip these conditions if we have a null terminator and process a backspace if we have one.
|
||||
|
||||
12.
|
||||
```
|
||||
delete$:
|
||||
cmp length,#0
|
||||
subgt length,#1
|
||||
b cursor$
|
||||
```
|
||||
Remove one from the length to delete a character.
|
||||
|
||||
13.
|
||||
```
|
||||
standard$:
|
||||
cmp length,maxLength
|
||||
bge cursor$
|
||||
strb r0,[string,length]
|
||||
add length,#1
|
||||
```
|
||||
Write out an ordinary character where possible.
|
||||
|
||||
14.
|
||||
```
|
||||
cursor$:
|
||||
ldrb r0,[string,length]
|
||||
teq r0,#'_'
|
||||
moveq r0,#' '
|
||||
movne r0,#'_'
|
||||
strb r0,[string,length]
|
||||
```
|
||||
Load in the last character, and change it to an underscore if it isn't one, and a space if it is.
|
||||
|
||||
15.
|
||||
```
|
||||
b readLoop$
|
||||
readLoopBreak$:
|
||||
```
|
||||
Loop until the user presses enter.
|
||||
|
||||
16.
|
||||
```
|
||||
mov r0,#'\n'
|
||||
strb r0,[string,length]
|
||||
```
|
||||
Store a new line at the end of the string.
|
||||
|
||||
17.
|
||||
```
|
||||
str input,[taddr,#terminalStop-terminalStart]
|
||||
str view,[taddr,#terminalView-terminalStart]
|
||||
mov r0,string
|
||||
mov r1,length
|
||||
add r1,#1
|
||||
bl Print
|
||||
bl TerminalDisplay
|
||||
```
|
||||
Reset the terminalView and terminalStop and then Print and TerminalDisplay the final input.
|
||||
|
||||
18.
|
||||
```
|
||||
mov r0,#0
|
||||
strb r0,[string,length]
|
||||
```
|
||||
Write out the null terminator.
|
||||
|
||||
19.
|
||||
```
|
||||
mov r0,length
|
||||
pop {r4,r5,r6,r7,r8,r9,pc}
|
||||
.unreq string
|
||||
.unreq maxLength
|
||||
.unreq input
|
||||
.unreq taddr
|
||||
.unreq length
|
||||
.unreq view
|
||||
```
|
||||
Return the length.
|
||||
|
||||
|
||||
|
||||
|
||||
### 5 The Terminal: Rise of the Machine
|
||||
|
||||
So, now we can theoretically interact with the user on the terminal. The most obvious thing to do is to put this to the test! In 'main.s' delete everything after bl UsbInitialise and copy in the following code:
|
||||
|
||||
```
|
||||
reset$:
|
||||
mov sp,#0x8000
|
||||
bl TerminalClear
|
||||
|
||||
ldr r0,=welcome
|
||||
mov r1,#welcomeEnd-welcome
|
||||
bl Print
|
||||
|
||||
loop$:
|
||||
ldr r0,=prompt
|
||||
mov r1,#promptEnd-prompt
|
||||
bl Print
|
||||
|
||||
ldr r0,=command
|
||||
mov r1,#commandEnd-command
|
||||
bl ReadLine
|
||||
|
||||
teq r0,#0
|
||||
beq loopContinue$
|
||||
|
||||
mov r4,r0
|
||||
|
||||
ldr r5,=command
|
||||
ldr r6,=commandTable
|
||||
|
||||
ldr r7,[r6,#0]
|
||||
ldr r9,[r6,#4]
|
||||
commandLoop$:
|
||||
ldr r8,[r6,#8]
|
||||
sub r1,r8,r7
|
||||
|
||||
cmp r1,r4
|
||||
bgt commandLoopContinue$
|
||||
|
||||
mov r0,#0
|
||||
commandName$:
|
||||
ldrb r2,[r5,r0]
|
||||
ldrb r3,[r7,r0]
|
||||
teq r2,r3
|
||||
bne commandLoopContinue$
|
||||
add r0,#1
|
||||
teq r0,r1
|
||||
bne commandName$
|
||||
|
||||
ldrb r2,[r5,r0]
|
||||
teq r2,#0
|
||||
teqne r2,#' '
|
||||
bne commandLoopContinue$
|
||||
|
||||
mov r0,r5
|
||||
mov r1,r4
|
||||
mov lr,pc
|
||||
mov pc,r9
|
||||
b loopContinue$
|
||||
|
||||
commandLoopContinue$:
|
||||
add r6,#8
|
||||
mov r7,r8
|
||||
ldr r9,[r6,#4]
|
||||
teq r9,#0
|
||||
bne commandLoop$
|
||||
|
||||
ldr r0,=commandUnknown
|
||||
mov r1,#commandUnknownEnd-commandUnknown
|
||||
ldr r2,=formatBuffer
|
||||
ldr r3,=command
|
||||
bl FormatString
|
||||
|
||||
mov r1,r0
|
||||
ldr r0,=formatBuffer
|
||||
bl Print
|
||||
|
||||
loopContinue$:
|
||||
bl TerminalDisplay
|
||||
b loop$
|
||||
|
||||
echo:
|
||||
cmp r1,#5
|
||||
movle pc,lr
|
||||
|
||||
add r0,#5
|
||||
sub r1,#5
|
||||
b Print
|
||||
|
||||
ok:
|
||||
teq r1,#5
|
||||
beq okOn$
|
||||
teq r1,#6
|
||||
beq okOff$
|
||||
mov pc,lr
|
||||
|
||||
okOn$:
|
||||
ldrb r2,[r0,#3]
|
||||
teq r2,#'o'
|
||||
ldreqb r2,[r0,#4]
|
||||
teqeq r2,#'n'
|
||||
movne pc,lr
|
||||
mov r1,#0
|
||||
b okAct$
|
||||
|
||||
okOff$:
|
||||
ldrb r2,[r0,#3]
|
||||
teq r2,#'o'
|
||||
ldreqb r2,[r0,#4]
|
||||
teqeq r2,#'f'
|
||||
ldreqb r2,[r0,#5]
|
||||
teqeq r2,#'f'
|
||||
movne pc,lr
|
||||
mov r1,#1
|
||||
|
||||
okAct$:
|
||||
|
||||
mov r0,#16
|
||||
b SetGpio
|
||||
|
||||
.section .data
|
||||
.align 2
|
||||
welcome: .ascii "Welcome to Alex's OS - Everyone's favourite OS"
|
||||
welcomeEnd:
|
||||
.align 2
|
||||
prompt: .ascii "\n> "
|
||||
promptEnd:
|
||||
.align 2
|
||||
command:
|
||||
.rept 128
|
||||
.byte 0
|
||||
.endr
|
||||
commandEnd:
|
||||
.byte 0
|
||||
.align 2
|
||||
commandUnknown: .ascii "Command `%s' was not recognised.\n"
|
||||
commandUnknownEnd:
|
||||
.align 2
|
||||
formatBuffer:
|
||||
.rept 256
|
||||
.byte 0
|
||||
.endr
|
||||
formatEnd:
|
||||
|
||||
.align 2
|
||||
commandStringEcho: .ascii "echo"
|
||||
commandStringReset: .ascii "reset"
|
||||
commandStringOk: .ascii "ok"
|
||||
commandStringCls: .ascii "cls"
|
||||
commandStringEnd:
|
||||
|
||||
.align 2
|
||||
commandTable:
|
||||
.int commandStringEcho, echo
|
||||
.int commandStringReset, reset$
|
||||
.int commandStringOk, ok
|
||||
.int commandStringCls, TerminalClear
|
||||
.int commandStringEnd, 0
|
||||
```
|
||||
This code brings everything together into a simple command line operating system. The commands available are echo, reset, ok and cls. echo copies any text after it back to the terminal, reset resets the operating system if things go wrong, ok has two functions: ok on turns the OK LED on, and ok off turns the OK LED off, and cls clears the terminal using TerminalClear.
|
||||
|
||||
Have a go with this code on the Raspberry Pi. If it doesn't work, please see our troubleshooting page.
|
||||
|
||||
When it works, congratulations you've completed a basic terminal Operating System, and have completed the input series. Unfortunately, this is as far as these tutorials go at the moment, but I hope to make more in the future. Please send feedback to awc32@cam.ac.uk.
|
||||
|
||||
You're now in position to start building some simple terminal Operating Systems. My code above builds up a table of available commands in commandTable. Each entry in the table is an int for the address of the string, and an int for the address of the code to run. The last entry has to be commandStringEnd, 0. Try implementing some of your own commands, using our existing functions, or making new ones. The parameters for the functions to run are r0 is the address of the command the user typed, and r1 is the length. You can use this to pass inputs to your commands. Maybe you could make a calculator program, perhaps a drawing program or a chess program. Whatever ideas you've got, give them a go!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/input02.html
|
||||
|
||||
作者:[Alex Chadwick][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.cl.cam.ac.uk
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/input01.html
|
||||
[2]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/images/circular_buffer.png
|
||||
@@ -0,0 +1,503 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Computer Laboratory – Raspberry Pi: Lesson 6 Screen01)
|
||||
[#]: via: (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen01.html)
|
||||
[#]: author: (Alex Chadwick https://www.cl.cam.ac.uk)
|
||||
|
||||
Computer Laboratory – Raspberry Pi: Lesson 6 Screen01
|
||||
======
|
||||
|
||||
Welcome to the Screen lesson series. In this series, you will learn how to control the screen using the Raspberry Pi in assembly code, starting at just displaying random data, then moving up to displaying a fixed image, displaying text and then formatting numbers into text. It is assumed that you have already completed the OK series, and so things covered in this series will not be repeated here.
|
||||
|
||||
This first screen lesson teaches some basic theory about graphics, and then applies it to display a gradient pattern to the screen or TV.
|
||||
|
||||
### 1 Getting Started
|
||||
|
||||
It is expected that you have completed the OK series, and so functions in the 'gpio.s' file and 'systemTimer.s' file from that series will be called. If you do not have these files, or prefer to use a correct implementation, download the solution to OK05.s. The 'main.s' file from here will also be useful, up to and including mov sp,#0x8000. Please delete anything after that line.
|
||||
|
||||
### 2 Computer Graphics
|
||||
|
||||
There are a few systems for representing colours as numbers. Here we focus on RGB systems, but HSL is another common system used.
|
||||
|
||||
As you're hopefully beginning to appreciate, at a fundamental level, computers are very stupid. They have a limited number of instructions, almost exclusively to do with maths, and yet somehow they are capable of doing many things. The thing we currently wish to understand is how a computer could possibly put an image on the screen. How would we translate this problem into binary? The answer is relatively straightforward; we devise some system of numbering each colour, and then we store one number for every pixel on the screen. A pixel is a small dot on your screen. If you move very close, you will probably be able to make out individual pixels on your screen, and be able to see that everything image is just made out of these pixels in combination.
|
||||
|
||||
As the computer age advanced, people wanted more and more complicated graphics, and so the concept of a graphics card was invented. The graphics card is a secondary processor on your computer which only exists to draw images to the screen. It has the job of turning the pixel value information into light intensity levels to be transmitted to the screen. On modern computers, graphics cards can also do a lot more than that, such as drawing 3D graphics. In this tutorial however, we will just concentrate on the first use of graphics cards; getting pixel colours from memory out to the screen.
|
||||
|
||||
One issue that is raised immediately by all this is the system we use for numbering colours. There are several choices, each producing outputs of different quality. I will outline a few here for completeness.
|
||||
|
||||
Although some images here have few colours they use a technique called spatial dithering. This allows them to still show a good representation of the image, with very few colours. Many early Operating Systems used this technique.
|
||||
|
||||
| Name | Unique Colours | Description | Examples |
|
||||
| ----------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------- |
|
||||
| Monochrome | 2 | Use 1 bit to store each pixel, with a 1 being white, and a 0 being black. | ![Monochrome image of a bird][1] |
|
||||
| Greyscale | 256 | Use 1 byte to store each pixel, with 255 representing white, 0 representing black, and all values in between representing a linear combination of the two. | ![Geryscale image of a bird][2] |
|
||||
| 8 Colour | 8 | Use 3 bits to store each pixel, the first bit representing the presence of a red channel, the second representing a green channel and the third a blue channel. | ![8 colour image of a bird][3] |
|
||||
| Low Colour | 256 | Use 8 bits to store each pixel, the first 3 bit representing the intensity of the red channel, the next 3 bits representing the intensity of the green channel and the final 2 bits representing the intensity of the blue channel. | ![Low colour image of a bird][4] |
|
||||
| High Colour | 65,536 | Use 16 bits to store each pixel, the first 5 bit representing the intensity of the red channel, the next 6 bits representing the intensity of the green channel and the final 5 bits representing the intensity of the blue channel. | ![High colour image of a bird][5] |
|
||||
| True Colour | 16,777,216 | Use 24 bits to store each pixel, the first 8 bits representing the intensity of the red channel, the second 8 representing the green channel and the final 8 bits the blue channel. | ![True colour image of a bird][6] |
|
||||
| RGBA32 | 16,777,216 with 256 transparency levels | Use 32 bits to store each pixel, the first 8 bits representing the intensity of the red channel, the second 8 representing the green channel, the third 8 bits the blue channel, and the final 8 bits a transparency channel. The transparency channel is only considered when drawing one image on top of another and is stored such that a value of 0 indicates the image behind's colour, a value of 255 represents this image's colour, and all values between represent a mix. | |
|
||||
|
||||
|
||||
In this tutorial we shall use High Colour initially. As you can see form the image, it is produces clear, good quality images, but it doesn't take up as much space as True Colour. That said, for quite a small display of 800x600 pixels, it would still take just under 1 megabyte of space. It also has the advantage that the size is a multiple of a power of 2, which greatly reduces the complexity of getting information compared with True Colour.
|
||||
|
||||
```
|
||||
Storing the frame buffer places a heavy memory burden on a computer. For this reason, early computers often cheated, by, for example, storing a screens worth of text, and just drawing each letter to the screen every time it is refreshed separately.
|
||||
```
|
||||
|
||||
The Raspberry Pi has a very special and rather odd relationship with it's graphics processor. On the Raspberry Pi, the graphics processor actually runs first, and is responsible for starting up the main processor. This is very unusual. Ultimately it doesn't make too much difference, but in many interactions, it often feels like the processor is secondary, and the graphics processor is the most important. The two communicate on the Raspberry Pi by what is called the 'mailbox'. Each can deposit mail for the other, which will be collected at some future point and then dealt with. We shall use the mailbox to ask the graphics processor for an address. The address will be a location to which we can write the pixel colour information for the screen, called a frame buffer, and the graphics card will regularly check this location, and update the pixels on the screen appropriately.
|
||||
|
||||
### 3 Programming the Postman
|
||||
|
||||
```
|
||||
Message passing is quite a common way for components to communicate. Some Operating Systems use virtual message passing to allow programs to communicate.
|
||||
```
|
||||
|
||||
The first thing we are going to need to program is a 'postman'. This is just two methods: MailboxRead, reading one message from the mailbox channel in r0. and MailboxWrite, writing the value in the top 28 bits of r0 to the mailbox channel in r1. The Raspberry Pi has 7 mailbox channels for communication with the graphics processor, only the first of which is useful to us, as it is for negotiating the frame buffer.
|
||||
|
||||
The following table and diagrams describe the operation of the mailbox.
|
||||
|
||||
Table 3.1 Mailbox Addresses
|
||||
| Address | Size / Bytes | Name | Description | Read / Write |
|
||||
| 2000B880 | 4 | Read | Receiving mail. | R |
|
||||
| 2000B890 | 4 | Poll | Receive without retrieving. | R |
|
||||
| 2000B894 | 4 | Sender | Sender information. | R |
|
||||
| 2000B898 | 4 | Status | Information. | R |
|
||||
| 2000B89C | 4 | Configuration | Settings. | RW |
|
||||
| 2000B8A0 | 4 | Write | Sending mail. | W |
|
||||
|
||||
In order to send a message to a particular mailbox:
|
||||
|
||||
1. The sender waits until the Status field has a 0 in the top bit.
|
||||
2. The sender writes to Write such that the lowest 4 bits are the mailbox to write to, and the upper 28 bits are the message to write.
|
||||
|
||||
|
||||
|
||||
In order to read a message:
|
||||
|
||||
1. The receiver waits until the Status field has a 0 in the 30th bit.
|
||||
2. The receiver reads from Read.
|
||||
3. The receiver confirms the message is for the correct mailbox, and tries again if not.
|
||||
|
||||
|
||||
|
||||
If you're feeling particularly confident, you now have enough information to write the two methods we need. If not, read on.
|
||||
|
||||
As always the first method I recommend you implement is one to get the address of the mailbox region.
|
||||
|
||||
```
|
||||
.globl GetMailboxBase
|
||||
GetMailboxBase:
|
||||
ldr r0,=0x2000B880
|
||||
mov pc,lr
|
||||
```
|
||||
|
||||
The sending procedure is least complicated, so we shall implement this first. As your methods become more and more complicated, you will need to start planning them in advance. A good way to do this might be to write out a simple list of the steps that need to be done, in a fair amount of detail, like below.
|
||||
|
||||
1. Our input will be what to write (r0), and what mailbox to write it to (r1). We must validate this is by checking it is a real mailbox, and that the low 4 bits of the value are 0. Never forget to validate inputs.
|
||||
2. Use GetMailboxBase to retrieve the address.
|
||||
3. Read from the Status field.
|
||||
4. Check the top bit is 0. If not, go back to 3.
|
||||
5. Combine the value to write and the channel.
|
||||
6. Write to the Write.
|
||||
|
||||
|
||||
|
||||
Let's handle each of these in order.
|
||||
|
||||
1.
|
||||
```
|
||||
.globl MailboxWrite
|
||||
MailboxWrite:
|
||||
tst r0,#0b1111
|
||||
movne pc,lr
|
||||
cmp r1,#15
|
||||
movhi pc,lr
|
||||
```
|
||||
|
||||
```
|
||||
tst reg,#val computes and reg,#val and compares the result with 0.
|
||||
```
|
||||
|
||||
This achieves our validation on r0 and r1. tst is a function that compares two numbers by computing the logical and operation of the numbers, and then comparing the result with 0. In this case it checks that the lowest 4 bits of the input in r0 are all 0.
|
||||
|
||||
2.
|
||||
```
|
||||
channel .req r1
|
||||
value .req r2
|
||||
mov value,r0
|
||||
push {lr}
|
||||
bl GetMailboxBase
|
||||
mailbox .req r0
|
||||
```
|
||||
|
||||
This code ensures we will not overwrite our value, or link register and calls GetMailboxBase.
|
||||
|
||||
3.
|
||||
```
|
||||
wait1$:
|
||||
status .req r3
|
||||
ldr status,[mailbox,#0x18]
|
||||
```
|
||||
|
||||
This code loads in the current status.
|
||||
|
||||
4.
|
||||
```
|
||||
tst status,#0x80000000
|
||||
.unreq status
|
||||
bne wait1$
|
||||
```
|
||||
|
||||
This code checks that the top bit of the status field is 0, and loops back to 3. if it is not.
|
||||
|
||||
5.
|
||||
```
|
||||
add value,channel
|
||||
.unreq channel
|
||||
```
|
||||
|
||||
This code combines the channel and value together.
|
||||
|
||||
6.
|
||||
```
|
||||
str value,[mailbox,#0x20]
|
||||
.unreq value
|
||||
.unreq mailbox
|
||||
pop {pc}
|
||||
```
|
||||
|
||||
This code stores the result to the write field.
|
||||
|
||||
|
||||
|
||||
|
||||
The code for MailboxRead is quite similar.
|
||||
|
||||
1. Our input will be what mailbox to read from (r0). We must validate this is by checking it is a real mailbox. Never forget to validate inputs.
|
||||
2. Use GetMailboxBase to retrieve the address.
|
||||
3. Read from the Status field.
|
||||
4. Check the 30th bit is 0. If not, go back to 3.
|
||||
5. Read from the Read field.
|
||||
6. Check the mailbox is the one we want, if not go back to 3.
|
||||
7. Return the result.
|
||||
|
||||
|
||||
|
||||
Let's handle each of these in order.
|
||||
|
||||
1.
|
||||
```
|
||||
.globl MailboxRead
|
||||
MailboxRead:
|
||||
cmp r0,#15
|
||||
movhi pc,lr
|
||||
```
|
||||
|
||||
This achieves our validation on r0.
|
||||
|
||||
2.
|
||||
```
|
||||
channel .req r1
|
||||
mov channel,r0
|
||||
push {lr}
|
||||
bl GetMailboxBase
|
||||
mailbox .req r0
|
||||
```
|
||||
|
||||
This code ensures we will not overwrite our value, or link register and calls GetMailboxBase.
|
||||
|
||||
3.
|
||||
```
|
||||
rightmail$:
|
||||
wait2$:
|
||||
status .req r2
|
||||
ldr status,[mailbox,#0x18]
|
||||
```
|
||||
|
||||
This code loads in the current status.
|
||||
|
||||
4.
|
||||
```
|
||||
tst status,#0x40000000
|
||||
.unreq status
|
||||
bne wait2$
|
||||
```
|
||||
|
||||
This code checks that the 30th bit of the status field is 0, and loops back to 3. if it is not.
|
||||
|
||||
5.
|
||||
```
|
||||
mail .req r2
|
||||
ldr mail,[mailbox,#0]
|
||||
```
|
||||
|
||||
This code reads the next item from the mailbox.
|
||||
|
||||
6.
|
||||
```
|
||||
inchan .req r3
|
||||
and inchan,mail,#0b1111
|
||||
teq inchan,channel
|
||||
.unreq inchan
|
||||
bne rightmail$
|
||||
.unreq mailbox
|
||||
.unreq channel
|
||||
```
|
||||
|
||||
This code checks that the channel of the mail we just read is the one we were supplied. If not it loops back to 3.
|
||||
|
||||
7.
|
||||
```
|
||||
and r0,mail,#0xfffffff0
|
||||
.unreq mail
|
||||
pop {pc}
|
||||
```
|
||||
|
||||
This code moves the answer (the top 28 bits of mail) to r0.
|
||||
|
||||
|
||||
|
||||
|
||||
### 4 My Dearest Graphics Processor
|
||||
|
||||
Through our new postman, we now have the ability to send a message to the graphics card. What should we send though? This was certainly a difficult question for me to find the answer to, as it isn't in any online manual that I have found. Nevertheless, by looking at the GNU/Linux for the Raspberry Pi, we are able to work out what we needed to send.
|
||||
|
||||
```
|
||||
Since the RAM is shared between the graphics processor and the processor on the Pi, we can just send where to find our message. This is called DMA, many complicated devices use this to speed up access times.
|
||||
```
|
||||
|
||||
The message is very simple. We describe the framebuffer we would like, and the graphics card either agrees to our request, in which case it sends us back a 0, and fills in a small questionnaire we make, or it sends back a non-zero number, in which case we know it is unhappy. Unfortunately, I have no idea what any of the other numbers it can send back are, nor what they mean, but only when it sends a zero it is happy. Fortunately it always seems to send a zero for sensible inputs, so we don't need to worry too much.
|
||||
|
||||
For simplicity we shall design our request in advance, and store it in the .data section. In a file called 'framebuffer.s' place the following code:
|
||||
|
||||
```
|
||||
.section .data
|
||||
.align 4
|
||||
.globl FrameBufferInfo
|
||||
FrameBufferInfo:
|
||||
.int 1024 /bin /boot /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var #0 Physical Width */
|
||||
.int 768 /bin /boot /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var #4 Physical Height */
|
||||
.int 1024 /bin /boot /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var #8 Virtual Width */
|
||||
.int 768 /bin /boot /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var #12 Virtual Height */
|
||||
.int 0 /bin /boot /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var #16 GPU - Pitch */
|
||||
.int 16 /bin /boot /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var #20 Bit Depth */
|
||||
.int 0 /bin /boot /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var #24 X */
|
||||
.int 0 /bin /boot /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var #28 Y */
|
||||
.int 0 /bin /boot /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var #32 GPU - Pointer */
|
||||
.int 0 /bin /boot /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var #36 GPU - Size */
|
||||
```
|
||||
|
||||
This is the format of our messages to the graphics processor. The first two words describe the physical width and height. The second pair is the virtual width and height. The framebuffer's width and height are the virtual width and height, and the GPU scales the framebuffer as need to fit the physical screen. The next word is one of the ones the GPU will fill in if it grants our request. It will be the number of bytes on each row of the frame buffer, in this case 2 × 1024 = 2048. The next word is how many bits to allocate to each pixel. Using a value of 16 means that the graphics processor uses High Colour mode described above. A value of 24 would use True Colour, and 32 would use RGBA32. The next two words are x and y offsets, which mean the number of pixels to skip in the top left corner of the screen when copying the framebuffer to the screen. Finally, the last two words are filled in by the graphics processor, the first of which is the actual pointer to the frame buffer, and the second is the size of the frame buffer in bytes.
|
||||
|
||||
```
|
||||
When working with devices using DMA, alignment constraints become very important. The GPU expects the message to be 16 byte aligned.
|
||||
```
|
||||
|
||||
I was very careful to include a .align 4 here. As discussed before, this ensures the lowest 4 bits of the address of the next line are 0. Thus, we know for sure that FrameBufferInfo will be placed at an address we can send to the graphics processor, as our mailbox only sends values with the low 4 bits all 0.
|
||||
|
||||
So, now that we have our message, we can write code to send it. The communication will go as follows:
|
||||
|
||||
1. Write the address of FrameBufferInfo + 0x40000000 to mailbox 1.
|
||||
2. Read the result from mailbox 1. If it is not zero, we didn't ask for a proper frame buffer.
|
||||
3. Copy our images to the pointer, and they will appear on screen!
|
||||
|
||||
|
||||
|
||||
I've said something that I've not mentioned before in step 1. We have to add 0x40000000 to the address of FrameBufferInfo before sending it. This is actually a special signal to the GPU of how it should write to the structure. If we just send the address, the GPU will write its response, but will not make sure we can see it by flushing its cache. The cache is a piece of memory where a processor stores values its working on before sending them to the RAM. By adding 0x40000000, we tell the GPU not to use its cache for these writes, which ensures we will be able to see the change.
|
||||
|
||||
Since there is quite a lot going on there, it would be best to implement this as a function, rather than just putting the code into main.s. We shall write a function InitialiseFrameBuffer which does all this negotiation and returns the pointer to the frame buffer info data above, once it has a pointer in it. For ease, we should also make it so that the width, height and bit depth of the frame buffer are inputs to this method, so that it is easy to change in main.s without having to get into the details of the negotiation.
|
||||
|
||||
Once again, let's write down in detail the steps we will have to take. If you're feeling confident, try writing the function straight away.
|
||||
|
||||
1. Validate our inputs.
|
||||
2. Write the inputs into the frame buffer.
|
||||
3. Send the address of the frame buffer + 0x40000000 to the mailbox.
|
||||
4. Receive the reply from the mailbox.
|
||||
5. If the reply is not 0, the method has failed. We should return 0 to indicate failure.
|
||||
6. Return a pointer to the frame buffer info.
|
||||
|
||||
|
||||
|
||||
Now we're getting into much bigger methods than before. Below is one implementation of the above.
|
||||
|
||||
1.
|
||||
```
|
||||
.section .text
|
||||
.globl InitialiseFrameBuffer
|
||||
InitialiseFrameBuffer:
|
||||
width .req r0
|
||||
height .req r1
|
||||
bitDepth .req r2
|
||||
cmp width,#4096
|
||||
cmpls height,#4096
|
||||
cmpls bitDepth,#32
|
||||
result .req r0
|
||||
movhi result,#0
|
||||
movhi pc,lr
|
||||
```
|
||||
|
||||
This code checks that the width and height are less than or equal to 4096, and that the bit depth is less than or equal to 32. This is once again using a trick with conditional execution. Convince yourself that this works.
|
||||
|
||||
2.
|
||||
```
|
||||
fbInfoAddr .req r3
|
||||
push {lr}
|
||||
ldr fbInfoAddr,=FrameBufferInfo
|
||||
str width,[fbInfoAddr,#0]
|
||||
str height,[fbInfoAddr,#4]
|
||||
str width,[fbInfoAddr,#8]
|
||||
str height,[fbInfoAddr,#12]
|
||||
str bitDepth,[fbInfoAddr,#20]
|
||||
.unreq width
|
||||
.unreq height
|
||||
.unreq bitDepth
|
||||
```
|
||||
|
||||
This code simply writes into our frame buffer structure defined above. I also take the opportunity to push the link register onto the stack.
|
||||
|
||||
3.
|
||||
```
|
||||
mov r0,fbInfoAddr
|
||||
add r0,#0x40000000
|
||||
mov r1,#1
|
||||
bl MailboxWrite
|
||||
```
|
||||
|
||||
The inputs to the MailboxWrite method are the value to write in r0, and the channel to write to in r1.
|
||||
|
||||
4.
|
||||
```
|
||||
mov r0,#1
|
||||
bl MailboxRead
|
||||
```
|
||||
|
||||
The inputs to the MailboxRead method is the channel to write to in r0, and the output is the value read.
|
||||
|
||||
5.
|
||||
```
|
||||
teq result,#0
|
||||
movne result,#0
|
||||
popne {pc}
|
||||
```
|
||||
|
||||
This code checks if the result of the MailboxRead method is 0, and returns 0 if not.
|
||||
|
||||
6.
|
||||
```
|
||||
mov result,fbInfoAddr
|
||||
pop {pc}
|
||||
.unreq result
|
||||
.unreq fbInfoAddr
|
||||
```
|
||||
|
||||
This code finishes off and returns the frame buffer info address.
|
||||
|
||||
|
||||
|
||||
|
||||
### 5 A Pixel Within a Row Within a Frame
|
||||
|
||||
So, we've now created our methods to communicate with the graphics processor. It should now be capable of giving us the pointer to a frame buffer we can draw graphics to. Let's draw something now.
|
||||
|
||||
In this first example, we'll just draw consecutive colours to the screen. It won't look pretty, but at least it will be working. How we will do this is by setting each pixel in the framebuffer to a consecutive number, and continually doing so.
|
||||
|
||||
Copy the following code to 'main.s' after mov sp,#0x8000
|
||||
|
||||
```
|
||||
mov r0,#1024
|
||||
mov r1,#768
|
||||
mov r2,#16
|
||||
bl InitialiseFrameBuffer
|
||||
```
|
||||
|
||||
This code simply uses our InitialiseFrameBuffer method to create a frame buffer with width 1024, height 768, and bit depth 16. You can try different values in here if you wish, as long as you are consistent throughout the code. Since it's possible that this method can return 0 if the graphics processor did not give us a frame buffer, we had better check for this, and turn the OK LED on if it happens.
|
||||
|
||||
```
|
||||
teq r0,#0
|
||||
bne noError$
|
||||
|
||||
mov r0,#16
|
||||
mov r1,#1
|
||||
bl SetGpioFunction
|
||||
mov r0,#16
|
||||
mov r1,#0
|
||||
bl SetGpio
|
||||
|
||||
error$:
|
||||
b error$
|
||||
|
||||
noError$:
|
||||
fbInfoAddr .req r4
|
||||
mov fbInfoAddr,r0
|
||||
```
|
||||
|
||||
Now that we have the frame buffer info address, we need to get the frame buffer pointer from it, and start drawing to the screen. We will do this using two loops, one going down the rows, and one going along the columns. On the Raspberry Pi, indeed in most applications, pictures are stored left to right then top to bottom, so we have to do the loops in the order I have said.
|
||||
|
||||
|
||||
```
|
||||
render$:
|
||||
|
||||
fbAddr .req r3
|
||||
ldr fbAddr,[fbInfoAddr,#32]
|
||||
|
||||
colour .req r0
|
||||
y .req r1
|
||||
mov y,#768
|
||||
drawRow$:
|
||||
|
||||
x .req r2
|
||||
mov x,#1024
|
||||
drawPixel$:
|
||||
|
||||
strh colour,[fbAddr]
|
||||
add fbAddr,#2
|
||||
sub x,#1
|
||||
teq x,#0
|
||||
bne drawPixel$
|
||||
|
||||
sub y,#1
|
||||
add colour,#1
|
||||
teq y,#0
|
||||
bne drawRow$
|
||||
|
||||
b render$
|
||||
|
||||
.unreq fbAddr
|
||||
.unreq fbInfoAddr
|
||||
```
|
||||
|
||||
```
|
||||
strh reg,[dest] stores the low half word number in reg at the address given by dest.
|
||||
```
|
||||
|
||||
This is quite a large chunk of code, and has a loop within a loop within a loop. To help get your head around the looping, I've indented the code which is looped, depending on which loop it is in. This is quite common in most high level programming languages, and the assembler simply ignores the tabs. We see here that I load in the frame buffer address from the frame buffer information structure, and then loop over every row, then every pixel on the row. At each pixel, I use an strh (store half word) command to store the current colour, then increment the address we're writing to. After drawing each row, we increment the colour that we are drawing. After drawing the full screen, we branch back to the beginning.
|
||||
|
||||
### 6 Seeing the Light
|
||||
|
||||
Now you're ready to test this code on the Raspberry Pi. You should see a changing gradient pattern. Be careful: until the first message is sent to the mailbox, the Raspberry Pi displays a still gradient pattern between the four corners. If it doesn't work, please see our troubleshooting page.
|
||||
|
||||
If it does work, congratulations! You can now control the screen! Feel free to alter this code to draw whatever pattern you like. You can do some very nice gradient patterns, and can compute the value of each pixel directly, since y contains a y-coordinate for the pixel, and x contains an x-coordinate. In the next lesson, [Lesson 7: Screen 02][7], we will look at one of the most common drawing tasks, lines.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen01.html
|
||||
|
||||
作者:[Alex Chadwick][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.cl.cam.ac.uk
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/images/colour1bImage.png
|
||||
[2]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/images/colour8gImage.png
|
||||
[3]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/images/colour3bImage.png
|
||||
[4]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/images/colour8bImage.png
|
||||
[5]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/images/colour16bImage.png
|
||||
[6]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/images/colour24bImage.png
|
||||
[7]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen02.html
|
||||
@@ -0,0 +1,449 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Computer Laboratory – Raspberry Pi: Lesson 7 Screen02)
|
||||
[#]: via: (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen02.html)
|
||||
[#]: author: (Alex Chadwick https://www.cl.cam.ac.uk)
|
||||
|
||||
Computer Laboratory – Raspberry Pi: Lesson 7 Screen02
|
||||
======
|
||||
|
||||
The Screen02 lesson builds on Screen01, by teaching how to draw lines and also a small feature on generating pseudo random numbers. It is assumed you have the code for the [Lesson 6: Screen01][1] operating system as a basis.
|
||||
|
||||
### 1 Dots
|
||||
|
||||
Now that we've got the screen working, it is only natural to start waiting to create sensible images. It would be very nice indeed if we were able to actually draw something. One of the most basic components in all drawings is a line. If we were able to draw a line between any two points on the screen, we could start creating more complicated drawings just using combinations of these lines.
|
||||
|
||||
```
|
||||
To allow complex drawing, some systems use a colouring function rather than just one colour to draw things. Each pixel calls the colouring function to determine what colour to draw there.
|
||||
```
|
||||
|
||||
We will attempt to implement this in assembly code, but first we could really use some other functions to help. We need a function I will call SetPixel that changes the colour of a particular pixel, supplied as inputs in r0 and r1. It will be helpful for future if we write code that could draw to any memory, not just the screen, so first of all, we need some system to control where we are actually going to draw to. I think that the best way to do this would be to have a piece of memory which stores where we are going to draw to. What we should end up with is a stored address which normally points to the frame buffer structure from last time. We will use this at all times in our drawing method. That way, if we want to draw to a different image in another part of our operating system, we could make this value the address of a different structure, and use the exact same code. For simplicity we will use another piece of data to control the colour of our drawings.
|
||||
|
||||
Copy the following code to a new file called 'drawing.s'.
|
||||
|
||||
```
|
||||
.section .data
|
||||
.align 1
|
||||
foreColour:
|
||||
.hword 0xFFFF
|
||||
|
||||
.align 2
|
||||
graphicsAddress:
|
||||
.int 0
|
||||
|
||||
.section .text
|
||||
.globl SetForeColour
|
||||
SetForeColour:
|
||||
cmp r0,#0x10000
|
||||
movhs pc,lr
|
||||
ldr r1,=foreColour
|
||||
strh r0,[r1]
|
||||
mov pc,lr
|
||||
|
||||
.globl SetGraphicsAddress
|
||||
SetGraphicsAddress:
|
||||
ldr r1,=graphicsAddress
|
||||
str r0,[r1]
|
||||
mov pc,lr
|
||||
```
|
||||
|
||||
This is just the pair of functions that I described above, along with their data. We will use them in 'main.s' before drawing anything to control where and what we are drawing.
|
||||
|
||||
```
|
||||
Building generic methods like SetPixel which we can build other methods on top of is a useful idea. We have to make sure the method is fast though, since we will use it a lot.
|
||||
```
|
||||
|
||||
Our next task is to implement a SetPixel method. This needs to take two parameters, the x and y co-ordinate of a pixel, and it should use the graphicsAddress and foreColour we have just defined to control exactly what and where it is drawing. If you think you can implement this immediately, do, if not I shall outline the steps to be taken, and then give an example implementation.
|
||||
|
||||
1. Load in the graphicsAddress.
|
||||
2. Check that the x and y co-ordinates of the pixel are less than the width and height.
|
||||
3. Compute the address of the pixel to write. (hint: frameBufferAddress + (x + y core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated width) * pixel size)
|
||||
4. Load in the foreColour.
|
||||
5. Store it at the address.
|
||||
|
||||
|
||||
|
||||
An implementation of the above follows.
|
||||
|
||||
1.
|
||||
```
|
||||
.globl DrawPixel
|
||||
DrawPixel:
|
||||
px .req r0
|
||||
py .req r1
|
||||
addr .req r2
|
||||
ldr addr,=graphicsAddress
|
||||
ldr addr,[addr]
|
||||
```
|
||||
|
||||
2.
|
||||
```
|
||||
height .req r3
|
||||
ldr height,[addr,#4]
|
||||
sub height,#1
|
||||
cmp py,height
|
||||
movhi pc,lr
|
||||
.unreq height
|
||||
|
||||
width .req r3
|
||||
ldr width,[addr,#0]
|
||||
sub width,#1
|
||||
cmp px,width
|
||||
movhi pc,lr
|
||||
```
|
||||
|
||||
Remember that the width and height are stored at offsets of 0 and 4 into the frame buffer description respectively. You can refer back to 'frameBuffer.s' if necessary.
|
||||
|
||||
3.
|
||||
```
|
||||
ldr addr,[addr,#32]
|
||||
add width,#1
|
||||
mla px,py,width,px
|
||||
.unreq width
|
||||
.unreq py
|
||||
add addr, px,lsl #1
|
||||
.unreq px
|
||||
```
|
||||
|
||||
```
|
||||
mla dst,reg1,reg2,reg3 multiplies the values from reg1 and reg2, adds the value from reg3 and places the least significant 32 bits of the result in dst.
|
||||
```
|
||||
|
||||
Admittedly, this code is specific to high colour frame buffers, as I use a bit shift directly to compute this address. You may wish to code a version of this function without the specific requirement to use high colour frame buffers, remembering to update the SetForeColour code. It may be significantly more complicated to implement.
|
||||
|
||||
4.
|
||||
```
|
||||
fore .req r3
|
||||
ldr fore,=foreColour
|
||||
ldrh fore,[fore]
|
||||
```
|
||||
|
||||
As above, this is high colour specific.
|
||||
|
||||
5.
|
||||
```
|
||||
strh fore,[addr]
|
||||
.unreq fore
|
||||
.unreq addr
|
||||
mov pc,lr
|
||||
```
|
||||
|
||||
As above, this is high colour specific.
|
||||
|
||||
|
||||
|
||||
|
||||
### 2 Lines
|
||||
|
||||
The trouble is, line drawing isn't quite as simple as you may expect. By now you must realise that when making operating system, we have to do almost everything ourselves, and line drawing is no exception. I suggest for a few minutes you have a think about how you would draw a line between any two points.
|
||||
|
||||
```
|
||||
When programming normally, we tend to be lazy with things like division. Operating Systems must be incredibly efficient, and so we must focus on doing things as best as possible.
|
||||
```
|
||||
|
||||
I expect the central idea of most strategies will involve computing the gradient of the line, and stepping along it. This sounds perfectly reasonable, but is actually a terrible idea. The problem with it is it involves division, which is something that we know can't easily be done in assembly, and also keeping track of decimal numbers, which is again difficult. There is, in fact, an algorithm called Bresenham's Algorithm, which is perfect for assembly code because it only involves addition, subtraction and bit shifts.
|
||||
```
|
||||
Let's start off by defining a reasonably straightforward line drawing algorithm as follows:
|
||||
|
||||
if x1 > x0 then
|
||||
|
||||
set deltax to x1 - x0
|
||||
set stepx to +1
|
||||
|
||||
otherwise
|
||||
|
||||
set deltax to x0 - x1
|
||||
set stepx to -1
|
||||
|
||||
end if
|
||||
|
||||
if y1 > y0 then
|
||||
|
||||
set deltay to y1 - y0
|
||||
set stepy to +1
|
||||
|
||||
otherwise
|
||||
|
||||
set deltay to y0 - y1
|
||||
set stepy to -1
|
||||
|
||||
end if
|
||||
|
||||
if deltax > deltay then
|
||||
|
||||
set error to 0
|
||||
until x0 = x1 + stepx
|
||||
|
||||
setPixel(x0, y0)
|
||||
set error to error + deltax ÷ deltay
|
||||
if error ≥ 0.5 then
|
||||
|
||||
set y0 to y0 + stepy
|
||||
set error to error - 1
|
||||
|
||||
end if
|
||||
set x0 to x0 + stepx
|
||||
|
||||
repeat
|
||||
|
||||
otherwise
|
||||
|
||||
end if
|
||||
|
||||
This algorithm is a representation of the sort of thing you may have imagined. The variable error keeps track of how far away from the actual line we are. Every step we take along the x axis increases this error, and every time we move down the y axis, the error decreases by 1 unit again. The error is measured as a distance along the y axis.
|
||||
|
||||
While this algorithm works, it suffers a major problem in that we clearly have to use decimal numbers to store error, and also we have to do a division. An immediate optimisation would therefore be to change the units of error. There is no need to store it in any particular units, as long as we scale every use of it by the same amount. Therefore, we could rewrite the algorithm simply by multiplying all equations involving error by deltay, and simplifying the result. Just showing the main loop:
|
||||
|
||||
set error to 0 × deltay
|
||||
until x0 = x1 + stepx
|
||||
|
||||
setPixel(x0, y0)
|
||||
set error to error + deltax ÷ deltay × deltay
|
||||
if error ≥ 0.5 × deltay then
|
||||
|
||||
set y0 to y0 + stepy
|
||||
set error to error - 1 × deltay
|
||||
|
||||
end if
|
||||
set x0 to x0 + stepx
|
||||
|
||||
repeat
|
||||
|
||||
Which simplifies to:
|
||||
|
||||
set error to 0
|
||||
until x0 = x1 + stepx
|
||||
|
||||
setPixel(x0, y0)
|
||||
set error to error + deltax
|
||||
if error × 2 ≥ deltay then
|
||||
|
||||
set y0 to y0 + stepy
|
||||
set error to error - deltay
|
||||
|
||||
end if
|
||||
set x0 to x0 + stepx
|
||||
|
||||
repeat
|
||||
|
||||
Suddenly we have a much better algorithm. We see now that we've eliminated the need for division altogether. Better still, the only multiplication is by 2, which we know is just a bit shift left by 1! This is now very close to Bresenham's Algorithm, but one further optimisation can be made. At the moment, we have an if statement which leads to two very similar blocks of code, one for lines with larger x differences, and one for lines with larger y differences. It is worth checking if the code could be converted to a single statement for both types of line.
|
||||
|
||||
The difficulty arises somewhat in that in the first case, error is to do with y, and in the second case error is to do with x. The solution is to track the error in both variables simultaneously, using negative error to represent an error in x, and positive error in y.
|
||||
|
||||
set error to deltax - deltay
|
||||
until x0 = x1 + stepx or y0 = y1 + stepy
|
||||
|
||||
setPixel(x0, y0)
|
||||
if error × 2 > -deltay then
|
||||
|
||||
set x0 to x0 + stepx
|
||||
set error to error - deltay
|
||||
|
||||
end if
|
||||
if error × 2 < deltax then
|
||||
|
||||
set y0 to y0 + stepy
|
||||
set error to error + deltax
|
||||
|
||||
end if
|
||||
|
||||
repeat
|
||||
|
||||
It may take some time to convince yourself that this actually works. At each step, we consider if it would be correct to move in x or y. We do this by checking if the magnitude of the error would be lower if we moved in the x or y co-ordinates, and then moving if so.
|
||||
```
|
||||
|
||||
```
|
||||
Bresenham's Line Algorithm was developed in 1962 by Jack Elton Bresenham, 24 at the time, whilst studying for a PhD.
|
||||
```
|
||||
|
||||
Bresenham's Algorithm for drawing a line can be described by the following pseudo code. Pseudo code is just text which looks like computer instructions, but is actually intended for programmers to understand algorithms, rather than being machine readable.
|
||||
|
||||
```
|
||||
/* We wish to draw a line from (x0,y0) to (x1,y1), using only a function setPixel(x,y) which draws a dot in the pixel given by (x,y). */
|
||||
if x1 > x0 then
|
||||
set deltax to x1 - x0
|
||||
set stepx to +1
|
||||
otherwise
|
||||
set deltax to x0 - x1
|
||||
set stepx to -1
|
||||
end if
|
||||
|
||||
set error to deltax - deltay
|
||||
until x0 = x1 + stepx or y0 = y1 + stepy
|
||||
setPixel(x0, y0)
|
||||
if error × 2 ≥ -deltay then
|
||||
set x0 to x0 + stepx
|
||||
set error to error - deltay
|
||||
end if
|
||||
if error × 2 ≤ deltax then
|
||||
set y0 to y0 + stepy
|
||||
set error to error + deltax
|
||||
end if
|
||||
repeat
|
||||
```
|
||||
|
||||
Rather than numbered lists as I have used so far, this representation of an algorithm is far more common. See if you can implement this yourself. For reference, I have provided my implementation below.
|
||||
|
||||
```
|
||||
.globl DrawLine
|
||||
DrawLine:
|
||||
push {r4,r5,r6,r7,r8,r9,r10,r11,r12,lr}
|
||||
x0 .req r9
|
||||
x1 .req r10
|
||||
y0 .req r11
|
||||
y1 .req r12
|
||||
|
||||
mov x0,r0
|
||||
mov x1,r2
|
||||
mov y0,r1
|
||||
mov y1,r3
|
||||
|
||||
dx .req r4
|
||||
dyn .req r5 /* Note that we only ever use -deltay, so I store its negative for speed. (hence dyn) */
|
||||
sx .req r6
|
||||
sy .req r7
|
||||
err .req r8
|
||||
|
||||
cmp x0,x1
|
||||
subgt dx,x0,x1
|
||||
movgt sx,#-1
|
||||
suble dx,x1,x0
|
||||
movle sx,#1
|
||||
|
||||
cmp y0,y1
|
||||
subgt dyn,y1,y0
|
||||
movgt sy,#-1
|
||||
suble dyn,y0,y1
|
||||
movle sy,#1
|
||||
|
||||
add err,dx,dyn
|
||||
add x1,sx
|
||||
add y1,sy
|
||||
|
||||
pixelLoop$:
|
||||
|
||||
teq x0,x1
|
||||
teqne y0,y1
|
||||
popeq {r4,r5,r6,r7,r8,r9,r10,r11,r12,pc}
|
||||
|
||||
mov r0,x0
|
||||
mov r1,y0
|
||||
bl DrawPixel
|
||||
|
||||
cmp dyn, err,lsl #1
|
||||
addle err,dyn
|
||||
addle x0,sx
|
||||
|
||||
cmp dx, err,lsl #1
|
||||
addge err,dx
|
||||
addge y0,sy
|
||||
|
||||
b pixelLoop$
|
||||
|
||||
.unreq x0
|
||||
.unreq x1
|
||||
.unreq y0
|
||||
.unreq y1
|
||||
.unreq dx
|
||||
.unreq dyn
|
||||
.unreq sx
|
||||
.unreq sy
|
||||
.unreq err
|
||||
```
|
||||
|
||||
### 3 Randomness
|
||||
|
||||
So, now we can draw lines. Although we could use this to draw pictures and whatnot (feel free to do so!), I thought I would take the opportunity to introduce the idea of computer randomness. What we will do is select a pair of random co-ordinates, and then draw a line from the last pair to that point in steadily incrementing colours. I do this purely because it looks quite pretty.
|
||||
|
||||
```
|
||||
Hardware random number generators are occasionally used in security, where the predictability sequence of random numbers may affect the security of some encryption.
|
||||
```
|
||||
|
||||
So, now it comes down to it, how do we be random? Unfortunately for us there isn't some device which generates random numbers (such devices are very rare). So somehow using only the operations we've learned so far we need to invent 'random numbers'. It shouldn't take you long to realise this is impossible. The operations always have well defined results, executing the same sequence of instructions with the same registers yields the same answer. What we instead do is deduce a sequence that is pseudo random. This means numbers that, to the outside observer, look random, but in fact were completely determined. So, we need a formula to generate random numbers. One might be tempted to just spam mathematical operators out for example: 4x2! / 64, but in actuality this generally produces low quality random numbers. In this case for example, if x were 0, the answer would be 0. Stupid though it sounds, we need a very careful choice of equation to produce high quality random numbers.
|
||||
|
||||
```
|
||||
This sort of discussion often begs the question what do we mean by a random number? We generally mean statistical randomness: A sequence of numbers that has no obvious patterns or properties that could be used to generalise it.
|
||||
```
|
||||
|
||||
The method I'm going to teach you is called the quadratic congruence generator. This is a good choice because it can be implemented in 5 instructions, and yet generates a seemingly random order of the numbers from 0 to 232-1.
|
||||
|
||||
The reason why the generator can create such long sequence with so few instructions is unfortunately a little beyond the scope of this course, but I encourage the interested to research it. It all centralises on the following quadratic formula, where xn is the nth random number generated.
|
||||
|
||||
x_(n+1) = ax_(n)^2 + bx_(n) + c mod 2^32
|
||||
|
||||
Subject to the following constraints:
|
||||
|
||||
1. a is even
|
||||
|
||||
2. b = a + 1 mod 4
|
||||
|
||||
3. c is odd
|
||||
|
||||
|
||||
|
||||
|
||||
If you've not seen mod before, it means the remainder of a division by the number after it. For example b = a + 1 mod 4 means that b is the remainder of dividing a + 1 by 4, so if a were 12 say, b would be 1 as a + 1 is 13, and 13 divided by 4 is 3 remainder 1.
|
||||
|
||||
Copy the following code into a file called 'random.s'.
|
||||
|
||||
```
|
||||
.globl Random
|
||||
Random:
|
||||
xnm .req r0
|
||||
a .req r1
|
||||
|
||||
mov a,#0xef00
|
||||
mul a,xnm
|
||||
mul a,xnm
|
||||
add a,xnm
|
||||
.unreq xnm
|
||||
add r0,a,#73
|
||||
|
||||
.unreq a
|
||||
mov pc,lr
|
||||
```
|
||||
|
||||
This is an implementation of the random function, with an input of the last value generated in r0, and an output of the next number. In my case, I've used a = EF0016, b = 1, c = 73. This choice was arbitrary but meets the requirements above. Feel free to use any numbers you wish instead, as long as they obey the rules.
|
||||
|
||||
### 4 Pi-casso
|
||||
|
||||
OK, now we have all the functions we're going to need, let's try it out. Alter main to do the following, after getting the frame buffer info address:
|
||||
|
||||
1. Call SetGraphicsAddress with r0 containing the frame buffer info address.
|
||||
2. Set four registers to 0. One will be the last random number, one will be the colour, one will be the last x co-ordinate and one will be the last y co-ordinate.
|
||||
3. Call random to generate the next x-coordinate, using the last random number as the input.
|
||||
4. Call random again to generate the next y-coordinate, using the x-coordinate you generated as an input.
|
||||
5. Update the last random number to contain the y-coordinate.
|
||||
6. Call SetForeColour with the colour, then increment the colour. If it goes above FFFF16, make sure it goes back to 0.
|
||||
7. The x and y coordinates we have generated are between 0 and FFFFFFFF16. Convert them to a number between 0 and 102310 by using a logical shift right of 22.
|
||||
8. Check the y coordinate is on the screen. Valid y coordinates are between 0 and 76710. If not, go back to 3.
|
||||
9. Draw a line from the last x and y coordinates to the current x and y coordinates.
|
||||
10. Update the last x and y coordinates to contain the current ones.
|
||||
11. Go back to 3.
|
||||
|
||||
|
||||
|
||||
As always, a solution for this can be found on the downloads page.
|
||||
|
||||
Once you've finished, test it on the Raspberry Pi. You should see a very fast sequence of random lines being drawn on the screen, in steadily incrementing colours. This should never stop. If it doesn't work, please see our troubleshooting page.
|
||||
|
||||
When you have it working, congratulations! We've now learned about meaningful graphics, and also about random numbers. I encourage you to play with line drawing, as it can be used to render almost anything you want. You may also want to explore more complicated shapes. Most can be made out of lines, but is this necessarily the best strategy? If you like the line program, try experimenting with the SetPixel function. What happens if instead of just setting the value of the pixel, you increase it by a small amount? What other patterns can you make? In the next lesson, [Lesson 8: Screen 03][2], we will look at the invaluable skill of drawing text.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen02.html
|
||||
|
||||
作者:[Alex Chadwick][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.cl.cam.ac.uk
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen01.html
|
||||
[2]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen03.html
|
||||
@@ -0,0 +1,485 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Computer Laboratory – Raspberry Pi: Lesson 8 Screen03)
|
||||
[#]: via: (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen03.html)
|
||||
[#]: author: (Alex Chadwick https://www.cl.cam.ac.uk)
|
||||
|
||||
Computer Laboratory – Raspberry Pi: Lesson 8 Screen03
|
||||
======
|
||||
|
||||
The Screen03 lesson builds on Screen02, by teaching how to draw text, and also a small feature on the command line arguments of the operating system. It is assumed you have the code for the [Lesson 7: Screen02][1] operating system as a basis.
|
||||
|
||||
### 1 String Theory
|
||||
|
||||
So, our task for this operating system is to draw text. We have several problems to address, the most pressing of which is probably about storing text. Unbelievably text has been one of the biggest flaws on computers to date. What should have been a straightforward type of data has brought down operating systems, crippled otherwise wonderful encryption, and caused many problems for users of different alphabets. Nevertheless, it is an incredibly important type of data, as it is an excellent link between the computer and the user. Text can be sufficiently structured that the operating system understands it, as well as sufficiently readable that humans can use it.
|
||||
|
||||
```
|
||||
Variable data types such as text require much more complex handling.
|
||||
```
|
||||
|
||||
So how exactly is text stored? Simply enough, we have some system by which we give each letter a unique number, and then store a sequence of such numbers. Sounds easy. The problem is that the number of numbers is not fixed. Some pieces of text are longer than others. With storing ordinary numbers, we have some fixed limit, e.g. 32 bits, and then we can't go beyond that, we write methods that use numbers of that length, etc. In terms of text, or strings as we often call it, we want to write functions that work on variable length strings, otherwise we would need a lot of functions! This is not a problem for numbers normally, as there are only a few common number formats (byte, word, half, double).
|
||||
|
||||
```
|
||||
Buffer overrun attacks have plagued computers for years. Recently, the Wii, Xbox and Playstation 2 all suffered buffer overrun attacks, as well as large systems like Microsoft's Web and Database servers.
|
||||
```
|
||||
|
||||
So, how do we determine how long the string is? I think the obvious answer is just to store how long the string is, and then to store the characters that make it up. This is called length prefixing, as the length comes before the string. Unfortunately, the pioneers of computer science did not agree. They felt it made more sense to have a special character called the null terminator (denoted \0) which represents when a string ends. This does indeed simplify many string algorithms, as you just keep working until the null terminator. Unfortunately this is the source of many security issues. What if a malicious user gives you a very long string? What if you didn't have enough space to store it. You might run a string copying function that copies until the null terminator, but because the string is so long, it overwrites your program. This may sound far fetched, but nevertheless, such buffer overrun attacks are incredibly common. Length prefixing mitigates this problem as it is easy to deduce the size of the buffer required to store the string. As an operating system developer, I leave it to you to decide how best to store text.
|
||||
|
||||
The next thing we need to establish is how best to map characters to numbers. Fortunately, this is reasonably well standardised, so you have two major choices, Unicode and ASCII. Unicode maps almost every single useful symbol that can be written to a number, in exchange for having a lot more numbers, and a more complicated encoding system. ASCII uses one byte per character, and so only stores the Latin alphabet, numbers, a few symbols and a few special characters. Thus, ASCII is very easy to implement, compared to Unicode, in which not every character takes the same space, making string algorithms tricky. Normally operating systems use ASCII for strings which will not be displayed to end users (but perhaps to developers or experts), and Unicode for displaying messages to users, as Unicode can support things like Japanese characters, and so could be localised.
|
||||
|
||||
Fortunately for us, this decision is irrelevant at the moment, as the first 128 characters of both are exactly the same, and are encoded exactly the same.
|
||||
|
||||
Table 1.1 ASCII/Unicode symbols 0-127
|
||||
|
||||
| | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e | f | |
|
||||
|----| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ----|
|
||||
| 00 | NUL | SOH | STX | ETX | EOT | ENQ | ACK | BEL | BS | HT | LF | VT | FF | CR | SO | SI | |
|
||||
| 10 | DLE | DC1 | DC2 | DC3 | DC4 | NAK | SYN | ETB | CAN | EM | SUB | ESC | FS | GS | RS | US | |
|
||||
| 20 | ! | " | # | $ | % | & | . | ( | ) | * | + | , | - | . | / | | |
|
||||
| 30 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; | < | = | > | ? | |
|
||||
| 40 | @ | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | |
|
||||
| 50 | P | Q | R | S | T | U | V | W | X | Y | Z | [ | \ | ] | ^ | _ | |
|
||||
| 60 | ` | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | |
|
||||
| 70 | p | q | r | s | t | u | v | w | x | y | z | { | | | } | ~ | DEL |
|
||||
|
||||
The table shows the first 128 symbols. The hexadecimal representation of the number for a symbol is the row value added to the column value, for example A is 4116. What you may find surprising is the first two rows, and the very last value. These 33 special characters are not printed at all. In fact, these days, many are ignored. They exist because ASCII was originally intended as a system for transmitting data over computer networks, and so a lot more information than just the symbols had to be sent. The key special symbols that you should learn are NUL, the null terminator character I mentioned before, HT, horizontal tab is what we normally refer to as a tab and LF, the line feed character is used to make a new line. You may wish to research and use the other characters for special meanings in your operating system.
|
||||
|
||||
### 2 Characters
|
||||
|
||||
So, now that we know a bit about strings, we can start to think about how they're displayed. The fundamental thing we need to do in order to be able to display a string is to be able to display a character. Our first task will be making a DrawCharacter function which takes in a character to draw and a location, and then draws the character.
|
||||
|
||||
```
|
||||
The true type font format used in many Operating Systems is so powerful, it has its own assembly language built in to ensure letters look correct at any resolution.
|
||||
```
|
||||
|
||||
Naturally, this leads to a discussion about fonts. We already know there are many ways to display any given letter in accordance with font choice. So how does a font work? In the very early days of computer science, a font was just a series of little pictures of all the letters, called a bitmap font, and all the draw character method would do is copy one of the pictures to the screen. The trouble with this is when people want to resize the text. Sometimes we need big letters, and sometimes small. Although we could keep drawing new pictures for every font at every size with every character, this would get tedious. Thus, vector fonts were invented. in vector fonts, rather than containing an image of the font, the font file contains a description of how to draw it, e.g. an 'o' could be circle with radius half that of the maximum letter height. Modern operating systems use such fonts almost exclusively, as they are perfect at any resolution.
|
||||
|
||||
Unfortunately, much though I would love to include an implementation of one of the vector font formats, it would take up the remainder of this website. Thus, we will implement a bitmap font, though if you wish to make a decent graphical operating system, a vector font would be useful.
|
||||
```
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
00010000
|
||||
00101000
|
||||
00101000
|
||||
00101000
|
||||
01000100
|
||||
01000100
|
||||
01111100
|
||||
11000110
|
||||
10000010
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
```
|
||||
|
||||
On the downloads page, I have included several '.bin' files in the font section. These are just raw binary data files for a few fonts. For this tutorial, pick your favourite from the monospace, monochrome, 8x16 section. Download it and store it in the 'source' directory as 'font.bin'. These files are just monochrome images of each of the letters in turn, with each letter being exactly 8 by 16 pixels. Thus, each takes 16 bytes, the first byte being the top row, the second the next, etc.
|
||||
|
||||
The diagram shows the 'A' character in the monospace, monochrome, 8x16 font Bitstream Vera Sans Mono. In the file, we would find this starting at the 4116 × 1016 = 41016th byte as the following sequence in hexadecimal:
|
||||
|
||||
00, 00, 00, 10, 28, 28, 28, 44, 44, 7C, C6, 82, 00, 00, 00, 00
|
||||
|
||||
We're going to use a monospace font here, because in a monospace font every character is the same size. Unfortunately, yet another complication with most fonts is that the character's widths vary, leading to more complex display code. I've included a few other fonts on the downloads page, as well as an explanation of the format I've stored them all in.
|
||||
|
||||
So let's get down to business. Copy the following to 'drawing.s' after the .int 0 of graphicsAddress.
|
||||
|
||||
```
|
||||
.align 4
|
||||
font:
|
||||
.incbin "font.bin"
|
||||
```
|
||||
|
||||
```
|
||||
.incbin "file" inserts the binary data from the file file.
|
||||
```
|
||||
|
||||
This code copies the font data from the file to the address labelled font. We've used an .align 4 here to ensure each character starts on a multiple of 16 bytes, which can be used for a speed trick later.
|
||||
|
||||
Now we want to write the draw character method. I'll give the pseudo code for this, so you can try to implement it yourself if you want to. Conventionally >> means logical shift right.
|
||||
|
||||
```
|
||||
function drawCharacter(r0 is character, r1 is x, r2 is y)
|
||||
if character > 127 then exit
|
||||
set charAddress to font + character × 16
|
||||
for row = 0 to 15
|
||||
set bits to readByte(charAddress + row)
|
||||
for bit = 0 to 7
|
||||
if test(bits >> bit, 0x1)
|
||||
then setPixel(x + bit, y + row)
|
||||
next
|
||||
next
|
||||
return r0 = 8, r1 = 16
|
||||
end function
|
||||
|
||||
```
|
||||
If implemented directly, this is deliberately not very efficient. With things like drawing characters, efficiency is a top priority, as we will do it a lot. Let's explore some improvements that bring this closer to optimal assembly code. Firstly, we have a × 16, which by now you should spot is the same as a logical shift left by 4 places. Next we have a variable row, which is only ever added to charAddress and to y. Thus, we can eliminate it by increasing these variables instead. The only issue now is how to tell when we've finished. This is where the .align 4 comes in handy. We know that charAddress will start with the low nibble containing 0. This means we can see how far into the character data we are by checking that low nibble.
|
||||
|
||||
Though we can eliminate the need for bits, we must introduce a new variable to do so, so it is best left in. The only other improvement that can be made is to remove the nested bits >> bit.
|
||||
|
||||
```
|
||||
function drawCharacter(r0 is character, r1 is x, r2 is y)
|
||||
if character > 127 then exit
|
||||
set charAddress to font + character << 4
|
||||
loop
|
||||
set bits to readByte(charAddress)
|
||||
set bit to 8
|
||||
loop
|
||||
set bits to bits << 1
|
||||
set bit to bit - 1
|
||||
if test(bits, 0x100)
|
||||
then setPixel(x + bit, y)
|
||||
until bit = 0
|
||||
set y to y + 1
|
||||
set chadAddress to chadAddress + 1
|
||||
until charAddress AND 0b1111 = 0
|
||||
return r0 = 8, r1 = 16
|
||||
end function
|
||||
```
|
||||
|
||||
Now we've got code that is much closer to assembly code, and is near optimal. Below is the assembly code version of the above.
|
||||
|
||||
```
|
||||
.globl DrawCharacter
|
||||
DrawCharacter:
|
||||
cmp r0,#127
|
||||
movhi r0,#0
|
||||
movhi r1,#0
|
||||
movhi pc,lr
|
||||
|
||||
push {r4,r5,r6,r7,r8,lr}
|
||||
x .req r4
|
||||
y .req r5
|
||||
charAddr .req r6
|
||||
mov x,r1
|
||||
mov y,r2
|
||||
ldr charAddr,=font
|
||||
add charAddr, r0,lsl #4
|
||||
|
||||
lineLoop$:
|
||||
|
||||
bits .req r7
|
||||
bit .req r8
|
||||
ldrb bits,[charAddr]
|
||||
mov bit,#8
|
||||
|
||||
charPixelLoop$:
|
||||
|
||||
subs bit,#1
|
||||
blt charPixelLoopEnd$
|
||||
lsl bits,#1
|
||||
tst bits,#0x100
|
||||
beq charPixelLoop$
|
||||
|
||||
add r0,x,bit
|
||||
mov r1,y
|
||||
bl DrawPixel
|
||||
|
||||
teq bit,#0
|
||||
bne charPixelLoop$
|
||||
|
||||
charPixelLoopEnd$:
|
||||
.unreq bit
|
||||
.unreq bits
|
||||
add y,#1
|
||||
add charAddr,#1
|
||||
tst charAddr,#0b1111
|
||||
bne lineLoop$
|
||||
|
||||
.unreq x
|
||||
.unreq y
|
||||
.unreq charAddr
|
||||
|
||||
width .req r0
|
||||
height .req r1
|
||||
mov width,#8
|
||||
mov height,#16
|
||||
|
||||
pop {r4,r5,r6,r7,r8,pc}
|
||||
.unreq width
|
||||
.unreq height
|
||||
```
|
||||
|
||||
### 3 Strings
|
||||
|
||||
Now that we can draw characters, we can draw text. We need to make a method that, for a given string, draws each character in turn, at incrementing positions. To be nice, we shall also implement new lines and tabs. It's decision time as far as null terminators are concerned, and if you want to make your operating system use them, feel free by changing the code below. To avoid the issue, I will have the length of the string passed as an argument to the DrawString function, along with the address of the string, and the x and y coordinates.
|
||||
|
||||
```
|
||||
function drawString(r0 is string, r1 is length, r2 is x, r3 is y)
|
||||
set x0 to x
|
||||
for pos = 0 to length - 1
|
||||
set char to loadByte(string + pos)
|
||||
set (cwidth, cheight) to DrawCharacter(char, x, y)
|
||||
if char = '\n' then
|
||||
set x to x0
|
||||
set y to y + cheight
|
||||
otherwise if char = '\t' then
|
||||
set x1 to x
|
||||
until x1 > x0
|
||||
set x1 to x1 + 5 × cwidth
|
||||
loop
|
||||
set x to x1
|
||||
otherwise
|
||||
set x to x + cwidth
|
||||
end if
|
||||
next
|
||||
end function
|
||||
```
|
||||
|
||||
Once again, this function isn't that close to assembly code. Feel free to try to implement it either directly or by simplifying it. I will give the simplification and then the assembly code below.
|
||||
|
||||
Clearly the person who wrote this function wasn't being very efficient (me in case you were wondering). Once again we have a pos variable that just increments and is added to something else, which is completely unnecessary. We can remove it, and instead simultaneously decrement length until it is 0, saving the need for one register. The rest of the function is probably fine, except for that annoying multiplication by five. A key thing to do here would be to move the multiplication outside the loop; multiplication is slow even with bit shifts, and since we're always adding the same constant multiplied by 5, there is no need to recompute this. It can in fact be implemented in one operation using the argument shifting in assembly code, so I shall rephrase it like that.
|
||||
|
||||
```
|
||||
function drawString(r0 is string, r1 is length, r2 is x, r3 is y)
|
||||
set x0 to x
|
||||
until length = 0
|
||||
set length to length - 1
|
||||
set char to loadByte(string)
|
||||
set (cwidth, cheight) to DrawCharacter(char, x, y)
|
||||
if char = '\n' then
|
||||
set x to x0
|
||||
set y to y + cheight
|
||||
otherwise if char = '\t' then
|
||||
set x1 to x
|
||||
set cwidth to cwidth + cwidth << 2
|
||||
until x1 > x0
|
||||
set x1 to x1 + cwidth
|
||||
loop
|
||||
set x to x1
|
||||
otherwise
|
||||
set x to x + cwidth
|
||||
end if
|
||||
set string to string + 1
|
||||
loop
|
||||
end function
|
||||
```
|
||||
|
||||
In assembly code:
|
||||
|
||||
```
|
||||
.globl DrawString
|
||||
DrawString:
|
||||
x .req r4
|
||||
y .req r5
|
||||
x0 .req r6
|
||||
string .req r7
|
||||
length .req r8
|
||||
char .req r9
|
||||
push {r4,r5,r6,r7,r8,r9,lr}
|
||||
|
||||
mov string,r0
|
||||
mov x,r2
|
||||
mov x0,x
|
||||
mov y,r3
|
||||
mov length,r1
|
||||
|
||||
stringLoop$:
|
||||
subs length,#1
|
||||
blt stringLoopEnd$
|
||||
|
||||
ldrb char,[string]
|
||||
add string,#1
|
||||
|
||||
mov r0,char
|
||||
mov r1,x
|
||||
mov r2,y
|
||||
bl DrawCharacter
|
||||
cwidth .req r0
|
||||
cheight .req r1
|
||||
|
||||
teq char,#'\n'
|
||||
moveq x,x0
|
||||
addeq y,cheight
|
||||
beq stringLoop$
|
||||
|
||||
teq char,#'\t'
|
||||
addne x,cwidth
|
||||
bne stringLoop$
|
||||
|
||||
add cwidth, cwidth,lsl #2
|
||||
x1 .req r1
|
||||
mov x1,x0
|
||||
|
||||
stringLoopTab$:
|
||||
add x1,cwidth
|
||||
cmp x,x1
|
||||
bge stringLoopTab$
|
||||
mov x,x1
|
||||
.unreq x1
|
||||
b stringLoop$
|
||||
stringLoopEnd$:
|
||||
.unreq cwidth
|
||||
.unreq cheight
|
||||
|
||||
pop {r4,r5,r6,r7,r8,r9,pc}
|
||||
.unreq x
|
||||
.unreq y
|
||||
.unreq x0
|
||||
.unreq string
|
||||
.unreq length
|
||||
```
|
||||
|
||||
```
|
||||
subs reg,#val subtracts val from the register reg and compares the result with 0.
|
||||
```
|
||||
|
||||
This code makes clever use of a new operation, subs which subtracts one number from another, stores the result and then compares it with 0. In truth, all comparisons are implemented as a subtraction and then comparison with 0, but the result is normally discarded. This means that this operation is as fast as cmp.
|
||||
|
||||
### 4 Your Wish is My Command Line
|
||||
|
||||
Now that we can print strings, the challenge is to find an interesting one to draw. Normally in tutorials such as this, people just draw "Hello World!", but after all we've done so far, I feel that is a little patronising (feel free to do so if it helps). Instead we're going to draw our command line.
|
||||
|
||||
A convention has been made for computers running ARM. When they boot, it is important they are given certain information about what they have available to them. Most all processors have some way of ascertaining this information, and on ARM this is by data left at the address 10016. The format of the data is as follows:
|
||||
|
||||
1. The data is broken down into a series of 'tags'.
|
||||
2. There are nine types of tag: 'core', 'mem', 'videotext', 'ramdisk', 'initrd2', 'serial' 'revision', 'videolfb', 'cmdline'.
|
||||
3. Each can only appear once, but all but the 'core' tag don't have to appear.
|
||||
4. The tags are placed from 0x100 in order one after the other.
|
||||
5. The end of the list of tags always contains 2 words which are 0.
|
||||
6. Every tag's size in bytes is a multiple of 4.
|
||||
7. Each tag starts with the size of the tag in words in the tag, including this number.
|
||||
8. This is followed by a half word containing the tag's number. These are numbered from 1 in the order above ('core' is 1, 'cmdline' is 9).
|
||||
9. This is followed by a half word containing 544116.
|
||||
10. After this comes the data of the tag, which varies depending on the tag. The size of the data in words + 2 is always the same as the length mentioned above.
|
||||
11. A 'core' tag is either 2 or 5 words in length. If it is 2, there is no data, if it is 5, it has 3 words.
|
||||
12. A 'mem' tag is always 4 words in length. The data is the first address in a block of memory, and the length of that block.
|
||||
13. A 'cmdline' tag contains a null terminated string which is the parameters of the kernel.
|
||||
|
||||
|
||||
```
|
||||
Almost all Operating Systems support the notion of programs having a 'command line'. The idea is to provide a common mechanism for choosing the desired behaviour of the program.
|
||||
```
|
||||
|
||||
On the current version of the Raspberry Pi, only the 'core', 'mem' and 'cmdline' tags are present. You may find these useful later, and a more complete reference for these is on our Raspberry Pi reference page. The one we're interested in at the moment is the 'cmdline' tag, because it contains a string. We're going to write some code to search for the command line tag, and, if found, to print it out with each item on a new line. The command line is just a list of things that either the graphics processor or the user thought it might be nice for the Operating System to know. On the Raspberry Pi, this includes the MAC Address, serial number and screen resolution. The string itself is just a list of expressions such as 'key.subkey=value' separated by spaces.
|
||||
|
||||
Let's start by finding the 'cmdline' tag. In a new file called 'tags.s' copy the following code.
|
||||
|
||||
```
|
||||
.section .data
|
||||
tag_core: .int 0
|
||||
tag_mem: .int 0
|
||||
tag_videotext: .int 0
|
||||
tag_ramdisk: .int 0
|
||||
tag_initrd2: .int 0
|
||||
tag_serial: .int 0
|
||||
tag_revision: .int 0
|
||||
tag_videolfb: .int 0
|
||||
tag_cmdline: .int 0
|
||||
```
|
||||
|
||||
Looking through the list of tags will be a slow operation, as it involves a lot of memory access. Therefore, we only want to have to do it once. This code creates some data which will store the memory address of the first tag of each of the types. Then, to find a tag the following pseudo code will suffice.
|
||||
|
||||
```
|
||||
function FindTag(r0 is tag)
|
||||
if tag > 9 or tag = 0 then return 0
|
||||
set tagAddr to loadWord(tag_core + (tag - 1) × 4)
|
||||
if not tagAddr = 0 then return tagAddr
|
||||
if readWord(tag_core) = 0 then return 0
|
||||
set tagAddr to 0x100
|
||||
loop forever
|
||||
set tagIndex to readHalfWord(tagAddr + 4)
|
||||
if tagIndex = 0 then return FindTag(tag)
|
||||
if readWord(tag_core+(tagIndex-1)×4) = 0
|
||||
then storeWord(tagAddr, tag_core+(tagIndex-1)×4)
|
||||
set tagAddr to tagAddr + loadWord(tagAddr) × 4
|
||||
end loop
|
||||
end function
|
||||
```
|
||||
This code is already quite well optimised and close to assembly. It is optimistic in that the first thing it tries is loading the tag directly, as all but the first time this should be the case. If that fails, it checks if the core tag has an address. Since there must always be a core tag, the only reason that it would not have an address is if it doesn't exist. If it does have an address, the tag we were looking for didn't. If it doesn't we need to find the addresses of all the tags. It does this by reading the number of the tag. If it is zero, that must mean we are at the end of the list. This means we've now filled in all the tags in our directory. Therefore if we run our function again, it will now be able to produce an answer. If the tag number is not zero, we check to see if this tag type already has an address. If not, we store the address of this tag in our directory. We then add the length of this tag in bytes to the tag address to find the next tag.
|
||||
|
||||
Have a go at implementing this code in assembly. You will need to simplify it. If you get stuck, my answer is below. Don't forget the .section .text!
|
||||
|
||||
```
|
||||
.section .text
|
||||
.globl FindTag
|
||||
FindTag:
|
||||
tag .req r0
|
||||
tagList .req r1
|
||||
tagAddr .req r2
|
||||
|
||||
sub tag,#1
|
||||
cmp tag,#8
|
||||
movhi tag,#0
|
||||
movhi pc,lr
|
||||
|
||||
ldr tagList,=tag_core
|
||||
tagReturn$:
|
||||
add tagAddr,tagList, tag,lsl #2
|
||||
ldr tagAddr,[tagAddr]
|
||||
|
||||
teq tagAddr,#0
|
||||
movne r0,tagAddr
|
||||
movne pc,lr
|
||||
|
||||
ldr tagAddr,[tagList]
|
||||
teq tagAddr,#0
|
||||
movne r0,#0
|
||||
movne pc,lr
|
||||
|
||||
mov tagAddr,#0x100
|
||||
push {r4}
|
||||
tagIndex .req r3
|
||||
oldAddr .req r4
|
||||
tagLoop$:
|
||||
ldrh tagIndex,[tagAddr,#4]
|
||||
subs tagIndex,#1
|
||||
poplt {r4}
|
||||
blt tagReturn$
|
||||
|
||||
add tagIndex,tagList, tagIndex,lsl #2
|
||||
ldr oldAddr,[tagIndex]
|
||||
teq oldAddr,#0
|
||||
.unreq oldAddr
|
||||
streq tagAddr,[tagIndex]
|
||||
|
||||
ldr tagIndex,[tagAddr]
|
||||
add tagAddr, tagIndex,lsl #2
|
||||
b tagLoop$
|
||||
|
||||
.unreq tag
|
||||
.unreq tagList
|
||||
.unreq tagAddr
|
||||
.unreq tagIndex
|
||||
```
|
||||
|
||||
### 5 Hello World
|
||||
|
||||
Now that we have everything we need, we can draw our first string. In 'main.s' delete everything after bl SetGraphicsAddress, and replace it with the following:
|
||||
|
||||
```
|
||||
mov r0,#9
|
||||
bl FindTag
|
||||
ldr r1,[r0]
|
||||
lsl r1,#2
|
||||
sub r1,#8
|
||||
add r0,#8
|
||||
mov r2,#0
|
||||
mov r3,#0
|
||||
bl DrawString
|
||||
loop$:
|
||||
b loop$
|
||||
```
|
||||
|
||||
This code simply uses our FindTag method to find the 9th tag (cmdline) and then calculates its length and passes the command and the length to the DrawString method, and tells it to draw the string at 0,0. Now test this on the Raspberry Pi. You should see a line of text on the screen. If not please see our troubleshooting page.
|
||||
|
||||
Once it works, congratulations you've now got the ability to draw text. But there is still room for improvement. What if we wanted to write out a number, or a section of the memory or manipulate our command line? In [Lesson 9: Screen04][2], we will look at manipulating text and displaying useful numbers and information.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen03.html
|
||||
|
||||
作者:[Alex Chadwick][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.cl.cam.ac.uk
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen02.html
|
||||
[2]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen04.html
|
||||
@@ -0,0 +1,540 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Computer Laboratory – Raspberry Pi: Lesson 9 Screen04)
|
||||
[#]: via: (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen04.html)
|
||||
[#]: author: (Alex Chadwick https://www.cl.cam.ac.uk)
|
||||
|
||||
Computer Laboratory – Raspberry Pi: Lesson 9 Screen04
|
||||
======
|
||||
|
||||
The Screen04 lesson builds on Screen03, by teaching how to manipulate text. It is assumed you have the code for the [Lesson 8: Screen03][1] operating system as a basis.
|
||||
|
||||
### 1 String Manipulation
|
||||
|
||||
```
|
||||
Variadic functions look much less intuitive in assembly code. Nevertheless, they are useful and powerful concepts.
|
||||
```
|
||||
|
||||
Being able to draw text is lovely, but unfortunately at the moment you can only draw strings which are already prepared. This is fine for displaying something like the command line, but ideally we would like to be able to display and text we so desire. As per usual, if we put the effort in and make an excellent function that does all the string manipulation we could ever want, we get much easier code later on in return. Once such complicated function in C programming is sprintf. This function generates a string based on a description given as another string and additional arguments. What is interesting about this function is that it is variadic. This means that it takes a variable number of parameters. The number of parameters depends on the exact format string, and so cannot be determined in advance.
|
||||
|
||||
The full function has many options, and I list a few here. I've highlighted the ones which we will implement in this tutorial, though you can try to implement more.
|
||||
|
||||
The function works by reading the format string, and then interpreting it using the table below. Once an argument is used, it is not considered again. The return value of the function is the number of characters written. If the method fails, a negative number is returned.
|
||||
|
||||
Table 1.1 sprintf formatting rules
|
||||
| Sequence | Meaning |
|
||||
| ---------------------- | ---------------------- |
|
||||
| Any character except % | Copies the character to the output. |
|
||||
| %% | Writes a % character to the output. |
|
||||
| %c | Writes the next argument as a character. |
|
||||
| %d or %i | Writes the next argument as a base 10 signed integer. |
|
||||
| %e | Writes the next argument in scientific notation using eN to mean ×10N. |
|
||||
| %E | Writes the next argument in scientific notation using EN to mean ×10N. |
|
||||
| %f | Writes the next argument as a decimal IEEE 754 floating point number. |
|
||||
| %g | Same as the shorter of %e and %f. |
|
||||
| %G | Same as the shorter of %E and %f. |
|
||||
| %o | Writes the next argument as a base 8 unsigned integer. |
|
||||
| %s | Writes the next argument as if it were a pointer to a null terminated string. |
|
||||
| %u | Writes the next argument as a base 10 unsigned integer. |
|
||||
| %x | Writes the next argument as a base 16 unsigned integer, with lowercase a,b,c,d,e and f. |
|
||||
| %X | Writes the next argument as a base 16 unsigned integer, with uppercase A,B,C,D,E and F. |
|
||||
| %p | Writes the next argument as a pointer address. |
|
||||
| %n | Writes nothing. Copies instead the number of characters written so far to the location addressed by the next argument. |
|
||||
|
||||
Further to the above, many additional tweaks exist to the sequences, such as specifying minimum length, signs, etc. More information can be found at [sprintf - C++ Reference][2].
|
||||
|
||||
Here are a few examples of calls to the method and their results to illustrate its use.
|
||||
|
||||
Table 1.2 sprintf example calls
|
||||
| Format String | Arguments | Result |
|
||||
| "%d" | 13 | "13" |
|
||||
| "+%d degrees" | 12 | "+12 degrees" |
|
||||
| "+%x degrees" | 24 | "+1c degrees" |
|
||||
| "'%c' = 0%o" | 65, 65 | "'A' = 0101" |
|
||||
| "%d * %d%% = %d" | 200, 40, 80 | "200 * 40% = 80" |
|
||||
| "+%d degrees" | -5 | "+-5 degrees" |
|
||||
| "+%u degrees" | -5 | "+4294967291 degrees" |
|
||||
|
||||
Hopefully you can already begin to see the usefulness of the function. It does take a fair amount of work to program, but our reward is a very general function we can use for all sorts of purposes.
|
||||
|
||||
### 2 Division
|
||||
|
||||
```
|
||||
Division is the slowest and most complicated of the basic mathematical operators. It is not implemented directly in ARM assembly code because it takes so long to deduce the answer, and so isn't a 'simple' operation.
|
||||
```
|
||||
|
||||
While this function does look very powerful, it also looks very complicated. The easiest way to deal with its many cases is probably to write functions to deal with some common tasks it has. What would be useful would be a function to generate the string for a signed and an unsigned number in any base. So, how can we go about doing that? Try to devise an algorithm quickly before reading on.
|
||||
|
||||
The easiest way is probably the exact way I mentioned in [Lesson 1: OK01][3], which is the division remainder method. The idea is the following:
|
||||
|
||||
1. Divide the current value by the base you're working in.
|
||||
2. Store the remainder.
|
||||
3. If the new value is not 0, go to 1.
|
||||
4. Reverse the order of the remainders. This is the answer.
|
||||
|
||||
|
||||
|
||||
For example:
|
||||
|
||||
Table 2.1 Example base 2
|
||||
conversion
|
||||
| Value | New Value | Remainder |
|
||||
| ----- | --------- | --------- |
|
||||
| 137 | 68 | 1 |
|
||||
| 68 | 34 | 0 |
|
||||
| 34 | 17 | 0 |
|
||||
| 17 | 8 | 1 |
|
||||
| 8 | 4 | 0 |
|
||||
| 4 | 2 | 0 |
|
||||
| 2 | 1 | 0 |
|
||||
| 1 | 0 | 1 |
|
||||
|
||||
So the answer is 100010012
|
||||
|
||||
The unfortunate part about this procedure is that it unavoidably uses division. Therefore, we must first contemplate division in binary.
|
||||
|
||||
For a refresher on long division expand the box below.
|
||||
|
||||
```
|
||||
Let's suppose we wish to divide 4135 by 17.
|
||||
|
||||
0243 r 4
|
||||
17)4135
|
||||
0 0 × 17 = 0000
|
||||
4135 4135 - 0 = 4135
|
||||
34 200 × 17 = 3400
|
||||
735 4135 - 3400 = 735
|
||||
68 40 × 17 = 680
|
||||
55 735 - 680 = 55
|
||||
51 3 × 17 = 51
|
||||
4 55 - 51 = 4
|
||||
Answer: 243 remainder 4
|
||||
|
||||
First of all we would look at the top digit of the dividend. We see that the smallest multiple of the divisor which is less or equal to it is 0. We output a 0 to the result.
|
||||
|
||||
Next we look at the second to top digit of the dividend and all higher digits. We see the smallest multiple of the divisor which is less than or equal is 34. We output a 2 and subtract 3400.
|
||||
|
||||
Next we look at the third digit of the dividend and all higher digits. The smallest multiple of the divisor that is less than or equal to this is 68. We output 4 and subtract 680.
|
||||
|
||||
Finally we look at all remaining digits. We see that the lowest multiple of the divisor that is less than the remaining digits is 51. We output a 3, subtract 51. The result of the subtraction is our remainder.
|
||||
```
|
||||
|
||||
To implement division in assembly code, we will implement binary long division. We do this because the numbers are stored in binary, which gives us easy access to the all important bit shift operations, and because division in binary is simpler than in any higher base due to the much lower number of cases.
|
||||
|
||||
```
|
||||
1011 r 1
|
||||
1010)1101111
|
||||
1010
|
||||
11111
|
||||
1010
|
||||
1011
|
||||
1010
|
||||
1
|
||||
This example shows how binary long division works. You simply shift the divisor as far right as possible without exceeding the dividend, output a 1 according to the poisition and subtract the number. Whatever remains is the remainder. In this case we show 11011112 ÷ 10102 = 10112 remainder 12. In decimal, 111 ÷ 10 = 11 remainder 1.
|
||||
```
|
||||
|
||||
|
||||
Try to implement long division yourself now. You should write a function, DivideU32 which divides r0 by r1, returning the result in r0, and the remainder in r1. Below, we will go through a very efficient implementation.
|
||||
|
||||
```
|
||||
function DivideU32(r0 is dividend, r1 is divisor)
|
||||
set shift to 31
|
||||
set result to 0
|
||||
while shift ≥ 0
|
||||
if dividend ≥ (divisor << shift) then
|
||||
set dividend to dividend - (divisor << shift)
|
||||
set result to result + 1
|
||||
end if
|
||||
set result to result << 1
|
||||
set shift to shift - 1
|
||||
loop
|
||||
return (result, dividend)
|
||||
end function
|
||||
```
|
||||
|
||||
This code does achieve what we need, but would not work as assembly code. Our problem comes from the fact that our registers only hold 32 bits, and so the result of divisor << shift may not fit in a register (we call this overflow). This is a real problem. Did your solution have overflow?
|
||||
|
||||
Fortunately, an instruction exists called clz or count leading zeros, which counts the number of zeros in the binary representation of a number starting at the top bit. Conveniently, this is exactly the number of times we can shift the register left before overflow occurs. Another optimisation you may spot is that we compute divisor << shift twice each loop. We could improve upon this by shifting the divisor at the beginning, then shifting it down at the end of each loop to avoid any need to shift it elsewhere.
|
||||
|
||||
Let's have a look at the assembly code to make further improvements.
|
||||
|
||||
```
|
||||
.globl DivideU32
|
||||
DivideU32:
|
||||
result .req r0
|
||||
remainder .req r1
|
||||
shift .req r2
|
||||
current .req r3
|
||||
|
||||
clz shift,r1
|
||||
lsl current,r1,shift
|
||||
mov remainder,r0
|
||||
mov result,#0
|
||||
|
||||
divideU32Loop$:
|
||||
cmp shift,#0
|
||||
blt divideU32Return$
|
||||
cmp remainder,current
|
||||
|
||||
addge result,result,#1
|
||||
subge remainder,current
|
||||
sub shift,#1
|
||||
lsr current,#1
|
||||
lsl result,#1
|
||||
b divideU32Loop$
|
||||
divideU32Return$:
|
||||
.unreq current
|
||||
mov pc,lr
|
||||
|
||||
.unreq result
|
||||
.unreq remainder
|
||||
.unreq shift
|
||||
```
|
||||
|
||||
```
|
||||
clz dest,src stores the number of zeros from the top to the first one of register dest to register src
|
||||
```
|
||||
|
||||
You may, quite rightly, think that this looks quite efficient. It is pretty good, but division is a very expensive operation, and one we may wish to do quite often, so it would be good if we could improve the speed in any way. When looking to optimise code with a loop in it, it is always important to consider how many times the loop must run. In this case, the loop will run a maximum of 31 times for an input of 1. Without making special cases, this could often be improved easily. For example when dividing 1 by 1, no shift is required, yet we shift the divisor to each of the positions above it. This could be improved by simply using the new clz command on the dividend and subtracting this from the shift. In the case of 1 ÷ 1, this means shift would be set to 0, rightly indicating no shift is required. If this causes the shift to be negative, the divisor is bigger than the dividend and so we know the result is 0 remainder the dividend. Another quick check we could make is if the current value is ever 0, then we have a perfect division and can stop looping.
|
||||
|
||||
```
|
||||
.globl DivideU32
|
||||
DivideU32:
|
||||
result .req r0
|
||||
remainder .req r1
|
||||
shift .req r2
|
||||
current .req r3
|
||||
|
||||
clz shift,r1
|
||||
clz r3,r0
|
||||
subs shift,r3
|
||||
lsl current,r1,shift
|
||||
mov remainder,r0
|
||||
mov result,#0
|
||||
blt divideU32Return$
|
||||
|
||||
divideU32Loop$:
|
||||
cmp remainder,current
|
||||
blt divideU32LoopContinue$
|
||||
|
||||
add result,result,#1
|
||||
subs remainder,current
|
||||
lsleq result,shift
|
||||
beq divideU32Return$
|
||||
divideU32LoopContinue$:
|
||||
subs shift,#1
|
||||
lsrge current,#1
|
||||
lslge result,#1
|
||||
bge divideU32Loop$
|
||||
|
||||
divideU32Return$:
|
||||
.unreq current
|
||||
mov pc,lr
|
||||
|
||||
.unreq result
|
||||
.unreq remainder
|
||||
.unreq shift
|
||||
```
|
||||
|
||||
Copy the code above to a file called 'maths.s'.
|
||||
|
||||
### 3 Number Strings
|
||||
|
||||
Now that we can do division, let's have another look at implementing number to string conversion. The following is pseudo code to convert numbers from registers into strings in up to base 36. By convention, a % b means the remainder of dividing a by b.
|
||||
|
||||
```
|
||||
function SignedString(r0 is value, r1 is dest, r2 is base)
|
||||
if value ≥ 0
|
||||
then return UnsignedString(value, dest, base)
|
||||
otherwise
|
||||
if dest > 0 then
|
||||
setByte(dest, '-')
|
||||
set dest to dest + 1
|
||||
end if
|
||||
return UnsignedString(-value, dest, base) + 1
|
||||
end if
|
||||
end function
|
||||
|
||||
function UnsignedString(r0 is value, r1 is dest, r2 is base)
|
||||
set length to 0
|
||||
do
|
||||
|
||||
set (value, rem) to DivideU32(value, base)
|
||||
if rem > 10
|
||||
then set rem to rem + '0'
|
||||
otherwise set rem to rem - 10 + 'a'
|
||||
if dest > 0
|
||||
then setByte(dest + length, rem)
|
||||
set length to length + 1
|
||||
|
||||
while value > 0
|
||||
if dest > 0
|
||||
then ReverseString(dest, length)
|
||||
return length
|
||||
end function
|
||||
|
||||
function ReverseString(r0 is string, r1 is length)
|
||||
set end to string + length - 1
|
||||
while end > start
|
||||
set temp1 to readByte(start)
|
||||
set temp2 to readByte(end)
|
||||
setByte(start, temp2)
|
||||
setByte(end, temp1)
|
||||
set start to start + 1
|
||||
set end to end - 1
|
||||
end while
|
||||
end function
|
||||
```
|
||||
|
||||
In a file called 'text.s' implement the above. Remember that if you get stuck, a full solution can be found on the downloads page.
|
||||
|
||||
### 4 Format Strings
|
||||
|
||||
Let's get back to our string formatting method. Since we're programming our own operating system, we can add or change formatting rules as we please. We may find it useful to add a %b operation that outputs a number in binary, and if you're not using null terminated strings, you may wish to alter the behaviour of %s to take the length of the string from another argument, or from a length prefix if you wish. I will use a null terminator in the example below.
|
||||
|
||||
One of the main obstacles to implementing this function is that the number of arguments varies. According to the ABI, additional arguments are pushed onto the stack before calling the method in reverse order. So, for example, if we wish to call our method with 8 parameters; 1,2,3,4,5,6,7 and 8, we would do the following:
|
||||
|
||||
1. Set r0 = 5, r1 = 6, r2 = 7, r3 = 8
|
||||
2. Push {r0,r1,r2,r3}
|
||||
3. Set r0 = 1, r1 = 2, r2 = 3, r3 = 4
|
||||
4. Call the function
|
||||
5. Add sp,#4*4
|
||||
|
||||
|
||||
|
||||
Now we must decide what arguments our function actually needs. In my case, I used the format string address in r0, the length of the format string in r1, the destination string address in r2, followed by the list of arguments required, starting in r3 and continuing on the stack as above. If you wish to use a null terminated format string, the parameter in r1 can be removed. If you wish to have a maximum buffer length, you could store this in r3. As an additional modification, I think it is useful to alter the function so that if the destination string address is 0, no string is outputted, but an accurate length is still returned, so that the length of a formatted string can be accurately determined.
|
||||
|
||||
If you wish to attempt the implementation on your own, try it now. If not, I will first construct the pseudo code for the method, then give the assembly code implementation.
|
||||
|
||||
```
|
||||
function StringFormat(r0 is format, r1 is formatLength, r2 is dest, ...)
|
||||
set index to 0
|
||||
set length to 0
|
||||
while index < formatLength
|
||||
if readByte(format + index) = '%' then
|
||||
set index to index + 1
|
||||
if readByte(format + index) = '%' then
|
||||
if dest > 0
|
||||
then setByte(dest + length, '%')
|
||||
set length to length + 1
|
||||
otherwise if readByte(format + index) = 'c' then
|
||||
if dest > 0
|
||||
then setByte(dest + length, nextArg)
|
||||
set length to length + 1
|
||||
otherwise if readByte(format + index) = 'd' or 'i' then
|
||||
set length to length + SignedString(nextArg, dest, 10)
|
||||
otherwise if readByte(format + index) = 'o' then
|
||||
set length to length + UnsignedString(nextArg, dest, 8)
|
||||
otherwise if readByte(format + index) = 'u' then
|
||||
set length to length + UnsignedString(nextArg, dest, 10)
|
||||
otherwise if readByte(format + index) = 'b' then
|
||||
set length to length + UnsignedString(nextArg, dest, 2)
|
||||
otherwise if readByte(format + index) = 'x' then
|
||||
set length to length + UnsignedString(nextArg, dest, 16)
|
||||
otherwise if readByte(format + index) = 's' then
|
||||
set str to nextArg
|
||||
while getByte(str) != '\0'
|
||||
if dest > 0
|
||||
then setByte(dest + length, getByte(str))
|
||||
set length to length + 1
|
||||
set str to str + 1
|
||||
loop
|
||||
otherwise if readByte(format + index) = 'n' then
|
||||
setWord(nextArg, length)
|
||||
end if
|
||||
otherwise
|
||||
if dest > 0
|
||||
then setByte(dest + length, readByte(format + index))
|
||||
set length to length + 1
|
||||
end if
|
||||
set index to index + 1
|
||||
loop
|
||||
return length
|
||||
end function
|
||||
```
|
||||
|
||||
Although this function is massive, it is quite straightforward. Most of the code goes into checking all the various conditions, the code for each one is simple. Further, all the various unsigned integer cases are the same but for the base, and so can be summarised in assembly. This is given below.
|
||||
|
||||
```
|
||||
.globl FormatString
|
||||
FormatString:
|
||||
format .req r4
|
||||
formatLength .req r5
|
||||
dest .req r6
|
||||
nextArg .req r7
|
||||
argList .req r8
|
||||
length .req r9
|
||||
|
||||
push {r4,r5,r6,r7,r8,r9,lr}
|
||||
mov format,r0
|
||||
mov formatLength,r1
|
||||
mov dest,r2
|
||||
mov nextArg,r3
|
||||
add argList,sp,#7*4
|
||||
mov length,#0
|
||||
|
||||
formatLoop$:
|
||||
subs formatLength,#1
|
||||
movlt r0,length
|
||||
poplt {r4,r5,r6,r7,r8,r9,pc}
|
||||
|
||||
ldrb r0,[format]
|
||||
add format,#1
|
||||
teq r0,#'%'
|
||||
beq formatArg$
|
||||
|
||||
formatChar$:
|
||||
teq dest,#0
|
||||
strneb r0,[dest]
|
||||
addne dest,#1
|
||||
add length,#1
|
||||
b formatLoop$
|
||||
|
||||
formatArg$:
|
||||
subs formatLength,#1
|
||||
movlt r0,length
|
||||
poplt {r4,r5,r6,r7,r8,r9,pc}
|
||||
|
||||
ldrb r0,[format]
|
||||
add format,#1
|
||||
teq r0,#'%'
|
||||
beq formatChar$
|
||||
|
||||
teq r0,#'c'
|
||||
moveq r0,nextArg
|
||||
ldreq nextArg,[argList]
|
||||
addeq argList,#4
|
||||
beq formatChar$
|
||||
|
||||
teq r0,#'s'
|
||||
beq formatString$
|
||||
|
||||
teq r0,#'d'
|
||||
beq formatSigned$
|
||||
|
||||
teq r0,#'u'
|
||||
teqne r0,#'x'
|
||||
teqne r0,#'b'
|
||||
teqne r0,#'o'
|
||||
beq formatUnsigned$
|
||||
|
||||
b formatLoop$
|
||||
|
||||
formatString$:
|
||||
ldrb r0,[nextArg]
|
||||
teq r0,#0x0
|
||||
ldreq nextArg,[argList]
|
||||
addeq argList,#4
|
||||
beq formatLoop$
|
||||
add length,#1
|
||||
teq dest,#0
|
||||
strneb r0,[dest]
|
||||
addne dest,#1
|
||||
add nextArg,#1
|
||||
b formatString$
|
||||
|
||||
formatSigned$:
|
||||
mov r0,nextArg
|
||||
ldr nextArg,[argList]
|
||||
add argList,#4
|
||||
mov r1,dest
|
||||
mov r2,#10
|
||||
bl SignedString
|
||||
teq dest,#0
|
||||
addne dest,r0
|
||||
add length,r0
|
||||
b formatLoop$
|
||||
|
||||
formatUnsigned$:
|
||||
teq r0,#'u'
|
||||
moveq r2,#10
|
||||
teq r0,#'x'
|
||||
moveq r2,#16
|
||||
teq r0,#'b'
|
||||
moveq r2,#2
|
||||
teq r0,#'o'
|
||||
moveq r2,#8
|
||||
|
||||
mov r0,nextArg
|
||||
ldr nextArg,[argList]
|
||||
add argList,#4
|
||||
mov r1,dest
|
||||
bl UnsignedString
|
||||
teq dest,#0
|
||||
addne dest,r0
|
||||
add length,r0
|
||||
b formatLoop$
|
||||
```
|
||||
|
||||
### 5 Convert OS
|
||||
|
||||
Feel free to try using this method however you wish. As an example, here is the code to generate a conversion chart from base 10 to binary to hexadecimal to octal and to ASCII.
|
||||
|
||||
Delete all code after bl SetGraphicsAddress in 'main.s' and replace it with the following:
|
||||
|
||||
```
|
||||
mov r4,#0
|
||||
loop$:
|
||||
ldr r0,=format
|
||||
mov r1,#formatEnd-format
|
||||
ldr r2,=formatEnd
|
||||
lsr r3,r4,#4
|
||||
push {r3}
|
||||
push {r3}
|
||||
push {r3}
|
||||
push {r3}
|
||||
bl FormatString
|
||||
add sp,#16
|
||||
|
||||
mov r1,r0
|
||||
ldr r0,=formatEnd
|
||||
mov r2,#0
|
||||
mov r3,r4
|
||||
|
||||
cmp r3,#768-16
|
||||
subhi r3,#768
|
||||
addhi r2,#256
|
||||
cmp r3,#768-16
|
||||
subhi r3,#768
|
||||
addhi r2,#256
|
||||
cmp r3,#768-16
|
||||
subhi r3,#768
|
||||
addhi r2,#256
|
||||
|
||||
bl DrawString
|
||||
|
||||
add r4,#16
|
||||
b loop$
|
||||
|
||||
.section .data
|
||||
format:
|
||||
.ascii "%d=0b%b=0x%x=0%o='%c'"
|
||||
formatEnd:
|
||||
```
|
||||
|
||||
Can you work out what will happen before testing? Particularly what happens for r3 ≥ 128? Try it on the Raspberry Pi to see if you're right. If it doesn't work, please see our troubleshooting page.
|
||||
|
||||
When it does work, congratulations, you've completed the Screen04 tutorial, and reached the end of the screen series! We've learned about pixels and frame buffers, and how these apply to the Raspberry Pi. We've learned how to draw simple lines, and also how to draw characters, as well as the invaluable skill of formatting numbers into text. We now have all that you would need to make graphical output on an Operating System. Can you make some more drawing methods? What about 3D graphics? Can you implement a 24bit frame buffer? What about reading the size of the framebuffer in from the command line?
|
||||
|
||||
The next series is the [Input][4] series, which teaches how to use the keyboard and mouse to really get towards a traditional console computer.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen04.html
|
||||
|
||||
作者:[Alex Chadwick][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.cl.cam.ac.uk
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen03.html
|
||||
[2]: http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/
|
||||
[3]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok01.html
|
||||
[4]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/input01.html
|
||||
143
sources/tech/20150717 The History of Hello World.md
Normal file
143
sources/tech/20150717 The History of Hello World.md
Normal file
@@ -0,0 +1,143 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (The History of Hello World)
|
||||
[#]: via: (https://www.thesoftwareguild.com/blog/the-history-of-hello-world/)
|
||||
[#]: author: (thussong https://www.thesoftwareguild.com/blog/author/thussong/)
|
||||
|
||||
The History of Hello World
|
||||
======
|
||||
|
||||
|
||||
Veteran software developers know the [Hello World][2] program as the first step in learning to code. The program, which outputs some variant of “Hello, World!” on a device’s display, can be created in most languages, making it some of the most basic syntax involved in the coding process. In fact, a recent project at the Association for Computing Machinery (ACM) at Louisiana Tech [found][3] that there are at least 204 versions of the program.
|
||||
|
||||
Traditionally, Hello World programs are used to illustrate how the process of coding works, as well as to ensure that a language or system is operating correctly. They are usually the first programs that new coders learn, because even those with little or no experience can execute Hello World both easily and correctly.
|
||||
|
||||
Above all, Hello World is simple. That’s why it is so often used as a barometer of program success. If Hello World does not work effectively within the framework, then it is likely that other, more complex programs will also fail. As one expert at [Win-Vector][4] puts it, Hello World is actually a confrontational program. “The author is saying ‘it isn’t obvious your computer system will work, so I am not going to invest a lot of time in it until I see it can at least print one line of text,’” Win-Vector blogger John Mount says.
|
||||
|
||||
But this two-word phrase has big implications for the field of computer science. With Hello World as a foundation, novice programmers can easily understand computer science principles or elements. And professionals with years of coding experience can use it to learn how a given programming language works, especially in terms of structure and syntax. With applications at all skill levels and in almost every language, there is a long history behind such a short program.
|
||||
|
||||
### Uses
|
||||
|
||||
The main use for Hello World programs was outlined above: It is a way for rookie coders to become acquainted with a new language. However, the applications of these programs go beyond an introduction to the coding world. Hello World can, for example, be used as a sanity test to make sure that the components of a language (its compiler, development and run-time environment) have been correctly installed. Because the process involved in configuring a complete programming toolchain is lengthy and complex, a simple program like Hello World is often used as a first-run test on a new toolchain.
|
||||
|
||||
Hackers also use Hello World “as proof of concept that arbitrary code can be executed through an exploit where the system designers did not intend code to be executed,” according to programming consultants at Cunningham & Cunningham (C2). In fact, it’s the first step in using homemade content, or “home brew” on a device. When [experienced coders][5] are configuring an environment or learning a previously unknown one, they verify that Hello World behaves correctly.
|
||||
|
||||
It is also used as part of the debugging process, allowing programmers to check that they are editing the right aspect of a modifiable program at runtime and that it is being reloaded.
|
||||
|
||||
One more popular use for Hello World is as a basis for comparison. Coders can “compare the size of the executable that the language generates, and how much supporting infrastructure must exist behind the program for it to execute,” according to C2’s wiki.
|
||||
|
||||
### Beginnings
|
||||
|
||||
Though the origins of Hello World remain somewhat unclear, its use as a test phrase is widely believed to have begun with Brian Kernigham’s 1972 book, A Tutorial Introduction to the Language B. In this text, the first known version of the program was used to illustrate external variables. Because the previous example in the tutorial printed “hi!” on the terminal, the more complex “hello, world!” required more character constants for expression and was the next step in the learning process.
|
||||
|
||||
From there, it was used in a Bell Laboratories memo in 1974, as well as The C Programming Language in 1978. This popular text is what made Hello World famous. The example from that book (the first, and most pure, example) printed “hello, world,” with no capital letters or exclamation point. At this time, Hello World was used almost solely to illustrate a few functions of a language— not to test whether the system was running.
|
||||
|
||||
Before Kernigham’s seminal texts on B and C, there was no standard first program. Even as late as 1972, it was not widely in use. The popular BASIC tutorial, “My Computer Likes Me, When I Speak in Basic,” starts with a simple program that writes a line of text. However, this message was “MY HUMAN UNDERSTANDS ME,” far from the two-word greeting programmers use today. But once Hello World was invented, it spread quickly, becoming well-known by the late 1970s. Its popularity continues to this day.
|
||||
|
||||
### One Statement, Many Languages
|
||||
|
||||
Here’s what the code for Hello World looks like in some of the most popular programming languages currently in use.
|
||||
|
||||
#### Java
|
||||
|
||||
```
|
||||
class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, world!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### C#
|
||||
|
||||
```
|
||||
using System;
|
||||
class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, world!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Python
|
||||
|
||||
```
|
||||
print("Hello, world!")
|
||||
```
|
||||
|
||||
#### Ruby
|
||||
|
||||
```
|
||||
puts "Hello, world!"
|
||||
```
|
||||
|
||||
#### Scala
|
||||
|
||||
```
|
||||
object HelloWorld extends App {
|
||||
println("Hello, world!")
|
||||
}
|
||||
```
|
||||
|
||||
#### ASP.NET
|
||||
|
||||
`Response.Write("Hello World!");`
|
||||
|
||||
#### Lisp
|
||||
|
||||
```
|
||||
(princ "Hello, world!")
|
||||
```
|
||||
|
||||
#### Haskell
|
||||
|
||||
```
|
||||
main = putStrLn "Hello, world!"
|
||||
```
|
||||
|
||||
#### Malbolge
|
||||
|
||||
```
|
||||
('&%:9]!~}|z2Vxwv-,POqponl$Hjig%eB@@>}=<M:9wv6WsU2T|nm-,jcL(I&%$#"
|
||||
`CB]V?Tx<uVtT`Rpo3NlF.Jh++FdbCBA@?]!~|4XzyTT43Qsqq(Lnmkj"Fhg${z@>
|
||||
```
|
||||
|
||||
#### Go
|
||||
|
||||
```
|
||||
package main
|
||||
import "fmt"
|
||||
func main() {
|
||||
fmt.Println("Hello, world!")
|
||||
}
|
||||
```
|
||||
|
||||
### Hello World Today: A Standard Practice in Varied Forms
|
||||
|
||||
In modern coding languages, Hello World is deployed at different levels of sophistication. For example, the Go language introduced a multilingual Hello World program, and XL features a spinning, 3D version complete with graphics. Some languages, like Ruby and Python, need only a single statement to print “hello world,” but a low-level assembly language could require several commands to do so. Modern languages also introduce variations in punctuation and casing. These include the presence or absence of the comma and exclamation point, as well as the capitalization of both words. For example, when systems only support capital letters, the phrase appears as “HELLO WORLD.” The first nontrivial Malbolge program printed “HEllO WORld.” Variations go beyond the literal as well. In functional languages like Lisp and Haskell, factorial programs are substituted for Hello World to emphasize recursive techniques. This is different from the original examples, which emphasized I/O and produced side effects.
|
||||
|
||||
With the increasing complexity of modern coding languages, Hello World is more important than ever. Both as a test and a teaching tool, it has become a standardized way of allowing programmers to configure their environment. No one can be sure why Hello World has stood the test of time in an industry known for rapid-fire innovation, but it is here to stay.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.thesoftwareguild.com/blog/the-history-of-hello-world/
|
||||
|
||||
作者:[thussong][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.thesoftwareguild.com/blog/author/thussong/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.thesoftwareguild.com%2Fblog%2Fthe-history-of-hello-world%2F&title=The%20History%20of%20Hello%20World
|
||||
[2]: http://en.wikipedia.org/wiki/%22Hello,_World!%22_program
|
||||
[3]: http://whatis.techtarget.com/definition/Hello-World
|
||||
[4]: http://www.win-vector.com/blog/2008/02/hello-world-an-instance-rhetoric-in-computer-science/
|
||||
[5]: http://c2.com/cgi/wiki?HelloWorld
|
||||
@@ -1,259 +0,0 @@
|
||||
tmux – A Powerful Terminal Multiplexer For Heavy Command-Line Linux User
|
||||
======
|
||||
tmux stands for terminal multiplexer, it allows users to create/enable multiple terminals (vertical & horizontal) in single window, this can be accessed and controlled easily from single window when you are working with different issues.
|
||||
|
||||
It uses a client-server model, which allows you to share sessions between users, also you can attach terminals to a tmux session back. We can easily move or rearrange the virtual console as per the need. Terminal sessions can freely rebound from one virtual console to another.
|
||||
|
||||
tmux depends on libevent and ncurses libraries. tmux offers status-line at the bottom of the screen which display information about your current tmux session suc[]h as current window number, window name, username, hostname, current time, and current date.
|
||||
|
||||
When tmux is started it creates a new session with a single window and displays it on screen. It allows users to create Any number of windows in the same session.
|
||||
|
||||
Many of us says it's similar to screen but i'm not since this offers wide range of configuration options.
|
||||
|
||||
**Make a note:** `Ctrl+b` is the default prefix in tmux so, to perform any action in tumx, you have to type the prefix first then required options.
|
||||
|
||||
**Suggested Read :** [List Of Terminal Emulator For Linux][1]
|
||||
|
||||
### tmux Features
|
||||
|
||||
* Create any number of windows
|
||||
* Create any number of panes in the single window
|
||||
* It allows vertical and horizontal splits
|
||||
* Detach and Re-attach window
|
||||
* Server-client architecture which allows users to share sessions between users
|
||||
* tmux offers wide range of configuration hacks
|
||||
|
||||
|
||||
|
||||
**Suggested Read :**
|
||||
**(#)** [tmate - Instantly Share Your Terminal Session To Anyone In Seconds][2]
|
||||
**(#)** [Teleconsole - A Tool To Share Your Terminal Session Instantly To Anyone In Seconds][3]
|
||||
|
||||
### How to Install tmux Command
|
||||
|
||||
tmux command is pre-installed by default in most of the Linux systems. If no, follow the below procedure to get installed.
|
||||
|
||||
For **`Debian/Ubuntu`** , use [APT-GET Command][4] or [APT Command][5] to install tmux.
|
||||
```
|
||||
$ sudo apt install tmux
|
||||
|
||||
```
|
||||
|
||||
For **`RHEL/CentOS`** , use [YUM Command][6] to install tmux.
|
||||
```
|
||||
$ sudo yum install tmux
|
||||
|
||||
```
|
||||
|
||||
For **`Fedora`** , use [DNF Command][7] to install tmux.
|
||||
```
|
||||
$ sudo dnf install tmux
|
||||
|
||||
```
|
||||
|
||||
For **`Arch Linux`** , use [Pacman Command][8] to install tmux.
|
||||
```
|
||||
$ sudo pacman -S tmux
|
||||
|
||||
```
|
||||
|
||||
For **`openSUSE`** , use [Zypper Command][9] to install tmux.
|
||||
```
|
||||
$ sudo zypper in tmux
|
||||
|
||||
```
|
||||
|
||||
### How to Use tmux
|
||||
|
||||
kick start the tmux session by running following command on terminal. When tmux is started it creates a new session with a single window and will automatically login to your default shell with your user account.
|
||||
```
|
||||
$ tmux
|
||||
|
||||
```
|
||||
|
||||
[![][10]![][10]][11]
|
||||
|
||||
You will get similar to above screenshot like us. tmux comes with status bar which display an information's about current sessions details, date, time, etc.,.
|
||||
|
||||
The status bar information's are below:
|
||||
|
||||
* **`0 :`** It is indicating the session number which was created by the tmux server. By default it starts with 0.
|
||||
* **`0:username@host: :`** 0 is indicating the session number. Username and Hostname which is holding the current window.
|
||||
* **`~ :`** It is indicating the current directory (We are in the Home directory)
|
||||
* **`* :`** This indicate that the window is active now.
|
||||
* **`Hostname :`** This shows fully qualified hostname of the server
|
||||
* **`Date& Time:`** It shows current date and time
|
||||
|
||||
|
||||
|
||||
### How to Split Window
|
||||
|
||||
tmux allows users to split window vertically and horizontally. Let 's see how to do that.
|
||||
|
||||
Press `**(Ctrl+b), %**` to split the pane vertically.
|
||||
[![][10]![][10]][13]
|
||||
|
||||
Press `**(Ctrl+b), "**` to split the pane horizontally.
|
||||
[![][10]![][10]][14]
|
||||
|
||||
### How to Move Between Panes
|
||||
|
||||
Lets say, we have created few panes and want to move between them. How to do that? If you don 't know how to do, then there is no purpose to use tmux. Use the following control keys to perform the actions. There are many ways to move between panes.
|
||||
|
||||
Press `(Ctrl+b), Left arrow` - To Move Left
|
||||
|
||||
Press `(Ctrl+b), Right arrow` - To Move Right
|
||||
|
||||
Press `(Ctrl+b), Up arrow` - To Move Up
|
||||
|
||||
Press `(Ctrl+b), Down arrow` - To Move Down
|
||||
|
||||
Press `(Ctrl+b), {` - To Move Left
|
||||
|
||||
Press `(Ctrl+b), }` - To Move Right
|
||||
|
||||
Press `(Ctrl+b), o` - Switch to next pane (left-to-right, top-down)
|
||||
|
||||
Press `(Ctrl+b), ;` - Move to the previously active pane.
|
||||
|
||||
For testing purpose, we are going to move between panes. Now, we are in the `pane2` which shows `lsb_release -a` command output.
|
||||
[![][10]![][10]][15]
|
||||
|
||||
And we are going to move to `pane0` which shows `uname -a` command output.
|
||||
[![][10]![][10]][16]
|
||||
|
||||
### How to Open/Create New Window
|
||||
|
||||
You can open any number of windows within one terminal. Terminal window can be split vertically & horizontally which is called `panes`. Each pane will contain its own, independently running terminal instance.
|
||||
|
||||
Press `(Ctrl+b), c` to create a new window.
|
||||
|
||||
Press `(Ctrl+b), n` move to the next window.
|
||||
|
||||
Press `(Ctrl+b), p` to move to the previous window.
|
||||
|
||||
Press `(Ctrl+b), (0-9)` to immediately move to a specific window.
|
||||
|
||||
Press `(Ctrl+b), l` Move to the previously selected window.
|
||||
|
||||
I have two windows, first window has three panes which contains operating system distribution information, top command output & kernal information.
|
||||
[![][10]![][10]][17]
|
||||
|
||||
And second window has two panes which contains Linux distributions logo information. Use the following commands perform the action.
|
||||
[![][10]![][10]][18]
|
||||
|
||||
Press `(Ctrl+b), w` Choose the current window interactively.
|
||||
[![][10]![][10]][19]
|
||||
|
||||
### How to Zoom Panes
|
||||
|
||||
You are working in some pane which is very small and you want to zoom it out for further work. To do use the following key binds.
|
||||
|
||||
Currently we have three panes and i'm working in `pane1` which shows system activity using **Top** command and am going to zoom that.
|
||||
[![][10]![][10]][17]
|
||||
|
||||
When you zoom a pane, it will hide all other panes and display only the zoomed pane in the window.
|
||||
[![][10]![][10]][20]
|
||||
|
||||
Press `(Ctrl+b), z` to zoom the pane and press it again, to bring the zoomed pane back.
|
||||
|
||||
### Display Pane Information
|
||||
|
||||
To know about pane number and it's size, run the following command.
|
||||
|
||||
Press `(Ctrl+b), q` to briefly display pane indexes.
|
||||
[![][10]![][10]][21]
|
||||
|
||||
### Display Window Information
|
||||
|
||||
To know about window number, layout size, number of panes associated with the window and it's size, etc., run the following command.
|
||||
|
||||
Just run `tmux list-windows` to view window information.
|
||||
[![][10]![][10]][22]
|
||||
|
||||
### How to Resize Panes
|
||||
|
||||
You may want to resize the panes to fit your requirement. You have to press `(Ctrl+b), :` then type the following details on the `yellow` color bar in the bottom of the page.
|
||||
[![][10]![][10]][23]
|
||||
|
||||
In the previous section we have print pane index which shows panes size as well. To test this we are going to increase `10 cells UPward`. See the following output that has increased the pane1 & pane2 size from `55x21` to `55x31`.
|
||||
[![][10]![][10]][24]
|
||||
|
||||
**Syntax:** `(Ctrl+b), :` then type `resize-pane [options] [cells size]`
|
||||
|
||||
`(Ctrl+b), :` then type `resize-pane -D 10` to resize the current pane Down for 10 cells.
|
||||
|
||||
`(Ctrl+b), :` then type `resize-pane -U 10` to resize the current pane UPward for 10 cells.
|
||||
|
||||
`(Ctrl+b), :` then type `resize-pane -L 10` to resize the current pane Left for 10 cells.
|
||||
|
||||
`(Ctrl+b), :` then type `resize-pane -R 10` to resize the current pane Right for 10 cells.
|
||||
|
||||
### Detaching and Re-attaching tmux Session
|
||||
|
||||
One of the most powerful features of tmux is the ability to detach and reattach session whenever you need.
|
||||
|
||||
Run a long running process and press `Ctrl+b` followed by `d` to detach your tmux session safely by leaving the running process.
|
||||
|
||||
**Suggested Read :** [How To Keep A Process/Command Running After Disconnecting SSH Session][25]
|
||||
|
||||
Now, run a long running process. For demonstration purpose, we are going to move this server backup to another remote server for disaster recovery (DR) purpose.
|
||||
|
||||
You will get similar output like below after detached tmux session.
|
||||
```
|
||||
[detached (from session 0)]
|
||||
|
||||
```
|
||||
|
||||
Run the following command to list the available tmux sessions.
|
||||
```
|
||||
$ tmux ls
|
||||
0: 3 windows (created Tue Jan 30 06:17:47 2018) [109x45]
|
||||
|
||||
```
|
||||
|
||||
Now, re-attach the tmux session using an appropriate session ID as follow.
|
||||
```
|
||||
$ tmux attach -t 0
|
||||
|
||||
```
|
||||
|
||||
### How to Close Panes & Window
|
||||
|
||||
Just type `exit` or hit `Ctrl-d` in the corresponding pane to close it. It's similar to terminal close. To close window, press `(Ctrl+b), &`.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/tmux-a-powerful-terminal-multiplexer-emulator-for-linux/
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.2daygeek.com/author/magesh/
|
||||
[1]:https://www.2daygeek.com/category/terminal-emulator/
|
||||
[2]:https://www.2daygeek.com/tmate-instantly-share-your-terminal-session-to-anyone-in-seconds/
|
||||
[3]:https://www.2daygeek.com/teleconsole-share-terminal-session-instantly-to-anyone-in-seconds/
|
||||
[4]:https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[5]:https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[6]:https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[7]:https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/
|
||||
[8]:https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/
|
||||
[9]:https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[10]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[11]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-1.png
|
||||
[13]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-2.png
|
||||
[14]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-3.png
|
||||
[15]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-4.png
|
||||
[16]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-5.png
|
||||
[17]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-8.png
|
||||
[18]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-6.png
|
||||
[19]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-7.png
|
||||
[20]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-9.png
|
||||
[21]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-10.png
|
||||
[22]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-14.png
|
||||
[23]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-11.png
|
||||
[24]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-13.png
|
||||
[25]:https://www.2daygeek.com/how-to-keep-a-process-command-running-after-disconnecting-ssh-session/
|
||||
@@ -1,171 +0,0 @@
|
||||
How To Setup Static File Server Instantly
|
||||
======
|
||||
|
||||

|
||||
Ever wanted to share your files or project over network, but don’t know how to do? No worries! Here is a simple utility named **“serve”** to share your files instantly over network. This simple utility will instantly turn your system into a static file server, allowing you to serve your files over network. You can access the files from any devices regardless of their operating system. All you need is a web browser. This utility also can be used to serve static websites. It is formerly known as “list” and “micro-list”, but now the name has been changed to “serve”, which is much more suitable for the purpose of this utility.
|
||||
|
||||
### Setup Static File Server Using Serve
|
||||
|
||||
To install “serve”, you need to install NodeJS and NPM first. Refer the following link to install NodeJS and NPM in your Linux box.
|
||||
|
||||
Once NodeJS and NPM installed, run the following command to install “serve”.
|
||||
```
|
||||
$ npm install -g serve
|
||||
|
||||
```
|
||||
|
||||
Done! Now is the time to serve the files or folders.
|
||||
|
||||
The typical syntax to use “serve” is:
|
||||
```
|
||||
$ serve [options] <path-to-files-or-folders>
|
||||
|
||||
```
|
||||
|
||||
### Serve Specific files or folders
|
||||
|
||||
For example, let us share the contents of the **Documents** directory. To do so, run:
|
||||
```
|
||||
$ serve Documents/
|
||||
|
||||
```
|
||||
|
||||
Sample output would be:
|
||||
|
||||
![][2]
|
||||
|
||||
As you can see in the above screenshot, the contents of the given directory have been served over network via two URLs.
|
||||
|
||||
To access the contents from the local system itself, all you have to do is open your web browser and navigate to **<http://localhost:5000/>** URL.
|
||||
|
||||
![][3]
|
||||
|
||||
The Serve utility displays the contents of the given directory in a simple layout. You can download (right click on the files and choose “Save link as..”) or just view them in the browser.
|
||||
|
||||
If you want to open local address automatically in the browser, use **-o** flag.
|
||||
```
|
||||
$ serve -o Documents/
|
||||
|
||||
```
|
||||
|
||||
Once you run the above command, The Serve utility will open your web browser automatically and display the contents of the shared item.
|
||||
|
||||
Similarly, to access the shared directory from a remote system over network, type **<http://192.168.43.192:5000>** in the browser’s address bar. Replace 192.168.43.192 with your system’s IP.
|
||||
|
||||
**Serve contents via different port**
|
||||
|
||||
As you may noticed, The serve utility uses port **5000** by default. So, make sure the port 5000 is allowed in your firewall or router. If it is blocked for some reason, you can serve the contents using different port using **-p** flag.
|
||||
```
|
||||
$ serve -p 1234 Documents/
|
||||
|
||||
```
|
||||
|
||||
The above command will serve the contents of Documents directory via port **1234**.
|
||||
|
||||
![][4]
|
||||
|
||||
To serve a file, instead of a folder, just give it’s full path like below.
|
||||
```
|
||||
$ serve Documents/Papers/notes.txt
|
||||
|
||||
```
|
||||
|
||||
The contents of the shared directory can be accessed by any user on the network as long as they know the path.
|
||||
|
||||
**Serve the entire $HOME directory**
|
||||
|
||||
Open your Terminal and type:
|
||||
```
|
||||
$ serve
|
||||
|
||||
```
|
||||
|
||||
This will share the contents of your entire $HOME directory over network.
|
||||
|
||||
To stop the sharing, press **CTRL+C**.
|
||||
|
||||
**Serve selective files or folders**
|
||||
|
||||
You may not want to share all files or directories, but only a few in a directory. You can do this by excluding the files or directories using **-i** flag.
|
||||
```
|
||||
$ serve -i Downloads/
|
||||
|
||||
```
|
||||
|
||||
The above command will serve entire file system except **Downloads** directory.
|
||||
|
||||
**Serve contents only on localhost**
|
||||
|
||||
Sometimes, you want to serve the contents only on the local system itself, not on the entire network. To do so, use **-l** flag as shown below:
|
||||
```
|
||||
$ serve -l Documents/
|
||||
|
||||
```
|
||||
|
||||
This command will serve the **Documents** directory only on localhost.
|
||||
|
||||
![][5]
|
||||
|
||||
This can be useful when you’re working on a shared server. All users in the in the system can access the share, but not the remote users.
|
||||
|
||||
**Serve content using SSL**
|
||||
|
||||
Since we serve the contents over the local network, we need not to use SSL. However, Serve utility has the ability to shares contents using SSL using **–ssl** flag.
|
||||
```
|
||||
$ serve --ssl Documents/
|
||||
|
||||
```
|
||||
|
||||
![][6]
|
||||
|
||||
To access the shares via web browser use “<https://localhost:5000”> or “<https://ip:5000”>.
|
||||
|
||||
![][7]
|
||||
|
||||
**Serve contents with authentication**
|
||||
|
||||
In all above examples, we served the contents without any authentication. So anyone on the network can access them without any authentication. You might feel some contents should be accessed with username and password.
|
||||
|
||||
To do so, use:
|
||||
```
|
||||
$ SERVE_USER=ostechnix SERVE_PASSWORD=123456 serve --auth
|
||||
|
||||
```
|
||||
|
||||
Now the users need to enter the username (i.e **ostechnix** in our case) and password (123456) to access the shares.
|
||||
|
||||
![][8]
|
||||
|
||||
The Serve utility has some other features, such as disable [**Gzip compression**][9], setup * CORS headers to allow requests from any origin, prevent copy address automatically to clipboard etc. You can read the complete help section by running the following command:
|
||||
```
|
||||
$ serve help
|
||||
|
||||
```
|
||||
|
||||
And, that’s all for now. Hope this helps. More good stuffs to come. Stay tuned!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-setup-static-file-server-instantly/
|
||||
|
||||
作者:[SK][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.ostechnix.com/author/sk/
|
||||
[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[2]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-1.png
|
||||
[3]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-2.png
|
||||
[4]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-4.png
|
||||
[5]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-3.png
|
||||
[6]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-6.png
|
||||
[7]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-5-1.png
|
||||
[8]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-7-1.png
|
||||
[9]:https://www.ostechnix.com/how-to-compress-and-decompress-files-in-linux/
|
||||
@@ -1,68 +0,0 @@
|
||||
translated by lixinyuxx
|
||||
The life cycle of a software bug
|
||||
======
|
||||
|
||||

|
||||
|
||||
In 1947, the first computer bug was found—a moth trapped in a computer relay.
|
||||
|
||||
If only all bugs were as simple to uncover. As software has become more complex, so too has the process of testing and debugging. Today, the life cycle of a software bug can be lengthy—though the right technology and business processes can help. For open source software, developers use rigorous ticketing services and collaboration to find and mitigate bugs.
|
||||
|
||||
### Confirming a computer bug
|
||||
|
||||
During the process of testing, bugs are reported to the development team. Quality assurance testers describe the bug in as much detail as possible, reporting on their system state, the processes they were undertaking, and how the bug manifested itself.
|
||||
|
||||
Despite this, some bugs are never confirmed; they may be reported in testing but can never be reproduced in a controlled environment. In such cases they may not be resolved but are instead closed.
|
||||
|
||||
It can be difficult to confirm a computer bug due to the wide array of platforms in use and the many different types of user behavior. Some bugs only occur intermittently or under very specific situations, and others may occur seemingly at random.
|
||||
|
||||
Many people use and interact with open source software, and many bugs and issues may be non-repeatable or may not be adequately described. Still, because every user and developer also plays the role of quality assurance tester, at least in part, there is a good chance that bugs will be revealed.
|
||||
|
||||
When a bug is confirmed, work begins.
|
||||
|
||||
### Assigning a bug to be fixed
|
||||
|
||||
A confirmed bug is assigned to a developer or a development team to be addressed. At this stage, the bug needs to be reproduced, the issue uncovered, and the associated code fixed. Developers may categorize this bug as an issue to be fixed later if the bug is low-priority, or they may assign someone directly if it is high-priority. Either way, a ticket is opened during the process of development, and the bug becomes a known issue.
|
||||
|
||||
In open source solutions, developers may select from the bugs that they want to tackle, either choosing the areas of the program with which they are most familiar or working from the top priorities. Consolidated solutions such as [GitHub][1] make it easy for multiple developers to work on solutions without interfering with each other's work.
|
||||
|
||||
When assigning bugs to be fixed, reporters may also select a priority level for the bug. Major bugs may have a high priority level, whereas bugs related to appearance only, for example, may have a lower level. This priority level determines how and when the development team is assigned to resolve these issues. Either way, all bugs need to be resolved before a product can be considered complete. Using proper traceability back to prioritized requirements can also be helpful in this regard.
|
||||
|
||||
### Resolving the bug
|
||||
|
||||
Once a bug has been fixed, it is usually be sent back to Quality Assurance as a resolved bug. Quality Assurance then puts the product through its paces again to reproduce the bug. If the bug cannot be reproduced, Quality Assurance will assume that it has been properly resolved.
|
||||
|
||||
In open source situations, any changes are distributed—often as a tentative release that is being tested. This test release is distributed to users, who again fulfill the role of Quality Assurance and test the product.
|
||||
|
||||
If the bug occurs again, the issue is sent back to the development team. At this stage, the bug is reopened, and it is up to the development team to repeat the cycle of resolving the bug. This may occur multiple times, especially if the bug is unpredictable or intermittent. Intermittent bugs are notoriously difficult to resolve.
|
||||
|
||||
If the bug does not occur again, the issue will be marked as resolved. In some cases, the initial bug is resolved, but other bugs emerge as a result of the changes made. When this happens, new bug reports may need to be initiated, starting the process over again.
|
||||
|
||||
### Closing the bug
|
||||
|
||||
After a bug has been addressed, identified, and resolved, the bug is closed and developers can move on to other areas of software development and testing. A bug will also be closed if it was never found or if developers were never able to reproduce it—either way, the next stage of development and testing will begin.
|
||||
|
||||
Any changes made to the solution in the testing version will be rolled into the next release of the product. If the bug was a serious one, a patch or a hotfix may be provided for current users until the release of the next version. This is common for security issues.
|
||||
|
||||
Software bugs can be difficult to find, but by following set processes and procedures, developers can make the process faster, easier, and more consistent. Quality Assurance is an important part of this process, as QA testers must find and identify bugs and help developers reproduce them. Bugs cannot be closed and resolved until the error no longer occurs.
|
||||
|
||||
Open source solutions distribute the burden of quality assurance testing, development, and mitigation, which often leads to bugs being discovered and mitigated more quickly and comprehensively. However, because of the nature of open source technology, the speed and accuracy of this process often depends upon the popularity of the solution and the dedication of its maintenance and development team.
|
||||
|
||||
_Rich Butkevic is a PMP certified project manager, certified scum master, and runs[Project Zendo][2] , a website for project management professionals to discover strategies to simplify and improve their project results. Connect with Rich at [Richbutkevic.com][3] or on [LinkedIn][4]._
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/6/life-cycle-software-bug
|
||||
|
||||
作者:[Rich Butkevic][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/rich-butkevic
|
||||
[1]:https://github.com/
|
||||
[2]:https://projectzendo.com
|
||||
[3]:https://richbutkevic.com
|
||||
[4]:https://www.linkedin.com/in/richbutkevic
|
||||
@@ -1,5 +1,3 @@
|
||||
ScarboroughCoral translating!
|
||||
|
||||
How to use Fedora Server to create a router / gateway
|
||||
======
|
||||
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
Perform robust unit tests with PyHamcrest
|
||||
======
|
||||
|
||||

|
||||
|
||||
At the base of the [testing pyramid][1] are unit tests. Unit tests test one unit of code at a time—usually one function or method.
|
||||
|
||||
Often, a single unit test is designed to test one particular flow through a function, or a specific branch choice. This enables easy mapping of a unit test that fails and the bug that made it fail.
|
||||
|
||||
Ideally, unit tests use few or no external resources, isolating them and making them faster.
|
||||
|
||||
_Good_ tests increase developer productivity by catching bugs early and making testing faster. _Bad_ tests decrease developer productivity.
|
||||
|
||||
Unit test suites help maintain high-quality products by signaling problems early in the development process. An effective unit test catches bugs before the code has left the developer machine, or at least in a continuous integration environment on a dedicated branch. This marks the difference between good and bad unit tests:tests increase developer productivity by catching bugs early and making testing faster.tests decrease developer productivity.
|
||||
|
||||
Productivity usually decreases when testing _incidental features_. The test fails when the code changes, even if it is still correct. This happens because the output is different, but in a way that is not part of the function's contract.
|
||||
|
||||
A good unit test, therefore, is one that helps enforce the contract to which the function is committed.
|
||||
|
||||
If a unit test breaks, the contract is violated and should be either explicitly amended (by changing the documentation and tests), or fixed (by fixing the code and leaving the tests as is).
|
||||
|
||||
While limiting tests to enforce only the public contract is a complicated skill to learn, there are tools that can help.
|
||||
|
||||
One of these tools is [Hamcrest][2], a framework for writing assertions. Originally invented for Java-based unit tests, today the Hamcrest framework supports several languages, including [Python][3].
|
||||
|
||||
Hamcrest is designed to make test assertions easier to write and more precise.
|
||||
```
|
||||
def add(a, b):
|
||||
|
||||
return a + b
|
||||
|
||||
|
||||
|
||||
from hamcrest import assert_that, equal_to
|
||||
|
||||
|
||||
|
||||
def test_add():
|
||||
|
||||
assert_that(add(2, 2), equal_to(4))
|
||||
|
||||
```
|
||||
|
||||
This is a simple assertion, for simple functionality. What if we wanted to assert something more complicated?
|
||||
```
|
||||
def test_set_removal():
|
||||
|
||||
my_set = {1, 2, 3, 4}
|
||||
|
||||
my_set.remove(3)
|
||||
|
||||
assert_that(my_set, contains_inanyorder([1, 2, 4]))
|
||||
|
||||
assert_that(my_set, is_not(has_item(3)))
|
||||
|
||||
```
|
||||
|
||||
Note that we can succinctly assert that the result has `1`, `2`, and `4` in any order since sets do not guarantee order.
|
||||
|
||||
We also easily negate assertions with `is_not`. This helps us write _precise assertions_ , which allow us to limit ourselves to enforcing public contracts of functions.
|
||||
|
||||
Sometimes, however, none of the built-in functionality is _precisely_ what we need. In those cases, Hamcrest allows us to write our own matchers.
|
||||
|
||||
Imagine the following function:
|
||||
```
|
||||
def scale_one(a, b):
|
||||
|
||||
scale = random.randint(0, 5)
|
||||
|
||||
pick = random.choice([a,b])
|
||||
|
||||
return scale * pick
|
||||
|
||||
```
|
||||
|
||||
We can confidently assert that the result divides into at least one of the inputs evenly.
|
||||
|
||||
A matcher inherits from `hamcrest.core.base_matcher.BaseMatcher`, and overrides two methods:
|
||||
```
|
||||
class DivisibleBy(hamcrest.core.base_matcher.BaseMatcher):
|
||||
|
||||
|
||||
|
||||
def __init__(self, factor):
|
||||
|
||||
self.factor = factor
|
||||
|
||||
|
||||
|
||||
def _matches(self, item):
|
||||
|
||||
return (item % self.factor) == 0
|
||||
|
||||
|
||||
|
||||
def describe_to(self, description):
|
||||
|
||||
description.append_text('number divisible by')
|
||||
|
||||
description.append_text(repr(self.factor))
|
||||
|
||||
```
|
||||
|
||||
Writing high-quality `describe_to` methods is important, since this is part of the message that will show up if the test fails.
|
||||
```
|
||||
def divisible_by(num):
|
||||
|
||||
return DivisibleBy(num)
|
||||
|
||||
```
|
||||
|
||||
By convention, we wrap matchers in a function. Sometimes this gives us a chance to further process the inputs, but in this case, no further processing is needed.
|
||||
```
|
||||
def test_scale():
|
||||
|
||||
result = scale_one(3, 7)
|
||||
|
||||
assert_that(result,
|
||||
|
||||
any_of(divisible_by(3),
|
||||
|
||||
divisible_by(7)))
|
||||
|
||||
```
|
||||
|
||||
Note that we combined our `divisible_by` matcher with the built-in `any_of` matcher to ensure that we test only what the contract commits to.
|
||||
|
||||
While editing this article, I heard a rumor that the name "Hamcrest" was chosen as an anagram for "matches". Hrm...
|
||||
```
|
||||
>>> assert_that("matches", contains_inanyorder(*"hamcrest")
|
||||
|
||||
Traceback (most recent call last):
|
||||
|
||||
File "<stdin>", line 1, in <module>
|
||||
|
||||
File "/home/moshez/src/devops-python/build/devops/lib/python3.6/site-packages/hamcrest/core/assert_that.py", line 43, in assert_that
|
||||
|
||||
_assert_match(actual=arg1, matcher=arg2, reason=arg3)
|
||||
|
||||
File "/home/moshez/src/devops-python/build/devops/lib/python3.6/site-packages/hamcrest/core/assert_that.py", line 57, in _assert_match
|
||||
|
||||
raise AssertionError(description)
|
||||
|
||||
AssertionError:
|
||||
|
||||
Expected: a sequence over ['h', 'a', 'm', 'c', 'r', 'e', 's', 't'] in any order
|
||||
|
||||
but: no item matches: 'r' in ['m', 'a', 't', 'c', 'h', 'e', 's']
|
||||
|
||||
```
|
||||
|
||||
Researching more, I found the source of the rumor: It is an anagram for "matchers".
|
||||
```
|
||||
>>> assert_that("matchers", contains_inanyorder(*"hamcrest"))
|
||||
|
||||
>>>
|
||||
|
||||
```
|
||||
|
||||
If you are not yet writing unit tests for your Python code, now is a good time to start. If you are writing unit tests for your Python code, using Hamcrest will allow you to make your assertion _precise_ —neither more nor less than what you intend to test. This will lead to fewer false positives when modifying code and less time spent modifying tests for working code.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/8/robust-unit-tests-hamcrest
|
||||
|
||||
作者:[Moshe Zadka][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/moshez
|
||||
[1]:https://martinfowler.com/bliki/TestPyramid.html
|
||||
[2]:http://hamcrest.org/
|
||||
[3]:https://www.python.org/
|
||||
@@ -1,112 +0,0 @@
|
||||
Scoutydren is translating.
|
||||
5 open source strategy and simulation games for Linux
|
||||
======
|
||||
|
||||

|
||||
|
||||
Gaming has traditionally been one of Linux's weak points. That has changed somewhat in recent years thanks to Steam, GOG, and other efforts to bring commercial games to multiple operating systems, but those games are often not open source. Sure, the games can be played on an open source operating system, but that is not good enough for an open source purist.
|
||||
|
||||
So, can someone who only uses free and open source software find games that are polished enough to present a solid gaming experience without compromising their open source ideals? Absolutely. While open source games are unlikely ever to rival some of the AAA commercial games developed with massive budgets, there are plenty of open source games, in many genres, that are fun to play and can be installed from the repositories of most major Linux distributions. Even if a particular game is not packaged for a particular distribution, it is usually easy to download the game from the project's website to install and play it.
|
||||
|
||||
This article looks at strategy and simulation games. I have already written about [arcade-style games][1], [board & card games][2], [puzzle games][3], [racing & flying games][4], and [role-playing games][5].
|
||||
|
||||
### Freeciv
|
||||
|
||||

|
||||
|
||||
[Freeciv][6] is an open source version of the [Civilization series][7] of computer games. Gameplay is most similar to the earlier games in the Civilization series, and Freeciv even has options to use Civilization 1 and Civilization 2 rule sets. Freeciv involves building cities, exploring the world map, developing technologies, and competing with other civilizations trying to do the same. Victory conditions include defeating all the other civilizations, developing a space colony, or hitting deadline if neither of the first two conditions are met. The game can be played against AI opponents or other human players. Different tile-sets are available to change the look of the game's map.
|
||||
|
||||
To install Freeciv, run the following command:
|
||||
|
||||
* On Fedora: `dnf install freeciv`
|
||||
* On Debian/Ubuntu: `apt install freeciv`
|
||||
|
||||
|
||||
|
||||
### MegaGlest
|
||||
|
||||

|
||||
|
||||
[MegaGlest][8] is an open source real-time strategy game in the style of Blizzard Entertainment's [Warcraft][9] and [StarCraft][10] games. Players control one of several different factions, building structures and recruiting units to explore the map and battle their opponents. At the beginning of the match, a player can build only the most basic buildings and recruit the weakest units. To build and recruit better things, players must work their way up their factions technology tree by building structures and recruiting units that unlock more advanced options. Combat units will attack when enemy units come into range, but for optimal strategy, it is best to manage the battle directly by controlling the units. Simultaneously managing the construction of new structures, recruiting new units, and managing battles can be a challenge, but that is the point of a real-time strategy game. MegaGlest provides a nice variety of factions, so there are plenty of reasons to try new and different strategies.
|
||||
|
||||
To install MegaGlest, run the following command:
|
||||
|
||||
* On Fedora: `dnf install megaglest`
|
||||
* On Debian/Ubuntu: `apt install megaglest`
|
||||
|
||||
|
||||
|
||||
### OpenTTD
|
||||
|
||||

|
||||
|
||||
[OpenTTD][11] (see also [our review][12]) is an open source implementation of [Transport Tycoon Deluxe][13]. The object of the game is to create a transportation network and earn money, which allows the player to build an even bigger transportation network. The network can include boats, buses, trains, trucks, and planes. By default, gameplay takes place between 1950 and 2050, with players aiming to get the highest performance rating possible before time runs out. The performance rating is based on things like the amount of cargo delivered, the number of vehicles they have, and how much money they earned.
|
||||
|
||||
To install OpenTTD, run the following command:
|
||||
|
||||
* On Fedora: `dnf install openttd`
|
||||
* On Debian/Ubuntu: `apt install openttd`
|
||||
|
||||
|
||||
|
||||
### The Battle for Wesnoth
|
||||
|
||||

|
||||
|
||||
[The Battle for Wesnoth][14] is one of the most polished open source games available. This turn-based strategy game has a fantasy setting. Play takes place on a hexagonal grid, where individual units battle each other for control. Each type of unit has unique strengths and weaknesses, which requires players to plan their attacks accordingly. There are many different campaigns available for The Battle for Wesnoth, each with different objectives and storylines. The Battle for Wesnoth also comes with a map editor for players interested in creating their own maps or campaigns.
|
||||
|
||||
To install The Battle for Wesnoth, run the following command:
|
||||
|
||||
* On Fedora: `dnf install wesnoth`
|
||||
* On Debian/Ubuntu: `apt install wesnoth`
|
||||
|
||||
|
||||
|
||||
### UFO: Alien Invasion
|
||||
|
||||

|
||||
|
||||
[UFO: Alien Invasion][15] is an open source tactical strategy game inspired by the [X-COM series][20]. There are two distinct gameplay modes: geoscape and tactical. In geoscape mode, the player takes control of the big picture and deals with managing their bases, researching new technologies, and controlling overall strategy. In tactical mode, the player controls a squad of soldiers and directly confronts the alien invaders in a turn-based battle. Both modes provide different gameplay styles, but both require complex strategy and tactics.
|
||||
|
||||
To install UFO: Alien Invasion, run the following command:
|
||||
|
||||
* On Debian/Ubuntu: `apt install ufoai`
|
||||
|
||||
|
||||
|
||||
Unfortunately, UFO: Alien Invasion is not packaged for Fedora.
|
||||
|
||||
Did I miss one of your favorite open source strategy or simulation games? Share it in the comments below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/8/strategy-simulation-games-linux
|
||||
|
||||
作者:[Joshua Allen Holm][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/holmja
|
||||
[1]:https://opensource.com/article/18/1/arcade-games-linux
|
||||
[2]:https://opensource.com/article/18/3/card-board-games-linux
|
||||
[3]:https://opensource.com/article/18/6/puzzle-games-linux
|
||||
[4]:https://opensource.com/article/18/7/racing-flying-games-linux
|
||||
[5]:https://opensource.com/article/18/8/role-playing-games-linux
|
||||
[6]:http://www.freeciv.org/
|
||||
[7]:https://en.wikipedia.org/wiki/Civilization_(series)
|
||||
[8]:https://megaglest.org/
|
||||
[9]:https://en.wikipedia.org/wiki/Warcraft
|
||||
[10]:https://en.wikipedia.org/wiki/StarCraft
|
||||
[11]:https://www.openttd.org/
|
||||
[12]:https://opensource.com/life/15/7/linux-game-review-openttd
|
||||
[13]:https://en.wikipedia.org/wiki/Transport_Tycoon#Transport_Tycoon_Deluxe
|
||||
[14]:https://www.wesnoth.org/
|
||||
[15]:https://ufoai.org/
|
||||
[16]:https://opensource.com/downloads/cheat-sheets?intcmp=7016000000127cYAAQ
|
||||
[17]:https://opensource.com/alternatives?intcmp=7016000000127cYAAQ
|
||||
[18]:https://opensource.com/tags/linux?intcmp=7016000000127cYAAQ
|
||||
[19]:https://developers.redhat.com/cheat-sheets/advanced-linux-commands/?intcmp=7016000000127cYAAQ
|
||||
[20]:https://en.wikipedia.org/wiki/X-COM
|
||||
@@ -1,128 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( Auk7F7)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: subject: (Arch-Audit : A Tool To Check Vulnerable Packages In Arch Linux)
|
||||
[#]: via: (https://www.2daygeek.com/arch-audit-a-tool-to-check-vulnerable-packages-in-arch-linux/)
|
||||
[#]: author: (Prakash Subramanian https://www.2daygeek.com/author/prakash/)
|
||||
[#]: url: ( )
|
||||
|
||||
|
||||
Arch-Audit : A Tool To Check Vulnerable Packages In Arch Linux
|
||||
======
|
||||
|
||||
We have to make the system up-to date to minimize the downtime and issues.
|
||||
|
||||
It’s one of the routine task for Linux administrator to patch the system once in a month or 60 days once or 90 days at maximum.
|
||||
|
||||
It would be sufficient schedule and we can’t do it this less than a month as it’s involve multiple activities and environments.
|
||||
|
||||
Basically infrastructure comes with Test, Development, QA a.k.a Staging & Prod environments.
|
||||
|
||||
Initially we will deploy the patches in the Test environment and corresponding team will be monitoring the system a week then they will give a status report like good or bad.
|
||||
|
||||
If it’s success then we will move forward to other environments. If everything is good then finally we will patch production servers.
|
||||
|
||||
Many of the organization has prepare to patch entire system. i mean full system update. It is a general patching schedule for a typical infrastructure.
|
||||
|
||||
In some of the infrastructure they may have only production environment so, we should not prepare for the full system update instead we can go with security patch to make the system more stable and secure.
|
||||
|
||||
Since Arch Linux and its derivatives distributions are fall under rolling release can be considered to be always up-to-date, as it uses the latest versions of software packages from the upstream.
|
||||
|
||||
In some cases if you want to update security patch alone then you have to use arch-audit tool to identify and fix the security patches.
|
||||
|
||||
### What is a Vulnerability?
|
||||
|
||||
A vulnerability is a security weakness in a software program or hardware components (firmware). It’s a flaw that can leave it open to attack.
|
||||
|
||||
To mitigate this we need to patch accordingly like for application/hardware it could be a code changes or config changes or parameter changes.
|
||||
|
||||
### What is Arch-Audit Tool?
|
||||
|
||||
[Arch-audit][1] is a tool like pkg-audit for Arch Linux system. It Uses data collected by the awesome Arch Security Team. It wont scan and find the vulnerable packages on your system like **yum –security check-update & yum updateinfo list available** and it will simply parse the <https://security.archlinux.org/> page and display the results in terminal. So, it would show the accurate data.
|
||||
|
||||
The Arch Security Team is a group of volunteers whose goal is to track security issues with Arch Linux packages. All issues are tracked on the Arch Linux security tracker.
|
||||
|
||||
The team was formerly known as the Arch CVE Monitoring Team. The mission of the Arch Security Team is to contribute to the improvement of the security of Arch Linux.
|
||||
|
||||
### How to Install arch-audit tool in Arch Linux
|
||||
|
||||
The arch-audit tool is available in community repository so you can use the Pacman Package Manager to install it.
|
||||
|
||||
```
|
||||
$ sudo pacman -S arch-audit
|
||||
```
|
||||
|
||||
Run the `arch-audit` tool to find the open vulnerable packages on Arch based distributions.
|
||||
|
||||
```
|
||||
$ arch-audit
|
||||
Package cairo is affected by CVE-2017-7475. Low risk!
|
||||
Package exiv2 is affected by CVE-2017-11592, CVE-2017-11591, CVE-2017-11553, CVE-2017-17725, CVE-2017-17724, CVE-2017-17723, CVE-2017-17722. Medium risk!
|
||||
Package libtiff is affected by CVE-2018-18661, CVE-2018-18557, CVE-2017-9935, CVE-2017-11613. High risk!. Update to 4.0.10-1!
|
||||
Package openssl is affected by CVE-2018-0735, CVE-2018-0734. Low risk!
|
||||
Package openssl-1.0 is affected by CVE-2018-5407, CVE-2018-0734. Low risk!
|
||||
Package patch is affected by CVE-2018-6952, CVE-2018-1000156. High risk!. Update to 2.7.6-7!
|
||||
Package pcre is affected by CVE-2017-11164. Low risk!
|
||||
Package systemd is affected by CVE-2018-6954, CVE-2018-15688, CVE-2018-15687, CVE-2018-15686. Critical risk!. Update to 239.300-1!
|
||||
Package unzip is affected by CVE-2018-1000035. Medium risk!
|
||||
Package webkit2gtk is affected by CVE-2018-4372. Critical risk!. Update to 2.22.4-1!
|
||||
```
|
||||
|
||||
The above result shows the vulnerability risk status as well such as Low, Medium and Critical.
|
||||
|
||||
To Show only vulnerable package names and their versions.
|
||||
|
||||
```
|
||||
$ arch-audit -q
|
||||
cairo
|
||||
exiv2
|
||||
libtiff>=4.0.10-1
|
||||
openssl
|
||||
openssl-1.0
|
||||
patch>=2.7.6-7
|
||||
pcre
|
||||
systemd>=239.300-1
|
||||
unzip
|
||||
webkit2gtk>=2.22.4-1
|
||||
```
|
||||
|
||||
To show only packages that have already been fixed.
|
||||
|
||||
```
|
||||
$ arch-audit --upgradable --quiet
|
||||
libtiff>=4.0.10-1
|
||||
patch>=2.7.6-7
|
||||
systemd>=239.300-1
|
||||
webkit2gtk>=2.22.4-1
|
||||
```
|
||||
|
||||
To cross check the above results, i’m going to test one of the package which is listed above in <https://www.archlinux.org/packages/> to confirm whether the vulnerability is still open or fixed it. Yes, it’s fixed and published the updated package in repository on yesterday.
|
||||
![][3]
|
||||
|
||||
To print only package names and associated CVEs alone.
|
||||
|
||||
```
|
||||
$ arch-audit -uf "%n|%c"
|
||||
libtiff|CVE-2018-18661,CVE-2018-18557,CVE-2017-9935,CVE-2017-11613
|
||||
patch|CVE-2018-6952,CVE-2018-1000156
|
||||
systemd|CVE-2018-6954,CVE-2018-15688,CVE-2018-15687,CVE-2018-15686
|
||||
webkit2gtk|CVE-2018-4372
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/arch-audit-a-tool-to-check-vulnerable-packages-in-arch-linux/
|
||||
|
||||
作者:[Prakash Subramanian][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/prakash/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://github.com/ilpianista/arch-audit
|
||||
[2]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[3]: https://www.2daygeek.com/wp-content/uploads/2018/11/A-Tool-To-Check-Vulnerable-Packages-In-Arch-Linux.png
|
||||
@@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (HankChow)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Head to the arcade in your Linux terminal with this Pac-man clone)
|
||||
[#]: via: (https://opensource.com/article/18/12/linux-toy-myman)
|
||||
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
|
||||
|
||||
Head to the arcade in your Linux terminal with this Pac-man clone
|
||||
======
|
||||
Want to recreate the magic of your favorite arcade game? Today's command-line toy will transport you back in time.
|
||||

|
||||
|
||||
Welcome back to another day of the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself what command-line toys are all about. Basically, they're games and simple diversions that help you have fun at the terminal.
|
||||
|
||||
Some are new, and some are old classics. We hope you enjoy.
|
||||
|
||||
Today's toy, MyMan, is a fun clone of the classic arcade game [Pac-Man][1]. (You didn't think this was going to be about the [similarly-named][2] Linux package manager, did you?) If you're anything like me, you spent more than your fair share of quarters trying to hit a high score Pac-Man back in the day, and still give it a go whenever you get a chance.
|
||||
|
||||
MyMan isn't the only Pac-Man clone for the Linux terminal, but it's the one I chose to include because 1) I like its visual style, which rings true to the original and 2) it's conveniently packaged for my Linux distribution so it was an easy install. But you should check out your other options as well. Here's [another one][3] that looks like it may be promising, but I haven't tried it.
|
||||
|
||||
Since MyMan was packaged for Fedora, installation was as simple as:
|
||||
|
||||
```
|
||||
$ dnf install myman
|
||||
```
|
||||
|
||||
MyMan is made available under an MIT license and you can check out the source code on [SourceForge][4].
|
||||

|
||||
Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
|
||||
|
||||
Check out yesterday's toy, [The Linux terminal is no one-trick pony][5], and check back tomorrow for another!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/12/linux-toy-myman
|
||||
|
||||
作者:[Jason Baker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jason-baker
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://en.wikipedia.org/wiki/Pac-Man
|
||||
[2]: https://wiki.archlinux.org/index.php/pacman
|
||||
[3]: https://github.com/YoctoForBeaglebone/pacman4console
|
||||
[4]: https://myman.sourceforge.io/
|
||||
[5]: https://opensource.com/article/18/12/linux-toy-ponysay
|
||||
@@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (HankChow)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (s-tui: A Terminal Tool To Monitor CPU Temperature, Frequency, Power And Utilization In Linux)
|
||||
[#]: via: (https://www.2daygeek.com/s-tui-stress-terminal-ui-monitor-linux-cpu-temperature-frequency/)
|
||||
[#]: author: (Prakash Subramanian https://www.2daygeek.com/author/prakash/)
|
||||
|
||||
s-tui: A Terminal Tool To Monitor CPU Temperature, Frequency, Power And Utilization In Linux
|
||||
======
|
||||
|
||||
By default every Linux administrator would go with **[lm_sensors to monitor CPU temperature][1]**.
|
||||
|
||||
lm_sensors (Linux monitoring sensors) is a free and open-source application that provides tools and drivers for monitoring temperatures, voltage, and fans.
|
||||
|
||||
It’s a CLI utility and if you are looking for alternative tools.
|
||||
|
||||
I would suggest you to go for s-tui.
|
||||
|
||||
It’s a Stress Terminal UI which helps administrator to view CPU temperature with colors.
|
||||
|
||||
### What is s-tui
|
||||
|
||||
s-tui is a terminal UI for monitoring your computer. s-tui allows to monitor CPU temperature, frequency, power and utilization in a graphical way from the terminal.
|
||||
|
||||
Also, shows performance dips caused by thermal throttling, it requires minimal resources and doesn’t requires X-server. It was written in Python and requires root privilege to use this.
|
||||
|
||||
s-tui is a self-contained application which can run out-of-the-box and doesn’t need config files to drive its core features.
|
||||
|
||||
s-tui uses psutil to probe some of your hardware information. If your hardware is not supported, you might not see all the information.
|
||||
|
||||
Running s-tui as root gives access to the maximum Turbo Boost frequency available to your CPU when stressing all cores.
|
||||
|
||||
It uses Stress utility in the background to check the temperature of its components do not exceed their acceptable range by imposes certain types of compute stress on your system.
|
||||
|
||||
Running an overclocked PC is fine as long as it is stable and that the temperature of its components do not exceed their acceptable range.
|
||||
|
||||
There are several programs available to assess system stability through stress testing the system and thereby the overclock level.
|
||||
|
||||
### How to Install s-tui In Linux
|
||||
|
||||
It was written in Python and pip installation is a recommended method to install s-tui on Linux. Make sure you should have installed python-pip package on your system. If no, use the following command to install it.
|
||||
|
||||
For Debian/Ubuntu users, use **[Apt Command][2]** or **[Apt-Get Command][3]** to install pip package.
|
||||
|
||||
```
|
||||
$ sudo apt install python-pip stress
|
||||
```
|
||||
|
||||
For Archlinux users, use **[Pacman Command][4]** to install pip package.
|
||||
|
||||
```
|
||||
$ sudo pacman -S python-pip stress
|
||||
```
|
||||
|
||||
For Fedora users, use **[DNF Command][5]** to install pip package.
|
||||
|
||||
```
|
||||
$ sudo dnf install python-pip stress
|
||||
```
|
||||
|
||||
For CentOS/RHEL users, use **[YUM Command][6]** to install pip package.
|
||||
|
||||
```
|
||||
$ sudo yum install python-pip stress
|
||||
```
|
||||
|
||||
For openSUSE users, use **[Zypper Command][7]** to install pip package.
|
||||
|
||||
```
|
||||
$ sudo zypper install python-pip stress
|
||||
```
|
||||
|
||||
Finally run the following **[pip command][8]** to install s-tui tool in Linux.
|
||||
|
||||
For Python 2.x:
|
||||
|
||||
```
|
||||
$ sudo pip install s-tui
|
||||
```
|
||||
|
||||
For Python 3.x:
|
||||
|
||||
```
|
||||
$ sudo pip3 install s-tui
|
||||
```
|
||||
|
||||
### How to Access s-tui
|
||||
|
||||
As i told in the beginning of the article. It requires root privilege to get all the information from your system. Just run the following command to launch s-tui.
|
||||
|
||||
```
|
||||
$ sudo s-tui
|
||||
```
|
||||
|
||||
![][10]
|
||||
|
||||
By default it enable hardware monitoring and select the “Stress” option to do the stress test on your system.
|
||||
![][11]
|
||||
|
||||
To check other options, navigate to help page.
|
||||
|
||||
```
|
||||
$ s-tui --help
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/s-tui-stress-terminal-ui-monitor-linux-cpu-temperature-frequency/
|
||||
|
||||
作者:[Prakash Subramanian][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/prakash/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.2daygeek.com/view-check-cpu-hard-disk-temperature-linux/
|
||||
[2]: https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[3]: https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[4]: https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/
|
||||
[5]: https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/
|
||||
[6]: https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[7]: https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[8]: https://www.2daygeek.com/install-pip-manage-python-packages-linux/
|
||||
[9]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[10]: https://www.2daygeek.com/wp-content/uploads/2018/12/s-tui-stress-terminal-ui-monitor-linux-cpu-temperature-frequency-1.jpg
|
||||
[11]: https://www.2daygeek.com/wp-content/uploads/2018/12/s-tui-stress-terminal-ui-monitor-linux-cpu-temperature-frequency-2.jpg
|
||||
@@ -1,116 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Managing dotfiles with rcm)
|
||||
[#]: via: (https://fedoramagazine.org/managing-dotfiles-rcm/)
|
||||
[#]: author: (Link Dupont https://fedoramagazine.org/author/linkdupont/)
|
||||
|
||||
Managing dotfiles with rcm
|
||||
======
|
||||
|
||||

|
||||
|
||||
A hallmark feature of many GNU/Linux programs is the easy-to-edit configuration file. Nearly all common free software programs store configuration settings inside a plain text file, often in a structured format like JSON, YAML or [“INI-like”][1]. These configuration files are frequently found hidden inside a user’s home directory. However, a basic ls won’t reveal them. UNIX standards require that any file or directory name that begins with a period (or “dot”) is considered “hidden” and will not be listed in directory listings unless requested by the user. For example, to list all files using the ls program, pass the -a command-line option.
|
||||
|
||||
Over time, these configuration files become highly customized, and managing them becomes increasingly more challenging as time goes on. Not only that, but keeping them synchronized between multiple computers is a common challenge in large organizations. Finally, many users find a sense of pride in their unique configuration settings and want an easy way to share them with friends. That’s where **rcm** steps in.
|
||||
|
||||
**rcm** is a “rc” file management suite (“rc” is another convention for naming configuration files that has been adopted by some GNU/Linux programs like screen or bash). **rcm** provides a suite of commands to manage and list files it tracks. Install **rcm** using **dnf**.
|
||||
|
||||
### Getting started
|
||||
|
||||
By default, **rcm** uses ~/.dotfiles for storing all the dotfiles it manages. A managed dotfile is actually stored inside ~/.dotfiles, and a symlink is placed in the expected file’s location. For example, if ~/.bashrc is tracked by **rcm** , a long listing would look like this.
|
||||
|
||||
```
|
||||
[link@localhost ~]$ ls -l ~/.bashrc
|
||||
lrwxrwxrwx. 1 link link 27 Dec 16 05:19 .bashrc -> /home/link/.dotfiles/bashrc
|
||||
[link@localhost ~]$
|
||||
```
|
||||
|
||||
**rcm** consists of 4 commands:
|
||||
|
||||
* mkrc – convert a file into a dotfile managed by rcm
|
||||
* lsrc – list files managed by rcm
|
||||
* rcup – synchronize dotfiles managed by rcm
|
||||
* rcdn – remove all the symlinks managed by rcm
|
||||
|
||||
|
||||
|
||||
### Share bashrc across two computers
|
||||
|
||||
It is not uncommon today for a user to have shell accounts on more than one computer. Keeping dotfiles synchronized between those computers can be a challenge. This scenario will present one possible solution, using only **rcm** and **git**.
|
||||
|
||||
First, convert (or “bless”) a file into a dotfile managed by **rcm** with mkrc.
|
||||
|
||||
```
|
||||
[link@localhost ~]$ mkrc -v ~/.bashrc
|
||||
Moving...
|
||||
'/home/link/.bashrc' -> '/home/link/.dotfiles/bashrc'
|
||||
Linking...
|
||||
'/home/link/.dotfiles/bashrc' -> '/home/link/.bashrc'
|
||||
[link@localhost ~]$
|
||||
```
|
||||
|
||||
Next, verify the listings are correct with lsrc.
|
||||
|
||||
```
|
||||
[link@localhost ~]$ lsrc
|
||||
/home/link/.bashrc:/home/link/.dotfiles/bashrc
|
||||
[link@localhost ~]$
|
||||
```
|
||||
|
||||
Now create a git repository inside ~/.dotfiles and set up an accessible remote repository using your choice of hosted git repositories. Commit the bashrc file and push a new branch.
|
||||
|
||||
```
|
||||
[link@localhost ~]$ cd ~/.dotfiles
|
||||
[link@localhost .dotfiles]$ git init
|
||||
Initialized empty Git repository in /home/link/.dotfiles/.git/
|
||||
[link@localhost .dotfiles]$ git remote add origin git@github.com:linkdupont/dotfiles.git
|
||||
[link@localhost .dotfiles]$ git add bashrc
|
||||
[link@localhost .dotfiles]$ git commit -m "initial commit"
|
||||
[master (root-commit) b54406b] initial commit
|
||||
1 file changed, 15 insertions(+)
|
||||
create mode 100644 bashrc
|
||||
[link@localhost .dotfiles]$ git push -u origin master
|
||||
...
|
||||
[link@localhost .dotfiles]$
|
||||
```
|
||||
|
||||
On the second machine, clone this repository into ~/.dotfiles.
|
||||
|
||||
```
|
||||
[link@remotehost ~]$ git clone git@github.com:linkdupont/dotfiles.git ~/.dotfiles
|
||||
...
|
||||
[link@remotehost ~]$
|
||||
```
|
||||
|
||||
Now update the symlinks managed by **rcm** with rcup.
|
||||
|
||||
```
|
||||
[link@remotehost ~]$ rcup -v
|
||||
replacing identical but unlinked /home/link/.bashrc
|
||||
removed '/home/link/.bashrc'
|
||||
'/home/link/.dotfiles/bashrc' -> '/home/link/.bashrc'
|
||||
[link@remotehost ~]$
|
||||
```
|
||||
|
||||
Overwrite the existing ~/.bashrc (if it exists) and restart the shell.
|
||||
|
||||
That’s it! The host-specific option (-o) is a useful addition to the scenario above. And as always, be sure to read the manpages; they contain a wealth of example commands.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/managing-dotfiles-rcm/
|
||||
|
||||
作者:[Link Dupont][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/linkdupont/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://en.wikipedia.org/wiki/INI_file
|
||||
@@ -1,223 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Getting started with Pelican: A Python-based static site generator)
|
||||
[#]: via: (https://opensource.com/article/19/1/getting-started-pelican)
|
||||
[#]: author: (Craig Sebenik https://opensource.com/users/craig5)
|
||||
|
||||
Getting started with Pelican: A Python-based static site generator
|
||||
======
|
||||
Pelican is a great choice for Python users who want to self-host a simple website or blog.
|
||||
|
||||

|
||||
|
||||
If you want to create a custom website or blog, you have a lot of options. Many providers will host your website and do much of the work for you. (WordPress is an extremely popular option.) But you lose some flexibility by using a hosted solution. As a software developer, I prefer to manage my own server and keep more freedom in how my website operates.
|
||||
|
||||
However, it is a fair amount of work to manage a web server. Installing it and getting a simple application up to serve content is easy enough. But keeping on top of security patches and updates is very time-consuming. If you just want to serve static web pages, having a web server and a host of applications may be more effort than it's worth. Creating HTML pages by hand is also not a good option.
|
||||
|
||||
This is where a static site generator can come in. These applications use templates to create all the static pages you want and cross-link them with associated metadata. (e.g., showing all the pages with a common tag or keyword.) Static site generators help you create a site with a common look and feel using elements like navigation areas and a header and footer.
|
||||
|
||||
I have been using [Python][1] for years now. So, when I first started looking for something to generate static HTML pages, I wanted something written in Python. The main reason is that I often want to peek into the internals of how an application works, and using a language that I already know makes that easier. (If that isn't important to you or you don't use Python, there are some other great [static site generators][2] that use Ruby, JavaScript, and other languages.)
|
||||
|
||||
I decided to give [Pelican][3] a try. It is a commonly used static site generator written in Python. It directly supports [reStructuredText][4] and can support [Markdown][5] when the required package is installed. All the tasks are performed via command-line interface (CLI) tools, which makes it simple for anyone familiar with the command line. And its simple quickstart CLI tool makes creating a website extremely easy.
|
||||
|
||||
In this article, I'll explain how to install Pelican 4, add an article, and change the default theme. (Note: This was all developed on MacOS; it should work the same using any flavor of Unix/Linux, but I don't have a Windows host to test on.)
|
||||
|
||||
### Installation and configuration
|
||||
|
||||
The first step is to create a [virtualenv][6] and install Pelican.
|
||||
|
||||
```
|
||||
$ mkdir test-site
|
||||
$ cd test-site
|
||||
$ python3 -m venv venv
|
||||
$ ./venv/bin/pip install --upgrade pip
|
||||
...
|
||||
Successfully installed pip-18.1
|
||||
$ ./venv/bin/pip install pelican
|
||||
Collecting pelican
|
||||
...
|
||||
Successfully installed MarkupSafe-1.1.0 blinker-1.4 docutils-0.14 feedgenerator-1.9 jinja2-2.10 pelican-4.0.1 pygments-2.3.1 python-dateutil-2.7.5 pytz-2018.7 six-1.12.0 unidecode-1.0.23
|
||||
```
|
||||
|
||||
To keep things simple, I entered values for the title and author and replied N to URL prefix and article pagination. (For the rest of the questions, I used the default given.)
|
||||
|
||||
Pelican's quickstart CLI tool will create the basic layout and a few files to get you started. Run the **pelican-quickstart** command. To keep things simple, I entered values for the **title** and **author** and replied **N** to URL prefix and article pagination. It is very easy to change these settings in the configuration file later.
|
||||
|
||||
```
|
||||
$ ./venv/bin/pelicanquickstart
|
||||
Welcome to pelicanquickstart v4.0.1.
|
||||
|
||||
This script will help you create a new Pelican-based website.
|
||||
|
||||
Please answer the following questions so this script can generate the files needed by Pelican.
|
||||
|
||||
> Where do you want to create your new web site? [.]
|
||||
> What will be the title of this web site? My Test Blog
|
||||
> Who will be the author of this web site? Craig
|
||||
> What will be the default language of this web site? [en]
|
||||
> Do you want to specify a URL prefix? e.g., https://example.com (Y/n) n
|
||||
> Do you want to enable article pagination? (Y/n) n
|
||||
> What is your time zone? [Europe/Paris]
|
||||
> Do you want to generate a tasks.py/Makefile to automate generation and publishing? (Y/n)
|
||||
> Do you want to upload your website using FTP? (y/N)
|
||||
> Do you want to upload your website using SSH? (y/N)
|
||||
> Do you want to upload your website using Dropbox? (y/N)
|
||||
> Do you want to upload your website using S3? (y/N)
|
||||
> Do you want to upload your website using Rackspace Cloud Files? (y/N)
|
||||
> Do you want to upload your website using GitHub Pages? (y/N)
|
||||
Done. Your new project is available at /Users/craig/tmp/pelican/test-site
|
||||
```
|
||||
|
||||
All the files you need to get started are ready to go.
|
||||
|
||||
The quickstart defaults to the Europe/Paris time zone, so change that before proceeding. Open the **pelicanconf.py** file in your favorite text editor. Look for the **TIMEZONE** variable.
|
||||
|
||||
```
|
||||
TIMEZONE = 'Europe/Paris'
|
||||
```
|
||||
|
||||
Change it to **UTC**.
|
||||
|
||||
```
|
||||
TIMEZONE = 'UTC'
|
||||
```
|
||||
|
||||
To update the social settings, look for the **SOCIAL** variable in **pelicanconf.py**.
|
||||
|
||||
```
|
||||
SOCIAL = (('You can add links in your config file', '#'),
|
||||
('Another social link', '#'),)
|
||||
```
|
||||
|
||||
I'll add a link to my Twitter account.
|
||||
|
||||
```
|
||||
SOCIAL = (('Twitter (#craigs55)', 'https://twitter.com/craigs55'),)
|
||||
```
|
||||
|
||||
Notice that trailing comma—it's important. That comma helps Python recognize the variable is actually a set. Make sure you don't delete that comma.
|
||||
|
||||
Now you have the basics of a site. The quickstart created a Makefile with a number of targets. Giving the **devserver** target to **make** will start a development server on your machine so you can preview everything. The CLI commands used in the Makefile are assumed to be part of your **PATH** , so you need to **activate** the **virtualenv** first.
|
||||
|
||||
```
|
||||
$ source ./venv/bin/activate
|
||||
$ make devserver
|
||||
pelican -lr /Users/craig/tmp/pelican/test-site/content o
|
||||
/Users/craig/tmp/pelican/test-site/output -s /Users/craig/tmp/pelican/test-site/pelicanconf.py
|
||||
|
||||
-> Modified: theme, settings. regenerating...
|
||||
WARNING: No valid files found in content for the active readers:
|
||||
| BaseReader (static)
|
||||
| HTMLReader (htm, html)
|
||||
| RstReader (rst)
|
||||
Done: Processed 0 articles, 0 drafts, 0 pages, 0 hidden pages and 0 draft pages in 0.18 seconds.
|
||||
```
|
||||
|
||||
Point your favorite browser to <http://localhost:8000> to see your simple test blog.
|
||||
|
||||

|
||||
|
||||
You can see the Twitter link on the right side and some links to Pelican, Python, and Jinja to the left of it. (Jinja is a great templating language that Pelican can use. You can learn more about it in [Jinja's documentation][7].)
|
||||
|
||||
### Adding content
|
||||
|
||||
Now that you have a basic site, add some content. First, add a file called **welcome.rst** to the site's **content** directory. In your favorite text editor, create a file with the following text:
|
||||
|
||||
```
|
||||
$ pwd
|
||||
/Users/craig/tmp/pelican/test-site
|
||||
$ cat content/welcome.rst
|
||||
|
||||
Welcome to my blog!
|
||||
###################
|
||||
|
||||
:date: 20181216 08:30
|
||||
:tags: welcome
|
||||
:category: Intro
|
||||
:slug: welcome
|
||||
:author: Craig
|
||||
:summary: Welcome document
|
||||
|
||||
Welcome to my blog.
|
||||
This is a short page just to show how to put up a static page.
|
||||
```
|
||||
|
||||
The metadata lines—date, tags, etc.—are automatically parsed by Pelican.
|
||||
|
||||
After you write the file, the **devserver** should output something like this:
|
||||
|
||||
```
|
||||
-> Modified: content. regenerating...
|
||||
Done: Processed 1 article, 0 drafts, 0 pages, 0 hidden pages and 0 draft pages in 0.10 seconds.
|
||||
```
|
||||
|
||||
Reload your test site in your browser to view the changes.
|
||||
|
||||

|
||||
|
||||
The metadata (e.g., date and tags) were automatically added to the page. Also, Pelican automatically detected the **intro** category and added the section to the top navigation.
|
||||
|
||||
### Change the theme
|
||||
|
||||
One of the nicest parts of working with popular, open source software like Pelican is that many users will make changes and contribute them back to the project. Many of the contributions are in the form of themes.
|
||||
|
||||
A site's theme sets colors, layout options, etc. It's really easy to try out new themes. You can preview many of them at [Pelican Themes][8].
|
||||
|
||||
First, clone the GitHub repo:
|
||||
|
||||
```
|
||||
$ cd ..
|
||||
$ git clone --recursive https://github.com/getpelican/pelicanthemes
|
||||
Cloning into 'pelicanthemes'...
|
||||
```
|
||||
|
||||
Since I like the color blue, I'll try [blueidea][9].
|
||||
|
||||
Edit **pelicanconf.py** and add the following line:
|
||||
|
||||
```
|
||||
THEME = '/Users/craig/tmp/pelican/pelican-themes/blueidea/'
|
||||
```
|
||||
|
||||
The **devserver** will regenerate your output. Reload the webpage in your browser to see the new theme.
|
||||
|
||||

|
||||
|
||||
The theme controls many aspects of the layout. For example, in the default theme, you can see the category (Intro) with the meta tags next to the article. But that category is not displayed in the blueidea theme.
|
||||
|
||||
### Other considerations
|
||||
|
||||
This was a pretty quick introduction to Pelican. There are a couple of important topics that I did not cover.
|
||||
|
||||
First, one reason I was hesitant to move to a static site was that it wouldn't allow discussions on the articles. Fortunately, there are some third-party providers that will host discussions for you. The one I am currently looking at is [Disqus][10].
|
||||
|
||||
Next, everything above was done on my local machine. If I want others to view my site, I'll have to upload the pre-generated HTML files somewhere. If you look at the **pelican-quickstart** output, you will see options for using FTP, SSH, S3, and even GitHub Pages. Each option has its pros and cons. But, if I had to choose one, I would likely publish to GitHub Pages.
|
||||
|
||||
Pelican has many other features—I am still learning more about it every day. If you want to self-host a website or a blog with simple, static content and you want to use Python, Pelican is a great choice. It has an active user community that is fixing bugs, adding features, and creating new and interesting themes. Give it a try!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/1/getting-started-pelican
|
||||
|
||||
作者:[Craig Sebenik][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/craig5
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/resources/python
|
||||
[2]: https://opensource.com/sitewide-search?search_api_views_fulltext=static%20site%20generator
|
||||
[3]: http://docs.getpelican.com/en/stable/
|
||||
[4]: http://docutils.sourceforge.net/rst.html
|
||||
[5]: https://daringfireball.net/projects/markdown/
|
||||
[6]: https://virtualenv.pypa.io/en/latest/
|
||||
[7]: http://jinja.pocoo.org/docs/2.10/
|
||||
[8]: http://www.pelicanthemes.com/
|
||||
[9]: https://github.com/nasskach/pelican-blueidea/tree/58fb13112a2707baa7d65075517c40439ab95c0a
|
||||
[10]: https://disqus.com/
|
||||
@@ -1,80 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Bash 5.0 Released with New Features)
|
||||
[#]: via: (https://itsfoss.com/bash-5-release)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
|
||||
Bash 5.0 Released with New Features
|
||||
======
|
||||
|
||||
The [mailing list][1] confirmed the release of Bash-5.0 recently. And, it is exciting to know that it comes baked with new features and variable.
|
||||
|
||||
Well, if you’ve been using Bash 4.4.XX, you will definitely love the fifth major release of [Bash][2].
|
||||
|
||||
The fifth release focuses on new shell variables and a lot of major bug fixes with an overhaul. It also introduces a couple of new features along with some incompatible changes between bash-4.4 and bash-5.0.
|
||||
|
||||
![Bash logo][3]
|
||||
|
||||
### What about the new features?
|
||||
|
||||
The mailing list explains the bug fixed in this new release:
|
||||
|
||||
> This release fixes several outstanding bugs in bash-4.4 and introduces several new features. The most significant bug fixes are an overhaul of how nameref variables resolve and a number of potential out-of-bounds memory errors discovered via fuzzing. There are a number of changes to the expansion of $@ and $* in various contexts where word splitting is not performed to conform to a Posix standard interpretation, and additional changes to resolve corner cases for Posix conformance.
|
||||
|
||||
It also introduces some new features. As per the release note, these are the most notable new features are several new shell variables:
|
||||
|
||||
> The BASH_ARGV0, EPOCHSECONDS, and EPOCHREALTIME. The ‘history’ builtin can remove ranges of history entries and understands negative arguments as offsets from the end of the history list. There is an option to allow local variables to inherit the value of a variable with the same name at a preceding scope. There is a new shell option that, when enabled, causes the shell to attempt to expand associative array subscripts only once (this is an issue when they are used in arithmetic expressions). The ‘globasciiranges‘ shell option is now enabled by default; it can be set to off by default at configuration time.
|
||||
|
||||
### What about the changes between Bash-4.4 and Bash-5.0?
|
||||
|
||||
The update log mentioned about the incompatible changes and the supported readline version history. Here’s what it said:
|
||||
|
||||
> There are a few incompatible changes between bash-4.4 and bash-5.0. The changes to how nameref variables are resolved means that some uses of namerefs will behave differently, though I have tried to minimize the compatibility issues. By default, the shell only sets BASH_ARGC and BASH_ARGV at startup if extended debugging mode is enabled; it was an oversight that it was set unconditionally and caused performance issues when scripts were passed large numbers of arguments.
|
||||
>
|
||||
> Bash can be linked against an already-installed Readline library rather than the private version in lib/readline if desired. Only readline-8.0 and later versions are able to provide all of the symbols that bash-5.0 requires; earlier versions of the Readline library will not work correctly.
|
||||
|
||||
I believe some of the features/variables added are very useful. Some of my favorites are:
|
||||
|
||||
* There is a new (disabled by default, undocumented) shell option to enable and disable sending history to syslog at runtime.
|
||||
* The shell doesn’t automatically set BASH_ARGC and BASH_ARGV at startup unless it’s in debugging mode, as the documentation has always said, but will dynamically create them if a script references them at the top level without having enabled debugging mode.
|
||||
* The ‘history’ can now delete ranges of history entries using ‘-d start-end’.
|
||||
* If a non-interactive shell with job control enabled detects that a foreground job died due to SIGINT, it acts as if it received the SIGINT.
|
||||
* BASH_ARGV0: a new variable that expands to $0 and sets $0 on assignment.
|
||||
|
||||
|
||||
|
||||
To check the complete list of changes and features you should refer to the [Mailing list post][1].
|
||||
|
||||
### Wrapping Up
|
||||
|
||||
You can check your current Bash version, using this command:
|
||||
|
||||
```
|
||||
bash --version
|
||||
```
|
||||
|
||||
It’s more likely that you’ll have Bash 4.4 installed. If you want to get the new version, I would advise waiting for your distribution to provide it.
|
||||
|
||||
With Bash-5.0 available, what do you think about it? Are you using any alternative to bash? If so, would this update change your mind?
|
||||
|
||||
Let us know your thoughts in the comments below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/bash-5-release
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/ankush/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://lists.gnu.org/archive/html/bug-bash/2019-01/msg00063.html
|
||||
[2]: https://www.gnu.org/software/bash/
|
||||
[3]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/01/bash-logo.jpg?resize=800%2C450&ssl=1
|
||||
@@ -0,0 +1,187 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (GoAccess – A Real-Time Web Server Log Analyzer And Interactive Viewer)
|
||||
[#]: via: (https://www.2daygeek.com/goaccess-a-real-time-web-server-log-analyzer-and-interactive-viewer/)
|
||||
[#]: author: (Vinoth Kumar https://www.2daygeek.com/author/vinoth/)
|
||||
|
||||
GoAccess – A Real-Time Web Server Log Analyzer And Interactive Viewer
|
||||
======
|
||||
|
||||
Analyzing a log file is a big headache for Linux administrators as it’s capturing a lot of things.
|
||||
|
||||
Most of the newbies and L1 administrators doesn’t know how to analyze this.
|
||||
|
||||
If you have good knowledge to analyze a logs then you will be a legend for NIX system.
|
||||
|
||||
There are many tools available in Linux to analyze the logs easily.
|
||||
|
||||
GoAccess is one of the tool which allow users to analyze web server logs easily.
|
||||
|
||||
We will be going to discuss in details about GoAccess tool in this article.
|
||||
|
||||
### What is GoAccess?
|
||||
|
||||
GoAccess is a real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems or through your browser.
|
||||
|
||||
GoAccess has minimal requirements, it’s written in C and requires only ncurses.
|
||||
|
||||
It will support Apache, Nginx and Lighttpd logs. It provides fast and valuable HTTP statistics for system administrators that require a visual server report on the fly.
|
||||
|
||||
GoAccess parses the specified web log file and outputs the data to the X terminal and browser.
|
||||
|
||||
GoAccess was designed to be a fast, terminal-based log analyzer. Its core idea is to quickly analyze and view web server statistics in real time without needing to use your browser.
|
||||
|
||||
Terminal output is the default output, it has the capability to generate a complete, self-contained, real-time HTML report, as well as a JSON, and CSV report.
|
||||
|
||||
GoAccess allows any custom log format and the following (Combined Log Format (XLF/ELF) Apache | Nginx & Common Log Format (CLF) Apache) predefined log format options are included, but not limited to.
|
||||
|
||||
### GoAccess Features
|
||||
|
||||
* **`Completely Real Time:`** All the metrics are updated every 200 ms on the terminal and every second on the HTML output.
|
||||
* **`Track Application Response Time:`** Track the time taken to serve the request. Extremely useful if you want to track pages that are slowing down your site.
|
||||
* **`Visitors:`** Determine the amount of hits, visitors, bandwidth, and metrics for slowest running requests by the hour, or date.
|
||||
* **`Metrics per Virtual Host:`** Have multiple Virtual Hosts (Server Blocks)? It features a panel that displays which virtual host is consuming most of the web server resources.
|
||||
|
||||
|
||||
|
||||
### How to Install GoAccess?
|
||||
|
||||
I would advise users to install GoAccess from distribution official repository with help of Package Manager. It is available in most of the distributions official repository.
|
||||
|
||||
As we know, we will be getting bit outdated package for standard release distribution and rolling release distributions always include latest package.
|
||||
|
||||
If you are running the OS with standard release distributions, i would suggest you to check the alternative options such as PPA or Official GoAccess maintainer repository, etc, to get a latest package.
|
||||
|
||||
For **`Debian/Ubuntu`** systems, use **[APT-GET Command][1]** or **[APT Command][2]** to install GoAccess on your systems.
|
||||
|
||||
```
|
||||
# apt install goaccess
|
||||
```
|
||||
|
||||
To get a latest GoAccess package, use the below GoAccess official repository.
|
||||
|
||||
```
|
||||
$ echo "deb https://deb.goaccess.io/ $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list.d/goaccess.list
|
||||
$ wget -O - https://deb.goaccess.io/gnugpg.key | sudo apt-key add -
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install goaccess
|
||||
```
|
||||
|
||||
For **`RHEL/CentOS`** systems, use **[YUM Package Manager][3]** to install GoAccess on your systems.
|
||||
|
||||
```
|
||||
# yum install goaccess
|
||||
```
|
||||
|
||||
For **`Fedora`** system, use **[DNF Package Manager][4]** to install GoAccess on your system.
|
||||
|
||||
```
|
||||
# dnf install goaccess
|
||||
```
|
||||
|
||||
For **`ArchLinux/Manjaro`** based systems, use **[Pacman Package Manager][5]** to install GoAccess on your systems.
|
||||
|
||||
```
|
||||
# pacman -S goaccess
|
||||
```
|
||||
|
||||
For **`openSUSE Leap`** system, use **[Zypper Package Manager][6]** to install GoAccess on your system.
|
||||
|
||||
```
|
||||
# zypper install goaccess
|
||||
|
||||
# zypper ar -f obs://server:http
|
||||
|
||||
# zypper ref && zypper in goaccess
|
||||
```
|
||||
|
||||
### How to Use GoAccess?
|
||||
|
||||
After successful installation of GoAccess. Just enter the goaccess command and followed by the web server log location to view it.
|
||||
|
||||
```
|
||||
# goaccess [options] /path/to/Web Server/access.log
|
||||
|
||||
# goaccess /var/log/apache/2daygeek_access.log
|
||||
```
|
||||
|
||||
When you execute the above command, it will ask you to select the **Log Format Configuration**.
|
||||
![][8]
|
||||
|
||||
I had tested this with Apache access log. The Apache log is splitted in fifteen section. The details are below. The main section shows the summary about the fifteen section.
|
||||
|
||||
The below screenshots included four sessions such as Unique Visitors, Requested files, Static Requests, Not found URLs.
|
||||
![][9]
|
||||
|
||||
The below screenshots included four sessions such as Visitor Hostnames and IPs, Operating Systems, Browsers, Time Distribution.
|
||||
![][10]
|
||||
|
||||
The below screenshots included four sessions such as Referrers URLs, Referring Sites, Google’s search engine results, HTTP status codes.
|
||||
![][11]
|
||||
|
||||
If you would like to generate a html report, use the following format.
|
||||
|
||||
Initially i got an error when i was trying to generate the html report.
|
||||
|
||||
```
|
||||
# goaccess 2daygeek_access.log -a > report.html
|
||||
|
||||
GoAccess - version 1.3 - Nov 23 2018 11:28:19
|
||||
Config file: No config file used
|
||||
|
||||
Fatal error has occurred
|
||||
Error occurred at: src/parser.c - parse_log - 2764
|
||||
No time format was found on your conf file.Parsing... [0] [0/s]
|
||||
```
|
||||
|
||||
It says “No time format was found on your conf file”. To overcome this issue, add the “COMBINED” log format option on it.
|
||||
|
||||
```
|
||||
# goaccess -f 2daygeek_access.log --log-format=COMBINED -o 2daygeek.html
|
||||
Parsing...[0,165] [50,165/s]
|
||||
```
|
||||
|
||||
![][12]
|
||||
|
||||
GoAccess allows you to access and analyze the real-time log filtering and parsing.
|
||||
|
||||
```
|
||||
# tail -f /var/log/apache/2daygeek_access.log | goaccess -
|
||||
```
|
||||
|
||||
For more details navigate to man or help page.
|
||||
|
||||
```
|
||||
# man goaccess
|
||||
or
|
||||
# goaccess --help
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/goaccess-a-real-time-web-server-log-analyzer-and-interactive-viewer/
|
||||
|
||||
作者:[Vinoth Kumar][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/vinoth/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[2]: https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[3]: https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[4]: https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/
|
||||
[5]: https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/
|
||||
[6]: https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[7]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[8]: https://www.2daygeek.com/wp-content/uploads/2019/01/goaccess-a-real-time-web-server-log-analyzer-and-interactive-viewer-1.png
|
||||
[9]: https://www.2daygeek.com/wp-content/uploads/2019/01/goaccess-a-real-time-web-server-log-analyzer-and-interactive-viewer-2.png
|
||||
[10]: https://www.2daygeek.com/wp-content/uploads/2019/01/goaccess-a-real-time-web-server-log-analyzer-and-interactive-viewer-3.png
|
||||
[11]: https://www.2daygeek.com/wp-content/uploads/2019/01/goaccess-a-real-time-web-server-log-analyzer-and-interactive-viewer-4.png
|
||||
[12]: https://www.2daygeek.com/wp-content/uploads/2019/01/goaccess-a-real-time-web-server-log-analyzer-and-interactive-viewer-5.png
|
||||
@@ -1,61 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Get started with Joplin, a note-taking app)
|
||||
[#]: via: (https://opensource.com/article/19/1/productivity-tool-joplin)
|
||||
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney (Kevin Sonney))
|
||||
|
||||
Get started with Joplin, a note-taking app
|
||||
======
|
||||
Learn how open source tools can help you be more productive in 2019. First up, Joplin.
|
||||

|
||||
|
||||
There seems to be a mad rush at the beginning of every year to find ways to be more productive. New Year's resolutions, the itch to start the year off right, and of course, an "out with the old, in with the new" attitude all contribute to this. And the usual round of recommendations is heavily biased towards closed source and proprietary software. It doesn't have to be that way.
|
||||
|
||||
Here's the first of my picks for 19 new (or new-to-you) open source tools to help you be more productive in 2019.
|
||||
|
||||
### Joplin
|
||||
|
||||
In the realm of productivity tools, note-taking apps are VERY handy. Yes, you can use the open source [NixNote][1] to access [Evernote][2] notes, but it's still linked to the Evernote servers and still relies on a third party for security. And while you CAN export your Evernote notes from NixNote, the only format options are NixNote XML or PDF files.
|
||||
|
||||

|
||||
|
||||
Enter [Joplin][3]. Joplin is a NodeJS application that runs and stores notes locally, allows you to encrypt your notes and supports multiple sync methods. Joplin can run as a console or graphical application on Windows, Mac, and Linux. Joplin also has mobile apps for Android and iOS, meaning you can take your notes with you without a major hassle. Joplin even allows you to format notes with Markdown, HTML, or plain text.
|
||||
|
||||

|
||||
|
||||
One really nice thing about Joplin is it supports two kinds of notes: plain notes and to-do notes. Plain notes are what you expect—documents containing text. To-do notes, on the other hand, have a checkbox in the notes list that allows you to mark them "done." And since the to-do note is still a note, you can include lists, documentation, and additional to-do items in a to-do note.
|
||||
|
||||
When using the GUI, you can toggle editor views between plain text, WYSIWYG, and a split screen showing both the source text and the rendered view. You can also specify an external editor in the GUI, making it easy to update notes with Vim, Emacs, or any other editor capable of handling text documents.
|
||||
|
||||
![Joplin console version][5]
|
||||
|
||||
Joplin in the console.
|
||||
|
||||
The console interface is absolutely fantastic. While it lacks a WYSIWYG editor, it defaults to the text editor for your login. It also has a powerful command mode that allows you to do almost everything you can do in the GUI version. And it renders Markdown correctly in the viewer.
|
||||
|
||||
You can group notes in notebooks and tag notes for easy grouping across your notebooks. And it even has built-in search, so you can find things if you forget where you put them.
|
||||
|
||||
Overall, Joplin is a first-class note-taking app ([and a great alternative to Evernote][6]) that will help you be organized and more productive over the next year.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/1/productivity-tool-joplin
|
||||
|
||||
作者:[Kevin Sonney][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/ksonney (Kevin Sonney)
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: http://nixnote.org/NixNote-Home/
|
||||
[2]: https://evernote.com/
|
||||
[3]: https://joplin.cozic.net/
|
||||
[4]: https://opensource.com/article/19/1/file/419776
|
||||
[5]: https://opensource.com/sites/default/files/uploads/joplin-2_0.png (Joplin console version)
|
||||
[6]: https://opensource.com/article/17/12/joplin-open-source-evernote-alternative
|
||||
@@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (MjSeven)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How To Move Multiple File Types Simultaneously From Commandline)
|
||||
[#]: via: (https://www.ostechnix.com/how-to-move-multiple-file-types-simultaneously-from-commandline/)
|
||||
[#]: author: (SK https://www.ostechnix.com/author/sk/)
|
||||
|
||||
How To Move Multiple File Types Simultaneously From Commandline
|
||||
======
|
||||
|
||||

|
||||
|
||||
The other day I was wondering how can I move (not copy) multiple file types from directory to another. I already knew how to [**find and copy certain type of files from one directory to another**][1]. But, I don’t know how to move multiple file types simultaneously. If you’re ever in a situation like this, I know a easy way to do it from commandline in Unix-like systems.
|
||||
|
||||
### Move Multiple File Types Simultaneously
|
||||
|
||||
Picture this scenario.You have multiple type of files, for example .pdf, .doc, .mp3, .mp4, .txt etc., on a directory named **‘dir1’**. Let us take a look at the dir1 contents:
|
||||
|
||||
```
|
||||
$ ls dir1
|
||||
file.txt image.jpg mydoc.doc personal.pdf song.mp3 video.mp4
|
||||
```
|
||||
|
||||
You want to move some of the file types (not all of them) to different location. For example, let us say you want to move doc, pdf and txt files only to another directory named **‘dir2’** in one go.
|
||||
|
||||
To copy .doc, .pdf and .txt files from dir1 to dir2 simultaneously, the command would be:
|
||||
|
||||
```
|
||||
$ mv dir1/*.{doc,pdf,txt} dir2/
|
||||
```
|
||||
|
||||
It’s easy, isn’t it?
|
||||
|
||||
Now, let us check the contents of dir2:
|
||||
|
||||
```
|
||||
$ ls dir2/
|
||||
file.txt mydoc.doc personal.pdf
|
||||
```
|
||||
|
||||
See? Only the file types .doc, .pdf and .txt from dir1 have been moved to dir2.
|
||||
|
||||
![][3]
|
||||
|
||||
You can add as many file types as you want to inside curly braces in the above command to move them across different directories. The above command just works fine for me on Bash.
|
||||
|
||||
Another way to move multiple file types is go to the source directory i.e dir1 in our case:
|
||||
|
||||
```
|
||||
$ cd ~/dir1
|
||||
```
|
||||
|
||||
And, move file types of your choice to the destination (E.g dir2) as shown below.
|
||||
|
||||
```
|
||||
$ mv *.doc *.txt *.pdf /home/sk/dir2/
|
||||
```
|
||||
|
||||
To move all files having a particular extension, for example **.doc** only, run:
|
||||
|
||||
```
|
||||
$ mv dir1/*.doc dir2/
|
||||
```
|
||||
|
||||
For more details, refer man pages.
|
||||
|
||||
```
|
||||
$ man mv
|
||||
```
|
||||
|
||||
Moving a few number of same or different file types is easy! You could do this with couple mouse clicks in GUI mode or use a one-liner command in CLI mode. However, If you have thousands of different file types in a directory and wanted to move multiple file types to different directory in one go, it would be a cumbersome task. To me, the above method did the job easily! If you know any other one-liner commands to move multiple file types at a time, please share it in the comment section below. I will check and update the guide accordingly.
|
||||
|
||||
And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-move-multiple-file-types-simultaneously-from-commandline/
|
||||
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.ostechnix.com/author/sk/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.ostechnix.com/find-copy-certain-type-files-one-directory-another-linux/
|
||||
[2]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[3]: http://www.ostechnix.com/wp-content/uploads/2019/01/mv-command.gif
|
||||
@@ -1,632 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (qhwdw)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Build a Netboot Server, Part 4)
|
||||
[#]: via: (https://fedoramagazine.org/how-to-build-a-netboot-server-part-4/)
|
||||
[#]: author: (Gregory Bartholomew https://fedoramagazine.org/author/glb/)
|
||||
|
||||
How to Build a Netboot Server, Part 4
|
||||
======
|
||||

|
||||
|
||||
One significant limitation of the netboot server built in this series is the operating system image being served is read-only. Some use cases may require the end user to modify the image. For example, an instructor may want to have the students install and configure software packages like MariaDB and Node.js as part of their course walk-through.
|
||||
|
||||
An added benefit of writable netboot images is the end user’s “personalized” operating system can follow them to different workstations they may use at later times.
|
||||
|
||||
### Change the Bootmenu Application to use HTTPS
|
||||
|
||||
Create a self-signed certificate for the bootmenu application:
|
||||
|
||||
```
|
||||
$ sudo -i
|
||||
# MY_NAME=$(</etc/hostname)
|
||||
# MY_TLSD=/opt/bootmenu/tls
|
||||
# mkdir $MY_TLSD
|
||||
# openssl req -newkey rsa:2048 -nodes -keyout $MY_TLSD/$MY_NAME.key -x509 -days 3650 -out $MY_TLSD/$MY_NAME.pem
|
||||
```
|
||||
|
||||
Verify your certificate’s values. Make sure the “CN” value in the “Subject” line matches the DNS name that your iPXE clients use to connect to your bootmenu server:
|
||||
|
||||
```
|
||||
# openssl x509 -text -noout -in $MY_TLSD/$MY_NAME.pem
|
||||
```
|
||||
|
||||
Next, update the bootmenu application’s listen directive to use the HTTPS port and the newly created certificate and key:
|
||||
|
||||
```
|
||||
# sed -i "s#listen => .*#listen => ['https://$MY_NAME:443?cert=$MY_TLSD/$MY_NAME.pem\&key=$MY_TLSD/$MY_NAME.key\&ciphers=AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA'],#" /opt/bootmenu/bootmenu.conf
|
||||
```
|
||||
|
||||
Note the ciphers have been restricted to [those currently supported by iPXE][1].
|
||||
|
||||
GnuTLS requires the “CAP_DAC_READ_SEARCH” capability, so add it to the bootmenu application’s systemd service:
|
||||
|
||||
```
|
||||
# sed -i '/^AmbientCapabilities=/ s/$/ CAP_DAC_READ_SEARCH/' /etc/systemd/system/bootmenu.service
|
||||
# sed -i 's/Serves iPXE Menus over HTTP/Serves iPXE Menus over HTTPS/' /etc/systemd/system/bootmenu.service
|
||||
# systemctl daemon-reload
|
||||
```
|
||||
|
||||
Now, add an exception for the bootmenu service to the firewall and restart the service:
|
||||
|
||||
```
|
||||
# MY_SUBNET=192.0.2.0
|
||||
# MY_PREFIX=24
|
||||
# firewall-cmd --add-rich-rule="rule family='ipv4' source address='$MY_SUBNET/$MY_PREFIX' service name='https' accept"
|
||||
# firewall-cmd --runtime-to-permanent
|
||||
# systemctl restart bootmenu.service
|
||||
```
|
||||
|
||||
Use wget to verify it’s working:
|
||||
|
||||
```
|
||||
$ MY_NAME=server-01.example.edu
|
||||
$ MY_TLSD=/opt/bootmenu/tls
|
||||
$ wget -q --ca-certificate=$MY_TLSD/$MY_NAME.pem -O - https://$MY_NAME/menu
|
||||
```
|
||||
|
||||
### Add HTTPS to iPXE
|
||||
|
||||
Update init.ipxe to use HTTPS. Then recompile the ipxe bootloader with options to embed and trust the self-signed certificate you created for the bootmenu application:
|
||||
|
||||
```
|
||||
$ echo '#define DOWNLOAD_PROTO_HTTPS' >> $HOME/ipxe/src/config/local/general.h
|
||||
$ sed -i 's/^chain http:/chain https:/' $HOME/ipxe/init.ipxe
|
||||
$ cp $MY_TLSD/$MY_NAME.pem $HOME/ipxe
|
||||
$ cd $HOME/ipxe/src
|
||||
$ make clean
|
||||
$ make bin-x86_64-efi/ipxe.efi EMBED=../init.ipxe CERT="../$MY_NAME.pem" TRUST="../$MY_NAME.pem"
|
||||
```
|
||||
|
||||
You can now copy the HTTPS-enabled iPXE bootloader out to your clients and test that everything is working correctly:
|
||||
|
||||
```
|
||||
$ cp $HOME/ipxe/src/bin-x86_64-efi/ipxe.efi $HOME/esp/efi/boot/bootx64.efi
|
||||
```
|
||||
|
||||
### Add User Authentication to Mojolicious
|
||||
|
||||
Create a PAM service definition for the bootmenu application:
|
||||
|
||||
```
|
||||
# dnf install -y pam_krb5
|
||||
# echo 'auth required pam_krb5.so' > /etc/pam.d/bootmenu
|
||||
```
|
||||
|
||||
Add a library to the bootmenu application that uses the Authen-PAM perl module to perform user authentication:
|
||||
|
||||
```
|
||||
# dnf install -y perl-Authen-PAM;
|
||||
# MY_MOJO=/opt/bootmenu
|
||||
# mkdir $MY_MOJO/lib
|
||||
# cat << 'END' > $MY_MOJO/lib/PAM.pm
|
||||
package PAM;
|
||||
|
||||
use Authen::PAM;
|
||||
|
||||
sub auth {
|
||||
my $success = 0;
|
||||
|
||||
my $username = shift;
|
||||
my $password = shift;
|
||||
|
||||
my $callback = sub {
|
||||
my @res;
|
||||
while (@_) {
|
||||
my $code = shift;
|
||||
my $msg = shift;
|
||||
my $ans = "";
|
||||
|
||||
$ans = $username if ($code == PAM_PROMPT_ECHO_ON());
|
||||
$ans = $password if ($code == PAM_PROMPT_ECHO_OFF());
|
||||
|
||||
push @res, (PAM_SUCCESS(), $ans);
|
||||
}
|
||||
push @res, PAM_SUCCESS();
|
||||
|
||||
return @res;
|
||||
};
|
||||
|
||||
my $pamh = new Authen::PAM('bootmenu', $username, $callback);
|
||||
|
||||
{
|
||||
last unless ref $pamh;
|
||||
last unless $pamh->pam_authenticate() == PAM_SUCCESS;
|
||||
$success = 1;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
return 1;
|
||||
END
|
||||
```
|
||||
|
||||
The above code is taken almost verbatim from the Authen::PAM::FAQ man page.
|
||||
|
||||
Redefine the bootmenu application so it returns a netboot template only if a valid username and password are supplied:
|
||||
|
||||
```
|
||||
# cat << 'END' > $MY_MOJO/bootmenu.pl
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use lib 'lib';
|
||||
|
||||
use PAM;
|
||||
use Mojolicious::Lite;
|
||||
use Mojolicious::Plugins;
|
||||
use Mojo::Util ('url_unescape');
|
||||
|
||||
plugin 'Config';
|
||||
|
||||
get '/menu';
|
||||
get '/boot' => sub {
|
||||
my $c = shift;
|
||||
|
||||
my $instance = $c->param('instance');
|
||||
my $username = $c->param('username');
|
||||
my $password = $c->param('password');
|
||||
|
||||
my $template = 'menu';
|
||||
|
||||
{
|
||||
last unless $instance =~ /^fc[[:digit:]]{2}$/;
|
||||
last unless $username =~ /^[[:alnum:]]+$/;
|
||||
last unless PAM::auth($username, url_unescape($password));
|
||||
$template = $instance;
|
||||
}
|
||||
|
||||
return $c->render(template => $template);
|
||||
};
|
||||
|
||||
app->start;
|
||||
END
|
||||
```
|
||||
|
||||
The bootmenu application now looks for the lib directory relative to its WorkingDirectory. However, by default the working directory is set to the root directory of the server for systemd units. Therefore, you must update the systemd unit to set WorkingDirectory to the root of the bootmenu application instead:
|
||||
|
||||
```
|
||||
# sed -i "/^RuntimeDirectory=/ a WorkingDirectory=$MY_MOJO" /etc/systemd/system/bootmenu.service
|
||||
# systemctl daemon-reload
|
||||
```
|
||||
|
||||
Update the templates to work with the redefined bootmenu application:
|
||||
|
||||
```
|
||||
# cd $MY_MOJO/templates
|
||||
# MY_BOOTMENU_SERVER=$(</etc/hostname)
|
||||
# MY_FEDORA_RELEASES="28 29"
|
||||
# for i in $MY_FEDORA_RELEASES; do echo '#!ipxe' > fc$i.html.ep; grep "^kernel\|initrd" menu.html.ep | grep "fc$i" >> fc$i.html.ep; echo "boot || chain https://$MY_BOOTMENU_SERVER/menu" >> fc$i.html.ep; sed -i "/^:f$i$/,/^boot /c :f$i\nlogin\nchain https://$MY_BOOTMENU_SERVER/boot?instance=fc$i\&username=\${username}\&password=\${password:uristring} || goto failed" menu.html.ep; done
|
||||
```
|
||||
|
||||
The result of the last command above should be three files similar to the following:
|
||||
|
||||
**menu.html.ep** :
|
||||
|
||||
```
|
||||
#!ipxe
|
||||
|
||||
set timeout 5000
|
||||
|
||||
:menu
|
||||
menu iPXE Boot Menu
|
||||
item --key 1 lcl 1. Microsoft Windows 10
|
||||
item --key 2 f29 2. RedHat Fedora 29
|
||||
item --key 3 f28 3. RedHat Fedora 28
|
||||
choose --timeout ${timeout} --default lcl selected || goto shell
|
||||
set timeout 0
|
||||
goto ${selected}
|
||||
|
||||
:failed
|
||||
echo boot failed, dropping to shell...
|
||||
goto shell
|
||||
|
||||
:shell
|
||||
echo type 'exit' to get the back to the menu
|
||||
set timeout 0
|
||||
shell
|
||||
goto menu
|
||||
|
||||
:lcl
|
||||
exit
|
||||
|
||||
:f29
|
||||
login
|
||||
chain https://server-01.example.edu/boot?instance=fc29&username=${username}&password=${password:uristring} || goto failed
|
||||
|
||||
:f28
|
||||
login
|
||||
chain https://server-01.example.edu/boot?instance=fc28&username=${username}&password=${password:uristring} || goto failed
|
||||
```
|
||||
|
||||
**fc29.html.ep** :
|
||||
|
||||
```
|
||||
#!ipxe
|
||||
kernel --name kernel.efi ${prefix}/vmlinuz-4.19.5-300.fc29.x86_64 initrd=initrd.img ro ip=dhcp rd.peerdns=0 nameserver=192.0.2.91 nameserver=192.0.2.92 root=/dev/disk/by-path/ip-192.0.2.158:3260-iscsi-iqn.edu.example.server-01:fc29-lun-1 netroot=iscsi:192.0.2.158::::iqn.edu.example.server-01:fc29 console=tty0 console=ttyS0,115200n8 audit=0 selinux=0 quiet
|
||||
initrd --name initrd.img ${prefix}/initramfs-4.19.5-300.fc29.x86_64.img
|
||||
boot || chain https://server-01.example.edu/menu
|
||||
```
|
||||
|
||||
**fc28.html.ep** :
|
||||
|
||||
```
|
||||
#!ipxe
|
||||
kernel --name kernel.efi ${prefix}/vmlinuz-4.19.3-200.fc28.x86_64 initrd=initrd.img ro ip=dhcp rd.peerdns=0 nameserver=192.0.2.91 nameserver=192.0.2.92 root=/dev/disk/by-path/ip-192.0.2.158:3260-iscsi-iqn.edu.example.server-01:fc28-lun-1 netroot=iscsi:192.0.2.158::::iqn.edu.example.server-01:fc28 console=tty0 console=ttyS0,115200n8 audit=0 selinux=0 quiet
|
||||
initrd --name initrd.img ${prefix}/initramfs-4.19.3-200.fc28.x86_64.img
|
||||
boot || chain https://server-01.example.edu/menu
|
||||
```
|
||||
|
||||
Now, restart the bootmenu application and verify authentication is working:
|
||||
|
||||
```
|
||||
# systemctl restart bootmenu.service
|
||||
```
|
||||
|
||||
### Make the iSCSI Target Writeable
|
||||
|
||||
Now that user authentication works through iPXE, you can create per-user, writeable overlays on top of the read-only image on demand when users connect. Using a [copy-on-write][2] overlay has three advantages over simply copying the original image file for each user:
|
||||
|
||||
1. The copy can be created very quickly. This allows creation on-demand.
|
||||
2. The copy does not increase the disk usage on the server. Only what the user writes to their personal copy of the image is stored in addition to the original image.
|
||||
3. Since most sectors for each copy are the same sectors on the server’s storage, they’ll likely already be loaded in RAM when subsequent users access their copies of the operating system. This improves the server’s performance because RAM is faster than disk I/O.
|
||||
|
||||
|
||||
|
||||
One potential pitfall of using copy-on-write is that once overlays are created, the images on which they are overlayed must not be changed. If they are changed, all the overlays will be corrupted. Then the overlays must be deleted and replaced with new, blank overlays. Even simply mounting the image file in read-write mode can cause sufficient filesystem updates to corrupt the overlays.
|
||||
|
||||
Due to the potential for the overlays to be corrupted if the original image is modified, mark the original image as immutable by running:
|
||||
|
||||
```
|
||||
# chattr +i </path/to/file>
|
||||
```
|
||||
|
||||
You can use lsattr </path/to/file> to view the status of the immutable flag and use to chattr -i </path/to/file> unset the immutable flag. While the immutable flag is set, even the root user or a system process running as root cannot modify or delete the file.
|
||||
|
||||
Begin by stopping the tgtd.service so you can change the image files:
|
||||
|
||||
```
|
||||
# systemctl stop tgtd.service
|
||||
```
|
||||
|
||||
It’s normal for this command to take a minute or so to stop when there are connections still open.
|
||||
|
||||
Now, remove the read-only iSCSI export. Then update the readonly-root configuration file in the template so the image is no longer read-only:
|
||||
|
||||
```
|
||||
# MY_FC=fc29
|
||||
# rm -f /etc/tgt/conf.d/$MY_FC.conf
|
||||
# TEMP_MNT=$(mktemp -d)
|
||||
# mount /$MY_FC.img $TEMP_MNT
|
||||
# sed -i 's/^READONLY=yes$/READONLY=no/' $TEMP_MNT/etc/sysconfig/readonly-root
|
||||
# sed -i 's/^Storage=volatile$/#Storage=auto/' $TEMP_MNT/etc/systemd/journald.conf
|
||||
# umount $TEMP_MNT
|
||||
```
|
||||
|
||||
Journald was changed from logging to volatile memory back to its default (log to disk if /var/log/journal exists) because a user reported his clients would freeze with an out-of-memory error due to an application generating excessive system logs. The downside to setting logging to disk is that extra write traffic is generated by the clients, and might burden your netboot server with unnecessary I/O. You should decide which option — log to memory or log to disk — is preferable depending on your environment.
|
||||
|
||||
Since you won’t make any further changes to the template image, set the immutable flag on it and restart the tgtd.service:
|
||||
|
||||
```
|
||||
# chattr +i /$MY_FC.img
|
||||
# systemctl start tgtd.service
|
||||
```
|
||||
|
||||
Now, update the bootmenu application:
|
||||
|
||||
```
|
||||
# cat << 'END' > $MY_MOJO/bootmenu.pl
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use lib 'lib';
|
||||
|
||||
use PAM;
|
||||
use Mojolicious::Lite;
|
||||
use Mojolicious::Plugins;
|
||||
use Mojo::Util ('url_unescape');
|
||||
|
||||
plugin 'Config';
|
||||
|
||||
get '/menu';
|
||||
get '/boot' => sub {
|
||||
my $c = shift;
|
||||
|
||||
my $instance = $c->param('instance');
|
||||
my $username = $c->param('username');
|
||||
my $password = $c->param('password');
|
||||
|
||||
my $chapscrt;
|
||||
my $template = 'menu';
|
||||
|
||||
{
|
||||
last unless $instance =~ /^fc[[:digit:]]{2}$/;
|
||||
last unless $username =~ /^[[:alnum:]]+$/;
|
||||
last unless PAM::auth($username, url_unescape($password));
|
||||
last unless $chapscrt = `sudo scripts/mktgt $instance $username`;
|
||||
$template = $instance;
|
||||
}
|
||||
|
||||
return $c->render(template => $template, username => $username, chapscrt => $chapscrt);
|
||||
};
|
||||
|
||||
app->start;
|
||||
END
|
||||
```
|
||||
|
||||
This new version of the bootmenu application calls a custom mktgt script which, on success, returns a random [CHAP][3] password for each new iSCSI target that it creates. The CHAP password prevents one user from mounting another user’s iSCSI target by indirect means. The app only returns the correct iSCSI target password to a user who has successfully authenticated.
|
||||
|
||||
The mktgt script is prefixed with sudo because it needs root privileges to create the target.
|
||||
|
||||
The $username and $chapscrt variables also pass to the render command so they can be incorporated into the templates returned to the user when necessary.
|
||||
|
||||
Next, update our boot templates so they can read the username and chapscrt variables and pass them along to the end user. Also update the templates to mount the root filesystem in rw (read-write) mode:
|
||||
|
||||
```
|
||||
# cd $MY_MOJO/templates
|
||||
# sed -i "s/:$MY_FC/:$MY_FC-<%= \$username %>/g" $MY_FC.html.ep
|
||||
# sed -i "s/ netroot=iscsi:/ netroot=iscsi:<%= \$username %>:<%= \$chapscrt %>@/" $MY_FC.html.ep
|
||||
# sed -i "s/ ro / rw /" $MY_FC.html.ep
|
||||
```
|
||||
|
||||
After running the above commands, you should have boot templates like the following:
|
||||
|
||||
```
|
||||
#!ipxe
|
||||
kernel --name kernel.efi ${prefix}/vmlinuz-4.19.5-300.fc29.x86_64 initrd=initrd.img rw ip=dhcp rd.peerdns=0 nameserver=192.0.2.91 nameserver=192.0.2.92 root=/dev/disk/by-path/ip-192.0.2.158:3260-iscsi-iqn.edu.example.server-01:fc29-<%= $username %>-lun-1 netroot=iscsi:<%= $username %>:<%= $chapscrt %>@192.0.2.158::::iqn.edu.example.server-01:fc29-<%= $username %> console=tty0 console=ttyS0,115200n8 audit=0 selinux=0 quiet
|
||||
initrd --name initrd.img ${prefix}/initramfs-4.19.5-300.fc29.x86_64.img
|
||||
boot || chain https://server-01.example.edu/menu
|
||||
```
|
||||
|
||||
NOTE: If you need to view the boot template after the variables have been [interpolated][4], you can insert the “shell” command on its own line just before the “boot” command. Then, when you netboot your client, iPXE gives you an interactive shell where you can enter “imgstat” to view the parameters being passed to the kernel. If everything looks correct, you can type “exit” to leave the shell and continue the boot process.
|
||||
|
||||
Now allow the bootmenu user to run the mktgt script (and only that script) as root via sudo:
|
||||
|
||||
```
|
||||
# echo "bootmenu ALL = NOPASSWD: $MY_MOJO/scripts/mktgt *" > /etc/sudoers.d/bootmenu
|
||||
```
|
||||
|
||||
The bootmenu user should not have write access to the mktgt script or any other files under its home directory. All the files under /opt/bootmenu should be owned by root, and should not be writable by any user other than root.
|
||||
|
||||
Sudo does not work well with systemd’s DynamicUser option, so create a normal user account and set the systemd service to run as that user:
|
||||
|
||||
```
|
||||
# useradd -r -c 'iPXE Boot Menu Service' -d /opt/bootmenu -s /sbin/nologin bootmenu
|
||||
# sed -i 's/^DynamicUser=true$/User=bootmenu/' /etc/systemd/system/bootmenu.service
|
||||
# systemctl daemon-reload
|
||||
```
|
||||
|
||||
Finally, create a directory for the copy-on-write overlays and create the mktgt script that manages the iSCSI targets and their overlayed backing stores:
|
||||
|
||||
```
|
||||
# mkdir /$MY_FC.cow
|
||||
# mkdir $MY_MOJO/scripts
|
||||
# cat << 'END' > $MY_MOJO/scripts/mktgt
|
||||
#!/usr/bin/env perl
|
||||
|
||||
# if another instance of this script is running, wait for it to finish
|
||||
"$ENV{FLOCKER}" eq 'MKTGT' or exec "env FLOCKER=MKTGT flock /tmp $0 @ARGV";
|
||||
|
||||
# use "RETURN" to print to STDOUT; everything else goes to STDERR by default
|
||||
open(RETURN, '>&', STDOUT);
|
||||
open(STDOUT, '>&', STDERR);
|
||||
|
||||
my $instance = shift or die "instance not provided";
|
||||
my $username = shift or die "username not provided";
|
||||
|
||||
my $img = "/$instance.img";
|
||||
my $dir = "/$instance.cow";
|
||||
my $top = "$dir/$username";
|
||||
|
||||
-f "$img" or die "'$img' is not a file";
|
||||
-d "$dir" or die "'$dir' is not a directory";
|
||||
|
||||
my $base;
|
||||
die unless $base = `losetup --show --read-only --nooverlap --find $img`;
|
||||
chomp $base;
|
||||
|
||||
my $size;
|
||||
die unless $size = `blockdev --getsz $base`;
|
||||
chomp $size;
|
||||
|
||||
# create the per-user sparse file if it does not exist
|
||||
if (! -e "$top") {
|
||||
die unless system("dd if=/dev/zero of=$top status=none bs=512 count=0 seek=$size") == 0;
|
||||
}
|
||||
|
||||
# create the copy-on-write overlay if it does not exist
|
||||
my $cow="$instance-$username";
|
||||
my $dev="/dev/mapper/$cow";
|
||||
if (! -e "$dev") {
|
||||
my $over;
|
||||
die unless $over = `losetup --show --nooverlap --find $top`;
|
||||
chomp $over;
|
||||
die unless system("echo 0 $size snapshot $base $over p 8 | dmsetup create $cow") == 0;
|
||||
}
|
||||
|
||||
my $tgtadm = '/usr/sbin/tgtadm --lld iscsi';
|
||||
|
||||
# get textual representations of the iscsi targets
|
||||
my $text = `$tgtadm --op show --mode target`;
|
||||
my @targets = $text =~ /(?:^T.*\n)(?:^ .*\n)*/mg;
|
||||
|
||||
# convert the textual representations into a hash table
|
||||
my $targets = {};
|
||||
foreach (@targets) {
|
||||
my $tgt;
|
||||
my $sid;
|
||||
|
||||
foreach (split /\n/) {
|
||||
/^Target (\d+)(?{ $tgt = $targets->{$^N} = [] })/;
|
||||
/I_T nexus: (\d+)(?{ $sid = $^N })/;
|
||||
/Connection: (\d+)(?{ push @{$tgt}, [ $sid, $^N ] })/;
|
||||
}
|
||||
}
|
||||
|
||||
my $hostname;
|
||||
die unless $hostname = `hostname`;
|
||||
chomp $hostname;
|
||||
|
||||
my $target = 'iqn.' . join('.', reverse split('\.', $hostname)) . ":$cow";
|
||||
|
||||
# find the target id corresponding to the provided target name and
|
||||
# close any existing connections to it
|
||||
my $tid = 0;
|
||||
foreach (@targets) {
|
||||
next unless /^Target (\d+)(?{ $tid = $^N }): $target$/m;
|
||||
foreach (@{$targets->{$tid}}) {
|
||||
die unless system("$tgtadm --op delete --mode conn --tid $tid --sid $_->[0] --cid $_->[1]") == 0;
|
||||
}
|
||||
}
|
||||
|
||||
# create a new target if an existing one was not found
|
||||
if ($tid == 0) {
|
||||
# find an available target id
|
||||
my @ids = (0, sort keys %{$targets});
|
||||
$tid = 1; while ($ids[$tid]==$tid) { $tid++ }
|
||||
|
||||
# create the target
|
||||
die unless -e "$dev";
|
||||
die unless system("$tgtadm --op new --mode target --tid $tid --targetname $target") == 0;
|
||||
die unless system("$tgtadm --op new --mode logicalunit --tid $tid --lun 1 --backing-store $dev") == 0;
|
||||
die unless system("$tgtadm --op bind --mode target --tid $tid --initiator-address ALL") == 0;
|
||||
}
|
||||
|
||||
# (re)set the provided target's chap password
|
||||
my $password = join('', map(chr(int(rand(26))+65), 1..8));
|
||||
my $accounts = `$tgtadm --op show --mode account`;
|
||||
if ($accounts =~ / $username$/m) {
|
||||
die unless system("$tgtadm --op delete --mode account --user $username") == 0;
|
||||
}
|
||||
die unless system("$tgtadm --op new --mode account --user $username --password $password") == 0;
|
||||
die unless system("$tgtadm --op bind --mode account --tid $tid --user $username") == 0;
|
||||
|
||||
# return the new password to the iscsi target on stdout
|
||||
print RETURN $password;
|
||||
END
|
||||
# chmod +x $MY_MOJO/scripts/mktgt
|
||||
```
|
||||
|
||||
The above script does five things:
|
||||
|
||||
1. It creates the /<instance>.cow/<username> sparse file if it does not already exist.
|
||||
2. It creates the /dev/mapper/<instance>-<username> device node that serves as the copy-on-write backing store for the iSCSI target if it does not already exist.
|
||||
3. It creates the iqn.<reverse-hostname>:<instance>-<username> iSCSI target if it does not exist. Or, if the target does exist, it closes any existing connections to it because the image can only be opened in read-write mode from one place at a time.
|
||||
4. It (re)sets the chap password on the iqn.<reverse-hostname>:<instance>-<username> iSCSI target to a new random value.
|
||||
5. It prints the new chap password on [standard output][5] if all of the previous tasks compeleted successfully.
|
||||
|
||||
|
||||
|
||||
You should be able to test the mktgt script from the command line by running it with valid test parameters. For example:
|
||||
|
||||
```
|
||||
# echo `$MY_MOJO/scripts/mktgt fc29 jsmith`
|
||||
```
|
||||
|
||||
When run from the command line, the mktgt script should print out either the eight-character random password for the iSCSI target if it succeeded or the line number on which something went wrong if it failed.
|
||||
|
||||
On occasion, you may want to delete an iSCSI target without having to stop the entire service. For example, a user might inadvertently corrupt their personal image, in which case you would need to systematically undo everything that the above mktgt script does so that the next time they log in they will get a copy of the original image.
|
||||
|
||||
Below is an rmtgt script that undoes, in reverse order, what the above mktgt script did:
|
||||
|
||||
```
|
||||
# mkdir $HOME/bin
|
||||
# cat << 'END' > $HOME/bin/rmtgt
|
||||
#!/usr/bin/env perl
|
||||
|
||||
@ARGV >= 2 or die "usage: $0 <instance> <username> [+d|+f]\n";
|
||||
|
||||
my $instance = shift;
|
||||
my $username = shift;
|
||||
|
||||
my $rmd = ($ARGV[0] eq '+d'); #remove device node if +d flag is set
|
||||
my $rmf = ($ARGV[0] eq '+f'); #remove sparse file if +f flag is set
|
||||
my $cow = "$instance-$username";
|
||||
|
||||
my $hostname;
|
||||
die unless $hostname = `hostname`;
|
||||
chomp $hostname;
|
||||
|
||||
my $tgtadm = '/usr/sbin/tgtadm';
|
||||
my $target = 'iqn.' . join('.', reverse split('\.', $hostname)) . ":$cow";
|
||||
|
||||
my $text = `$tgtadm --op show --mode target`;
|
||||
my @targets = $text =~ /(?:^T.*\n)(?:^ .*\n)*/mg;
|
||||
|
||||
my $targets = {};
|
||||
foreach (@targets) {
|
||||
my $tgt;
|
||||
my $sid;
|
||||
|
||||
foreach (split /\n/) {
|
||||
/^Target (\d+)(?{ $tgt = $targets->{$^N} = [] })/;
|
||||
/I_T nexus: (\d+)(?{ $sid = $^N })/;
|
||||
/Connection: (\d+)(?{ push @{$tgt}, [ $sid, $^N ] })/;
|
||||
}
|
||||
}
|
||||
|
||||
my $tid = 0;
|
||||
foreach (@targets) {
|
||||
next unless /^Target (\d+)(?{ $tid = $^N }): $target$/m;
|
||||
foreach (@{$targets->{$tid}}) {
|
||||
die unless system("$tgtadm --op delete --mode conn --tid $tid --sid $_->[0] --cid $_->[1]") == 0;
|
||||
}
|
||||
die unless system("$tgtadm --op delete --mode target --tid $tid") == 0;
|
||||
print "target $tid deleted\n";
|
||||
sleep 1;
|
||||
}
|
||||
|
||||
my $dev = "/dev/mapper/$cow";
|
||||
if ($rmd or ($rmf and -e $dev)) {
|
||||
die unless system("dmsetup remove $cow") == 0;
|
||||
print "device node $dev deleted\n";
|
||||
}
|
||||
|
||||
if ($rmf) {
|
||||
my $sf = "/$instance.cow/$username";
|
||||
die "sparse file $sf not found" unless -e "$sf";
|
||||
die unless system("rm -f $sf") == 0;
|
||||
die unless not -e "$sf";
|
||||
print "sparse file $sf deleted\n";
|
||||
}
|
||||
END
|
||||
# chmod +x $HOME/bin/rmtgt
|
||||
```
|
||||
|
||||
For example, to use the above script to completely remove the fc29-jsmith target including its backing store device node and its sparse file, run the following:
|
||||
|
||||
```
|
||||
# rmtgt fc29 jsmith +f
|
||||
```
|
||||
|
||||
Once you’ve verified that the mktgt script is working properly, you can restart the bootmenu service. The next time someone netboots, they should receive a personal copy of the the netboot image they can write to:
|
||||
|
||||
```
|
||||
# systemctl restart bootmenu.service
|
||||
```
|
||||
|
||||
Users should now be able to modify the root filesystem as demonstrated in the below screenshot:
|
||||
|
||||
![][6]
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/how-to-build-a-netboot-server-part-4/
|
||||
|
||||
作者:[Gregory Bartholomew][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/glb/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: http://ipxe.org/crypto
|
||||
[2]: https://en.wikipedia.org/wiki/Copy-on-write
|
||||
[3]: https://en.wikipedia.org/wiki/Challenge-Handshake_Authentication_Protocol
|
||||
[4]: https://en.wikipedia.org/wiki/String_interpolation
|
||||
[5]: https://en.wikipedia.org/wiki/Standard_streams
|
||||
[6]: https://fedoramagazine.org/wp-content/uploads/2018/11/netboot-fix-pam_mount-1024x819.png
|
||||
@@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (jrglinux)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Linux Tools: The Meaning of Dot)
|
||||
[#]: via: (https://www.linux.com/blog/learn/2019/1/linux-tools-meaning-dot)
|
||||
[#]: author: (Paul Brown https://www.linux.com/users/bro66)
|
||||
|
||||
Linux Tools: The Meaning of Dot
|
||||
======
|
||||
|
||||

|
||||
|
||||
Let's face it: writing one-liners and scripts using shell commands can be confusing. Many of the names of the tools at your disposal are far from obvious in terms of what they do ( _grep_ , _tee_ and _awk_ , anyone?) and, when you combine two or more, the resulting "sentence" looks like some kind of alien gobbledygook.
|
||||
|
||||
None of the above is helped by the fact that many of the symbols you use to build a chain of instructions can mean different things depending on their context.
|
||||
|
||||
### Location, location, location
|
||||
|
||||
Take the humble dot (`.`) for example. Used with instructions that are expecting the name of a directory, it means "this directory" so this:
|
||||
|
||||
```
|
||||
find . -name "*.jpg"
|
||||
```
|
||||
|
||||
translates to " _find in this directory (and all its subdirectories) files that have names that end in`.jpg`_ ".
|
||||
|
||||
Both `ls .` and `cd .` act as expected, so they list and "change" to the current directory, respectively, although including the dot in these two cases is not necessary.
|
||||
|
||||
Two dots, one after the other, in the same context (i.e., when your instruction is expecting a directory path) means " _the directory immediately above the current one_ ". If you are in _/home/your_directory_ and run
|
||||
|
||||
```
|
||||
cd ..
|
||||
```
|
||||
|
||||
you will be taken to _/home_. So, you may think this still kind of fits into the “dots represent nearby directories” narrative and is not complicated at all, right?
|
||||
|
||||
How about this, then? If you use a dot at the beginning of a directory or file, it means the directory or file will be hidden:
|
||||
|
||||
```
|
||||
$ touch somedir/file01.txt somedir/file02.txt somedir/.secretfile.txt
|
||||
$ ls -l somedir/
|
||||
total 0
|
||||
-rw-r--r-- 1 paul paul 0 Jan 13 19:57 file01.txt
|
||||
-rw-r--r-- 1 paul paul 0 Jan 13 19:57 file02.txt
|
||||
$ # Note how there is no .secretfile.txt in the listing above
|
||||
$ ls -la somedir/
|
||||
total 8
|
||||
drwxr-xr-x 2 paul paul 4096 Jan 13 19:57 .
|
||||
drwx------ 48 paul paul 4096 Jan 13 19:57 ..
|
||||
-rw-r--r-- 1 paul paul 0 Jan 13 19:57 file01.txt
|
||||
-rw-r--r-- 1 paul paul 0 Jan 13 19:57 file02.txt
|
||||
-rw-r--r-- 1 paul paul 0 Jan 13 19:57 .secretfile.txt
|
||||
$ # The -a option tells ls to show "all" files, including the hidden ones
|
||||
```
|
||||
|
||||
And then there's when you use `.` as a command. Yep! You heard me: `.` is a full-fledged command. It is a synonym of `source` and you use that to execute a file in the current shell, as opposed to running a script some other way (which usually mean Bash will spawn a new shell in which to run it).
|
||||
|
||||
Confused? Don't worry -- try this: Create a script called _myscript_ that contains the line
|
||||
|
||||
```
|
||||
myvar="Hello"
|
||||
```
|
||||
|
||||
and execute it the regular way, that is, with `sh myscript` (or by making the script executable with `chmod a+x myscript` and then running `./myscript`). Now try and see the contents of `myvar` with `echo $myvar` (spoiler: You will get nothing). This is because, when your script plunks " _Hello_ " into `myvar`, it does so in a separate bash shell instance. When the script ends, the spawned instance disappears and control returns to the original shell, where `myvar` never even existed.
|
||||
|
||||
However, if you run _myscript_ like this:
|
||||
|
||||
```
|
||||
. myscript
|
||||
```
|
||||
|
||||
`echo $myvar` will print _Hello_ to the command line.
|
||||
|
||||
You will often use the `.` (or `source`) command after making changes to your _.bashrc_ file, [like when you need to expand your `PATH` variable][1]. You use `.` to make the changes available immediately in your current shell instance.
|
||||
|
||||
### Double Trouble
|
||||
|
||||
Just like the seemingly insignificant single dot has more than one meaning, so has the double dot. Apart from pointing to the parent of the current directory, the double dot (`..`) is also used to build sequences.
|
||||
|
||||
Try this:
|
||||
|
||||
```
|
||||
echo {1..10}
|
||||
```
|
||||
|
||||
It will print out the list of numbers from 1 to 10. In this context, `..` means " _starting with the value on my left, count up to the value on my right_ ".
|
||||
|
||||
Now try this:
|
||||
|
||||
```
|
||||
echo {1..10..2}
|
||||
```
|
||||
|
||||
You'll get _1 3 5 7 9_. The `..2` part of the command tells Bash to print the sequence, but not one by one, but two by two. In other words, you'll get all the odd numbers from 1 to 10.
|
||||
|
||||
It works backwards, too:
|
||||
|
||||
```
|
||||
echo {10..1..2}
|
||||
```
|
||||
|
||||
You can also pad your numbers with 0s. Doing:
|
||||
|
||||
```
|
||||
echo {000..121..2}
|
||||
```
|
||||
|
||||
will print out every even number from 0 to 121 like this:
|
||||
|
||||
```
|
||||
000 002 004 006 ... 050 052 054 ... 116 118 120
|
||||
```
|
||||
|
||||
But how is this sequence-generating construct useful? Well, suppose one of your New Year's resolutions is to be more careful with your accounts. As part of that, you want to create directories in which to classify your digital invoices of the last 10 years:
|
||||
|
||||
```
|
||||
mkdir {2009..2019}_Invoices
|
||||
```
|
||||
|
||||
Job done.
|
||||
|
||||
Or maybe you have a hundreds of numbered files, say, frames extracted from a video clip, and, for whatever reason, you want to remove only every third frame between the frames 43 and 61:
|
||||
|
||||
```
|
||||
rm frame_{043..61..3}
|
||||
```
|
||||
|
||||
It is likely that, if you have more than 100 frames, they will be named with padded 0s and look like this:
|
||||
|
||||
```
|
||||
frame_000 frame_001 frame_002 ...
|
||||
```
|
||||
|
||||
That’s why you will use `043` in your command instead of just `43`.
|
||||
|
||||
### Curly~Wurly
|
||||
|
||||
Truth be told, the magic of sequences lies not so much in the double dot as in the sorcery of the curly braces (`{}`). Look how it works for letters, too. Doing:
|
||||
|
||||
```
|
||||
touch file_{a..z}.txt
|
||||
```
|
||||
|
||||
creates the files _file_a.txt_ through _file_z.txt_.
|
||||
|
||||
You must be careful, however. Using a sequence like `{Z..a}` will run through a bunch of non-alphanumeric characters (glyphs that are neither numbers or letters) that live between the uppercase alphabet and the lowercase one. Some of these glyphs are unprintable or have a special meaning of their own. Using them to generate names of files could lead to a whole bevy of unexpected and potentially unpleasant effects.
|
||||
|
||||
One final thing worth pointing out about sequences encased between `{...}` is that they can also contain lists of strings:
|
||||
|
||||
```
|
||||
touch {blahg, splurg, mmmf}_file.txt
|
||||
```
|
||||
|
||||
Creates _blahg_file.txt_ , _splurg_file.txt_ and _mmmf_file.txt_.
|
||||
|
||||
Of course, in other contexts, the curly braces have different meanings (surprise!). But that is the stuff of another article.
|
||||
|
||||
### Conclusion
|
||||
|
||||
Bash and the utilities you can run within it have been shaped over decades by system administrators looking for ways to solve very particular problems. To say that sysadmins and their ways are their own breed of special would be an understatement. Consequently, as opposed to other languages, Bash was not designed to be user-friendly, easy or even logical.
|
||||
|
||||
That doesn't mean it is not powerful -- quite the contrary. Bash's grammar and shell tools may be inconsistent and sprawling, but they also provide a dizzying range of ways to do everything you can possibly imagine. It is like having a toolbox where you can find everything from a power drill to a spoon, as well as a rubber duck, a roll of duct tape, and some nail clippers.
|
||||
|
||||
Apart from fascinating, it is also fun to discover all you can achieve directly from within the shell, so next time we will delve ever deeper into how you can build bigger and better Bash command lines.
|
||||
|
||||
Until then, have fun!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/blog/learn/2019/1/linux-tools-meaning-dot
|
||||
|
||||
作者:[Paul Brown][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.linux.com/users/bro66
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.linux.com/blog/learn/2018/12/bash-variables-environmental-and-otherwise
|
||||
@@ -0,0 +1,324 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Zipping files on Linux: the many variations and how to use them)
|
||||
[#]: via: (https://www.networkworld.com/article/3333640/linux/zipping-files-on-linux-the-many-variations-and-how-to-use-them.html)
|
||||
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
|
||||
|
||||
Zipping files on Linux: the many variations and how to use them
|
||||
======
|
||||

|
||||
|
||||
Some of us have been zipping files on Unix and Linux systems for many decades — to save some disk space and package files together for archiving. Even so, there are some interesting variations on zipping that not all of us have tried. So, in this post, we’re going to look at standard zipping and unzipping as well as some other interesting zipping options.
|
||||
|
||||
### The basic zip command
|
||||
|
||||
First, let’s look at the basic **zip** command. It uses what is essentially the same compression algorithm as **gzip** , but there are a couple important differences. For one thing, the gzip command is used only for compressing a single file where zip can both compress files and join them together into an archive. For another, the gzip command zips “in place”. In other words, it leaves a compressed file — not the original file alongside the compressed copy. Here's an example of gzip at work:
|
||||
|
||||
```
|
||||
$ gzip onefile
|
||||
$ ls -l
|
||||
-rw-rw-r-- 1 shs shs 10514 Jan 15 13:13 onefile.gz
|
||||
```
|
||||
|
||||
And here's zip. Notice how this command requires that a name be provided for the zipped archive where gzip simply uses the original file name and adds the .gz extension.
|
||||
|
||||
```
|
||||
$ zip twofiles.zip file*
|
||||
adding: file1 (deflated 82%)
|
||||
adding: file2 (deflated 82%)
|
||||
$ ls -l
|
||||
-rw-rw-r-- 1 shs shs 58021 Jan 15 13:25 file1
|
||||
-rw-rw-r-- 1 shs shs 58933 Jan 15 13:34 file2
|
||||
-rw-rw-r-- 1 shs shs 21289 Jan 15 13:35 twofiles.zip
|
||||
```
|
||||
|
||||
Notice also that the original files are still sitting there.
|
||||
|
||||
The amount of disk space that is saved (i.e., the degree of compression obtained) will depend on the content of each file. The variation in the example below is considerable.
|
||||
|
||||
```
|
||||
$ zip mybin.zip ~/bin/*
|
||||
adding: bin/1 (deflated 26%)
|
||||
adding: bin/append (deflated 64%)
|
||||
adding: bin/BoD_meeting (deflated 18%)
|
||||
adding: bin/cpuhog1 (deflated 14%)
|
||||
adding: bin/cpuhog2 (stored 0%)
|
||||
adding: bin/ff (deflated 32%)
|
||||
adding: bin/file.0 (deflated 1%)
|
||||
adding: bin/loop (deflated 14%)
|
||||
adding: bin/notes (deflated 23%)
|
||||
adding: bin/patterns (stored 0%)
|
||||
adding: bin/runme (stored 0%)
|
||||
adding: bin/tryme (deflated 13%)
|
||||
adding: bin/tt (deflated 6%)
|
||||
```
|
||||
|
||||
### The unzip command
|
||||
|
||||
The **unzip** command will recover the contents from a zip file and, as you'd likely suspect, leave the zip file intact, whereas a similar gunzip command would leave only the uncompressed file.
|
||||
|
||||
```
|
||||
$ unzip twofiles.zip
|
||||
Archive: twofiles.zip
|
||||
inflating: file1
|
||||
inflating: file2
|
||||
$ ls -l
|
||||
-rw-rw-r-- 1 shs shs 58021 Jan 15 13:25 file1
|
||||
-rw-rw-r-- 1 shs shs 58933 Jan 15 13:34 file2
|
||||
-rw-rw-r-- 1 shs shs 21289 Jan 15 13:35 twofiles.zip
|
||||
```
|
||||
|
||||
### The zipcloak command
|
||||
|
||||
The **zipcloak** command encrypts a zip file, prompting you to enter a password twice (to help ensure you don't "fat finger" it) and leaves the file in place. You can expect the file size to vary a little from the original.
|
||||
|
||||
```
|
||||
$ zipcloak twofiles.zip
|
||||
Enter password:
|
||||
Verify password:
|
||||
encrypting: file1
|
||||
encrypting: file2
|
||||
$ ls -l
|
||||
total 204
|
||||
-rw-rw-r-- 1 shs shs 58021 Jan 15 13:25 file1
|
||||
-rw-rw-r-- 1 shs shs 58933 Jan 15 13:34 file2
|
||||
-rw-rw-r-- 1 shs shs 21313 Jan 15 13:46 twofiles.zip <== slightly larger than
|
||||
unencrypted version
|
||||
```
|
||||
|
||||
Keep in mind that the original files are still sitting there unencrypted.
|
||||
|
||||
### The zipdetails command
|
||||
|
||||
The **zipdetails** command is going to show you details — a _lot_ of details about a zipped file, likely a lot more than you care to absorb. Even though we're looking at an encrypted file, zipdetails does display the file names along with file modification dates, user and group information, file length data, etc. Keep in mind that this is all "metadata." We don't see the contents of the files.
|
||||
|
||||
```
|
||||
$ zipdetails twofiles.zip
|
||||
|
||||
0000 LOCAL HEADER #1 04034B50
|
||||
0004 Extract Zip Spec 14 '2.0'
|
||||
0005 Extract OS 00 'MS-DOS'
|
||||
0006 General Purpose Flag 0001
|
||||
[Bit 0] 1 'Encryption'
|
||||
[Bits 1-2] 1 'Maximum Compression'
|
||||
0008 Compression Method 0008 'Deflated'
|
||||
000A Last Mod Time 4E2F6B24 'Tue Jan 15 13:25:08 2019'
|
||||
000E CRC F1B115BD
|
||||
0012 Compressed Length 00002904
|
||||
0016 Uncompressed Length 0000E2A5
|
||||
001A Filename Length 0005
|
||||
001C Extra Length 001C
|
||||
001E Filename 'file1'
|
||||
0023 Extra ID #0001 5455 'UT: Extended Timestamp'
|
||||
0025 Length 0009
|
||||
0027 Flags '03 mod access'
|
||||
0028 Mod Time 5C3E2584 'Tue Jan 15 13:25:08 2019'
|
||||
002C Access Time 5C3E27BB 'Tue Jan 15 13:34:35 2019'
|
||||
0030 Extra ID #0002 7875 'ux: Unix Extra Type 3'
|
||||
0032 Length 000B
|
||||
0034 Version 01
|
||||
0035 UID Size 04
|
||||
0036 UID 000003E8
|
||||
003A GID Size 04
|
||||
003B GID 000003E8
|
||||
003F PAYLOAD
|
||||
|
||||
2943 LOCAL HEADER #2 04034B50
|
||||
2947 Extract Zip Spec 14 '2.0'
|
||||
2948 Extract OS 00 'MS-DOS'
|
||||
2949 General Purpose Flag 0001
|
||||
[Bit 0] 1 'Encryption'
|
||||
[Bits 1-2] 1 'Maximum Compression'
|
||||
294B Compression Method 0008 'Deflated'
|
||||
294D Last Mod Time 4E2F6C56 'Tue Jan 15 13:34:44 2019'
|
||||
2951 CRC EC214569
|
||||
2955 Compressed Length 00002913
|
||||
2959 Uncompressed Length 0000E635
|
||||
295D Filename Length 0005
|
||||
295F Extra Length 001C
|
||||
2961 Filename 'file2'
|
||||
2966 Extra ID #0001 5455 'UT: Extended Timestamp'
|
||||
2968 Length 0009
|
||||
296A Flags '03 mod access'
|
||||
296B Mod Time 5C3E27C4 'Tue Jan 15 13:34:44 2019'
|
||||
296F Access Time 5C3E27BD 'Tue Jan 15 13:34:37 2019'
|
||||
2973 Extra ID #0002 7875 'ux: Unix Extra Type 3'
|
||||
2975 Length 000B
|
||||
2977 Version 01
|
||||
2978 UID Size 04
|
||||
2979 UID 000003E8
|
||||
297D GID Size 04
|
||||
297E GID 000003E8
|
||||
2982 PAYLOAD
|
||||
|
||||
5295 CENTRAL HEADER #1 02014B50
|
||||
5299 Created Zip Spec 1E '3.0'
|
||||
529A Created OS 03 'Unix'
|
||||
529B Extract Zip Spec 14 '2.0'
|
||||
529C Extract OS 00 'MS-DOS'
|
||||
529D General Purpose Flag 0001
|
||||
[Bit 0] 1 'Encryption'
|
||||
[Bits 1-2] 1 'Maximum Compression'
|
||||
529F Compression Method 0008 'Deflated'
|
||||
52A1 Last Mod Time 4E2F6B24 'Tue Jan 15 13:25:08 2019'
|
||||
52A5 CRC F1B115BD
|
||||
52A9 Compressed Length 00002904
|
||||
52AD Uncompressed Length 0000E2A5
|
||||
52B1 Filename Length 0005
|
||||
52B3 Extra Length 0018
|
||||
52B5 Comment Length 0000
|
||||
52B7 Disk Start 0000
|
||||
52B9 Int File Attributes 0001
|
||||
[Bit 0] 1 Text Data
|
||||
52BB Ext File Attributes 81B40000
|
||||
52BF Local Header Offset 00000000
|
||||
52C3 Filename 'file1'
|
||||
52C8 Extra ID #0001 5455 'UT: Extended Timestamp'
|
||||
52CA Length 0005
|
||||
52CC Flags '03 mod access'
|
||||
52CD Mod Time 5C3E2584 'Tue Jan 15 13:25:08 2019'
|
||||
52D1 Extra ID #0002 7875 'ux: Unix Extra Type 3'
|
||||
52D3 Length 000B
|
||||
52D5 Version 01
|
||||
52D6 UID Size 04
|
||||
52D7 UID 000003E8
|
||||
52DB GID Size 04
|
||||
52DC GID 000003E8
|
||||
|
||||
52E0 CENTRAL HEADER #2 02014B50
|
||||
52E4 Created Zip Spec 1E '3.0'
|
||||
52E5 Created OS 03 'Unix'
|
||||
52E6 Extract Zip Spec 14 '2.0'
|
||||
52E7 Extract OS 00 'MS-DOS'
|
||||
52E8 General Purpose Flag 0001
|
||||
[Bit 0] 1 'Encryption'
|
||||
[Bits 1-2] 1 'Maximum Compression'
|
||||
52EA Compression Method 0008 'Deflated'
|
||||
52EC Last Mod Time 4E2F6C56 'Tue Jan 15 13:34:44 2019'
|
||||
52F0 CRC EC214569
|
||||
52F4 Compressed Length 00002913
|
||||
52F8 Uncompressed Length 0000E635
|
||||
52FC Filename Length 0005
|
||||
52FE Extra Length 0018
|
||||
5300 Comment Length 0000
|
||||
5302 Disk Start 0000
|
||||
5304 Int File Attributes 0001
|
||||
[Bit 0] 1 Text Data
|
||||
5306 Ext File Attributes 81B40000
|
||||
530A Local Header Offset 00002943
|
||||
530E Filename 'file2'
|
||||
5313 Extra ID #0001 5455 'UT: Extended Timestamp'
|
||||
5315 Length 0005
|
||||
5317 Flags '03 mod access'
|
||||
5318 Mod Time 5C3E27C4 'Tue Jan 15 13:34:44 2019'
|
||||
531C Extra ID #0002 7875 'ux: Unix Extra Type 3'
|
||||
531E Length 000B
|
||||
5320 Version 01
|
||||
5321 UID Size 04
|
||||
5322 UID 000003E8
|
||||
5326 GID Size 04
|
||||
5327 GID 000003E8
|
||||
|
||||
532B END CENTRAL HEADER 06054B50
|
||||
532F Number of this disk 0000
|
||||
5331 Central Dir Disk no 0000
|
||||
5333 Entries in this disk 0002
|
||||
5335 Total Entries 0002
|
||||
5337 Size of Central Dir 00000096
|
||||
533B Offset to Central Dir 00005295
|
||||
533F Comment Length 0000
|
||||
Done
|
||||
```
|
||||
|
||||
### The zipgrep command
|
||||
|
||||
The **zipgrep** command is going to use a grep-type feature to locate particular content in your zipped files. If the file is encrypted, you will need to enter the password provided for the encryption for each file you want to examine. If you only want to check the contents of a single file from the archive, add its name to the end of the zipgrep command as shown below.
|
||||
|
||||
```
|
||||
$ zipgrep hazard twofiles.zip file1
|
||||
[twofiles.zip] file1 password:
|
||||
Certain pesticides should be banned since they are hazardous to the environment.
|
||||
```
|
||||
|
||||
### The zipinfo command
|
||||
|
||||
The **zipinfo** command provides information on the contents of a zipped file whether encrypted or not. This includes the file names, sizes, dates and permissions.
|
||||
|
||||
```
|
||||
$ zipinfo twofiles.zip
|
||||
Archive: twofiles.zip
|
||||
Zip file size: 21313 bytes, number of entries: 2
|
||||
-rw-rw-r-- 3.0 unx 58021 Tx defN 19-Jan-15 13:25 file1
|
||||
-rw-rw-r-- 3.0 unx 58933 Tx defN 19-Jan-15 13:34 file2
|
||||
2 files, 116954 bytes uncompressed, 20991 bytes compressed: 82.1%
|
||||
```
|
||||
|
||||
### The zipnote command
|
||||
|
||||
The **zipnote** command can be used to extract comments from zip archives or add them. To display comments, just preface the name of the archive with the command. If no comments have been added previously, you will see something like this:
|
||||
|
||||
```
|
||||
$ zipnote twofiles.zip
|
||||
@ file1
|
||||
@ (comment above this line)
|
||||
@ file2
|
||||
@ (comment above this line)
|
||||
@ (zip file comment below this line)
|
||||
```
|
||||
|
||||
If you want to add comments, write the output from the zipnote command to a file:
|
||||
|
||||
```
|
||||
$ zipnote twofiles.zip > comments
|
||||
```
|
||||
|
||||
Next, edit the file you've just created, inserting your comments above the **(comment above this line)** lines. Then add the comments using a zipnote command like this one:
|
||||
|
||||
```
|
||||
$ zipnote -w twofiles.zip < comments
|
||||
```
|
||||
|
||||
### The zipsplit command
|
||||
|
||||
The **zipsplit** command can be used to break a zip archive into multiple zip archives when the original file is too large — maybe because you're trying to add one of the files to a small thumb drive. The easiest way to do this seems to be to specify the max size for each of the zipped file portions. This size must be large enough to accomodate the largest included file.
|
||||
|
||||
```
|
||||
$ zipsplit -n 12000 twofiles.zip
|
||||
2 zip files will be made (100% efficiency)
|
||||
creating: twofile1.zip
|
||||
creating: twofile2.zip
|
||||
$ ls twofile*.zip
|
||||
-rw-rw-r-- 1 shs shs 10697 Jan 15 14:52 twofile1.zip
|
||||
-rw-rw-r-- 1 shs shs 10702 Jan 15 14:52 twofile2.zip
|
||||
-rw-rw-r-- 1 shs shs 21377 Jan 15 14:27 twofiles.zip
|
||||
```
|
||||
|
||||
Notice how the extracted files are sequentially named "twofile1" and "twofile2".
|
||||
|
||||
### Wrap-up
|
||||
|
||||
The **zip** command, along with some of its zipping compatriots, provide a lot of control over how you generate and work with compressed file archives.
|
||||
|
||||
**[ Also see:[Invaluable tips and tricks for troubleshooting Linux][1] ]**
|
||||
|
||||
Join the Network World communities on [Facebook][2] and [LinkedIn][3] to comment on topics that are top of mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3333640/linux/zipping-files-on-linux-the-many-variations-and-how-to-use-them.html
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.networkworld.com/article/3242170/linux/invaluable-tips-and-tricks-for-troubleshooting-linux.html
|
||||
[2]: https://www.facebook.com/NetworkWorld/
|
||||
[3]: https://www.linkedin.com/company/network-world
|
||||
@@ -0,0 +1,90 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Get started with WTF, a dashboard for the terminal)
|
||||
[#]: via: (https://opensource.com/article/19/1/wtf-information-dashboard)
|
||||
[#]: author: (Kevein Sonney https://opensource.com/users/ksonney)
|
||||
|
||||
Get started with WTF, a dashboard for the terminal
|
||||
======
|
||||
Keep key information in view with WTF, the sixth in our series on open source tools that will make you more productive in 2019.
|
||||

|
||||
|
||||
There seems to be a mad rush at the beginning of every year to find ways to be more productive. New Year's resolutions, the itch to start the year off right, and of course, an "out with the old, in with the new" attitude all contribute to this. And the usual round of recommendations is heavily biased towards closed source and proprietary software. It doesn't have to be that way.
|
||||
|
||||
Here's the sixth of my picks for 19 new (or new-to-you) open source tools to help you be more productive in 2019.
|
||||
|
||||
### WTF
|
||||
|
||||
Once upon a time, I was doing some consulting at a firm that used [Bloomberg Terminals][1] . My reaction was, "Wow, that's WAY too much information on one screen." These days, however, it seems like I can't get enough information on a screen when I'm working and have multiple web pages, dashboards, and console apps open to try to keep track of things.
|
||||
|
||||
While [tmux][2] and [Screen][3] can do split screens and multiple windows, they are a pain to set up, and the keybindings can take a while to learn (and often conflict with other applications).
|
||||
|
||||
[WTF][4] is a simple, easily configured information dashboard for the terminal. It is written in [Go][5], uses a YAML configuration file, and can pull data from several different sources. All the data sources are contained in [modules][6] and include things like weather, issue trackers, date and time, Google Sheets, and a whole lot more. Some panes are interactive, and some just update with the most recent information available.
|
||||
|
||||
Setup is as easy as downloading the latest release for your operating system and running the command. Since it is written in Go, it is very portable and should run anywhere you can compile it (although the developer only builds for Linux and MacOS at this time).
|
||||
|
||||

|
||||
|
||||
When you run WTF for the first time, you'll get the default screen, identical to the image above.
|
||||
|
||||

|
||||
|
||||
You also get the default configuration file in **~/.wtf/config.yml** , and you can edit the file to suit your needs. The grid layout is configured in the top part of the file.
|
||||
|
||||
```
|
||||
grid:
|
||||
columns: [45, 45]
|
||||
rows: [7, 7, 7, 4]
|
||||
```
|
||||
|
||||
The numbers in the grid settings represent the character dimensions of each block. The default configuration is two columns of 40 characters, two rows 13 characters tall, and one row 4 characters tall. In the code above, I made the columns wider (45, 45), the rows smaller, and added a fourth row so I can have more widgets.
|
||||
|
||||

|
||||
|
||||
I like to see the day's weather on my dashboard. There are two weather modules to chose from: [Weather][7], which shows just the text information, and [Pretty Weather][8], which is colorful and uses text-based graphics in the display.
|
||||
|
||||
```
|
||||
prettyweather:
|
||||
enabled: true
|
||||
position:
|
||||
top: 0
|
||||
left: 1
|
||||
height: 2
|
||||
width: 1
|
||||
```
|
||||
|
||||
This code creates a pane two blocks tall (height: 2) and one block wide (height: 1), positioned on the second column (left: 1) on the top row (top: 0) containing the Pretty Weather module.
|
||||
|
||||
Some modules, like Jira, GitHub, and Todo, are interactive, and you can scroll, update, and save information in them. You can move between the interactive panes using the Tab key. The \ key brings up a help screen for the active pane so you can see what you can do and how. The Todo module lets you add, edit, and delete to-do items, as well as check them off as you complete them.
|
||||
|
||||

|
||||
|
||||
There are also modules to execute commands and present the output, watch a text file, and monitor build and integration server output. All the documentation is very well done.
|
||||
|
||||
WTF is a valuable tool for anyone who needs to see a lot of data on one screen from different sources.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/1/wtf-information-dashboard
|
||||
|
||||
作者:[Kevein Sonney][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/ksonney
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://en.wikipedia.org/wiki/Bloomberg_Terminal
|
||||
[2]: https://github.com/tmux/tmux
|
||||
[3]: https://www.gnu.org/software/screen/
|
||||
[4]: https://wtfutil.com/
|
||||
[5]: https://golang.org/
|
||||
[6]: https://wtfutil.com/posts/modules/
|
||||
[7]: https://wtfutil.com/posts/modules/weather/
|
||||
[8]: https://wtfutil.com/posts/modules/prettyweather/
|
||||
268
sources/tech/20190118 Top 5 Linux Server Distributions.md
Normal file
268
sources/tech/20190118 Top 5 Linux Server Distributions.md
Normal file
@@ -0,0 +1,268 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Top 5 Linux Server Distributions)
|
||||
[#]: via: (https://www.linux.com/blog/learn/2019/1/top-5-linux-server-distributions)
|
||||
[#]: author: (Jack Wallen https://www.linux.com/users/jlwallen)
|
||||
|
||||
Top 5 Linux Server Distributions
|
||||
======
|
||||

|
||||
|
||||
Ah, the age-old question: Which Linux distribution is best suited for servers? Typically, when this question is asked, the standard responses pop up:
|
||||
|
||||
* RHEL
|
||||
|
||||
* SUSE
|
||||
|
||||
* Ubuntu Server
|
||||
|
||||
* Debian
|
||||
|
||||
* CentOS
|
||||
|
||||
|
||||
|
||||
|
||||
However, in the name of opening your eyes to maybe something a bit different, I’m going to approach this a bit differently. I want to consider a list of possible distributions that are not only outstanding candidates but also easy to use, and that can serve many functions within your business. In some cases, my choices are drop-in replacements for other operating systems, whereas others require a bit of work to get them up to speed.
|
||||
|
||||
Some of my choices are community editions of enterprise-grade servers, which could be considered gateways to purchasing a much more powerful platform. You’ll even find one or two entries here to be duty-specific platforms. Most importantly, however, what you’ll find on this list isn’t the usual fare.
|
||||
|
||||
### ClearOS
|
||||
|
||||
What is ClearOS? For home and small business usage, you might not find a better solution. Out of the box, ClearOS includes tools like intrusion detection, a strong firewall, bandwidth management tools, a mail server, a domain controller, and much more. What makes ClearOS stand out above some of the competition is its purpose is to server as a simple Home and SOHO server with a user-friendly, graphical web-based interface. From that interface, you’ll find an application marketplace (Figure 1), with hundreds of apps (some of which are free, whereas some have an associated cost), that makes it incredibly easy to extend the ClearOS featureset. In other words, you make ClearOS the platform your home and small business needs it to be. Best of all, unlike many other alternatives, you only pay for the software and support you need.
|
||||

|
||||
There are three different editions of ClearOS:
|
||||
|
||||
* [ClearOS Community][1] - the free edition of ClearOS
|
||||
|
||||
* [ClearOS Home][2] - ideal for home offices
|
||||
|
||||
* [ClearOS Business][3] - ideal for small businesses, due to the inclusion of paid support
|
||||
|
||||
|
||||
|
||||
|
||||
To make the installation of software even easier, the ClearOS marketplace allows you to select via:
|
||||
|
||||
* By Function (which displays apps according to task)
|
||||
|
||||
* By Category (which displays groups of related apps)
|
||||
|
||||
* Quick Select File (which allows you to select pre-configured templates to get you up and running fast)
|
||||
|
||||
|
||||
|
||||
|
||||
In other words, if you’re looking for a Linux Home, SOHO, or SMB server, ClearOS is an outstanding choice (especially if you don’t have the Linux chops to get a standard server up and running).
|
||||
|
||||
### Fedora Server
|
||||
|
||||
You’ve heard of Fedora Linux. Of course you have. It’s one of the finest bleeding edge distributions on the market. But did you know the developers of that excellent Fedora Desktop distribution also has a Server edition? The Fedora Server platform is a short-lifecycle, community-supported server OS. This take on the server operating system enables seasoned system administrators, experienced with any flavor of Linux (or any OS at all), to make use of the very latest technologies available in the open source community. There are three key words in that description:
|
||||
|
||||
* Seasoned
|
||||
|
||||
* System
|
||||
|
||||
* Administrators
|
||||
|
||||
|
||||
|
||||
|
||||
In other words, new users need not apply. Although Fedora Server is quite capable of handling any task you throw at it, it’s going to require someone with a bit more Linux kung fu to make it work and work well. One very nice inclusion with Fedora Server is that, out of the box, it includes one of the finest open source, web-based interface for servers on the market. With Cockpit (Figure 2) you get a quick glance at system resources, logs, storage, network, as well as the ability to manage accounts, services, applications, and updates.
|
||||
|
||||
![Fedora Server][5]
|
||||
|
||||
Figure 2: Cockpit running on Fedora Server.
|
||||
|
||||
[Used with permission][6]
|
||||
|
||||
If you’re okay working with bleeding edge software, and want an outstanding admin dashboard, Fedora Server might be the platform for you.
|
||||
|
||||
### NethServer
|
||||
|
||||
NethServer is about as no-brainer of a drop-in SMB Linux server as you’ll find. With the latest iteration of NethServer, your small business will enjoy:
|
||||
|
||||
* Built-in Samba Active Directory Controller
|
||||
|
||||
* Seamless Nextcloud integration
|
||||
|
||||
* Certificate management
|
||||
|
||||
* Transparent HTTPS proxy
|
||||
|
||||
* Firewall
|
||||
|
||||
* Mail server and filter
|
||||
|
||||
* Web server and filter
|
||||
|
||||
* Groupware
|
||||
|
||||
* IPS/IDS or VPN
|
||||
|
||||
|
||||
|
||||
|
||||
All of the included features can be easily configured with a user-friendly, web-based interface that includes single-click installation of modules to expand the NethServer feature set (Figure 3) What sets NethServer apart from ClearOS is that it was designed to make the admin job easier. In other words, this platform offers much more in the way of flexibility and power. Unlike ClearOS, which is geared more toward home office and SOHO deployments, NethServer is equally at home in small business environments.
|
||||
|
||||
![NethServer][8]
|
||||
|
||||
Figure 3: Adding modules to NethServer.
|
||||
|
||||
[Used with permission][6]
|
||||
|
||||
### Rockstor
|
||||
|
||||
Rockstor is a Linux and Btfrs powered advanced Network Attached Storage (NAS) and Cloud storage server that can be deployed for Home, SOHO, as well as small- and mid-sized businesses alike. With Rockstor, you get a full-blown NAS/Cloud solution with a user-friendly, web-based GUI tool that is just as easy for admins to set up as it is for users to use. Once you have Rockstor deployed, you can create pools, shares, snapshots, manage replication and users, share files (with the help of Samba, NFS, SFTP, and AFP), and even extend the featureset, thanks to add-ons (called Rock-ons). The list of Rock-ons includes:
|
||||
|
||||
* CouchPotato (Downloader for usenet and bittorrent users)
|
||||
|
||||
* Deluge (Movie downloader for bittorrent users)
|
||||
|
||||
* EmbyServer (Emby media server)
|
||||
|
||||
* Ghost (Publishing platform for professional bloggers)
|
||||
|
||||
* GitLab CE (Git repository hosting and collaboration)
|
||||
|
||||
* Gogs Go Git Service (Lightweight Git version control server and front end)
|
||||
|
||||
* Headphones (An automated music downloader for NZB and Torrent)
|
||||
|
||||
* Logitech Squeezebox Server for Squeezebox Devices
|
||||
|
||||
* MariaDB (Relational database management system)
|
||||
|
||||
* NZBGet (Efficient usenet downloader)
|
||||
|
||||
* OwnCloud-Official (Secure file sharing and hosting)
|
||||
|
||||
* Plexpy (Python-based Plex Usage tracker)
|
||||
|
||||
* Rocket.Chat (Open Source Chat Platform)
|
||||
|
||||
* SaBnzbd (Usenet downloader)
|
||||
|
||||
* Sickbeard (Internet PVR for TV shows)
|
||||
|
||||
* Sickrage (Automatic Video Library Manager for TV Shows)
|
||||
|
||||
* Sonarr (PVR for usenet and bittorrent users)
|
||||
|
||||
* Symform (Backup service)
|
||||
|
||||
|
||||
|
||||
|
||||
Rockstor also includes an at-a-glance dashboard that gives admins quick access to all the information they need about their server (Figure 4).
|
||||
|
||||
![Rockstor][10]
|
||||
|
||||
The Rockstor dashboard in action.
|
||||
|
||||
[Used with permission][6]
|
||||
|
||||
### Zentyal
|
||||
|
||||
Zentyal is another Small Business Server that does a great job of handling multiple tasks. If you’re looking for a Linux distribution that can handle the likes of:
|
||||
|
||||
* Directory and Domain server
|
||||
|
||||
* Mail server
|
||||
|
||||
* Gateway
|
||||
|
||||
* DHCP, DNS, and NTP server
|
||||
|
||||
* Certification Authority
|
||||
|
||||
* VPN
|
||||
|
||||
* Instant Messaging
|
||||
|
||||
* FTP server
|
||||
|
||||
* Antivirus
|
||||
|
||||
* SSO authentication
|
||||
|
||||
* File sharing
|
||||
|
||||
* RADIUS
|
||||
|
||||
* Virtualization Management
|
||||
|
||||
* And more
|
||||
|
||||
|
||||
|
||||
|
||||
Zentyal might be your new go-to. Zentyal has been around since 2004 and is based on Ubuntu Server, so it enjoys a rock-solid base and plenty of applications. And with the help of the Zentyal dashboard (Figure 5), admins can easily manage:
|
||||
|
||||
* System
|
||||
|
||||
* Network
|
||||
|
||||
* Logs
|
||||
|
||||
* Software updates and installation
|
||||
|
||||
* Users/groups
|
||||
|
||||
* Domains
|
||||
|
||||
* File sharing
|
||||
|
||||
* Mail
|
||||
|
||||
* DNS
|
||||
|
||||
* Firewall
|
||||
|
||||
* Certificates
|
||||
|
||||
* And much more
|
||||
|
||||

|
||||
|
||||
|
||||
Adding new components to the Zentyal server is as simple as opening the Dashboard, clicking on Software Management > Zentyal Components, selecting what you want to add, and clicking Install. The one issue you might find with Zentyal is that it doesn’t offer nearly the amount of addons as you’ll find in the likes of Nethserver and ClearOS. But the services it does offer, Zentyal does incredibly well.
|
||||
|
||||
### Plenty More Where These Came From
|
||||
|
||||
This list of Linux servers is clearly not exhaustive. What it is, however, is a unique look at the top five server distributions you’ve probably not heard of. Of course, if you’d rather opt to use a more traditional Linux server distribution, you can always stick with [CentOS][11], [Ubuntu Server][12], [SUSE][13], [Red Hat Enterprise Linux][14], or [Debian][15]… most of which are found on every list of best server distributions on the market. If, however, you’re looking for something a bit different, give one of these five distos a try.
|
||||
|
||||
Learn more about Linux through the free ["Introduction to Linux" ][16]course from The Linux Foundation and edX.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/blog/learn/2019/1/top-5-linux-server-distributions
|
||||
|
||||
作者:[Jack Wallen][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.linux.com/users/jlwallen
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.clearos.com/clearfoundation/software/clearos-7-community
|
||||
[2]: https://www.clearos.com/products/clearos-editions/clearos-7-home
|
||||
[3]: https://www.clearos.com/products/clearos-editions/clearos-7-business
|
||||
[4]: https://www.linux.com/files/images/fedoraserverjpg
|
||||
[5]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/fedoraserver.jpg?itok=phaAIRXW (Fedora Server)
|
||||
[6]: https://www.linux.com/licenses/category/used-permission
|
||||
[7]: https://www.linux.com/files/images/nethserverjpg
|
||||
[8]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/nethserver.jpg?itok=HO-CRbOV (NethServer)
|
||||
[9]: https://www.linux.com/files/images/rockstorejpg
|
||||
[10]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/rockstore.jpg?itok=EN_5oFxQ (Rockstor)
|
||||
[11]: https://www.centos.org/
|
||||
[12]: https://www.ubuntu.com/download/server
|
||||
[13]: https://www.suse.com/
|
||||
[14]: https://www.redhat.com/en/technologies/linux-platforms/enterprise-linux
|
||||
[15]: https://www.debian.org/
|
||||
[16]: https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux
|
||||
@@ -0,0 +1,61 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Get started with HomeBank, an open source personal finance app)
|
||||
[#]: via: (https://opensource.com/article/19/1/productivity-tools-homebank)
|
||||
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney (Kevin Sonney))
|
||||
|
||||
Get started with HomeBank, an open source personal finance app
|
||||
======
|
||||
Keep track of where your money is going with HomeBank, the eighth in our series on open source tools that will make you more productive in 2019.
|
||||

|
||||
|
||||
There seems to be a mad rush at the beginning of every year to find ways to be more productive. New Year's resolutions, the itch to start the year off right, and of course, an "out with the old, in with the new" attitude all contribute to this. And the usual round of recommendations is heavily biased towards closed source and proprietary software. It doesn't have to be that way.
|
||||
|
||||
Here's the eighth of my picks for 19 new (or new-to-you) open source tools to help you be more productive in 2019.
|
||||
|
||||
### HomeBank
|
||||
|
||||
Managing my finances can be really stressful. I don't look at my bank balance every day and sometimes have trouble keeping track of where my money is going. I often spend more time managing my finances than I need to, digging into accounts and payment histories to figure out where my money went. Knowing my finances are OK helps keep me calm and allows me to focus on other things.
|
||||
|
||||

|
||||
|
||||
[HomeBank][1] is a personal finance desktop application that helps decrease this type of stress by making it fairly easy to keep track of your finances. It has some nice reports to help you figure out where you're spending your money, allows you to set up rules for importing transactions, and supports most modern formats.
|
||||
|
||||
HomeBank is available on most distributions by default, so installation is very easy. When you start it up for the first time, it will walk you through setup and allow you to create an account. From there, you can either import one of the supported file formats or start entering transactions. The transaction register itself is just that—a list of transactions. [Unlike some other apps][2], you don't have to learn [double-entry bookkeeping][3] to use HomeBank.
|
||||
|
||||

|
||||
|
||||
Importing files from your bank is handled with another step-by-step wizard, with options to create a new account or populate an existing one. Importing into a new account saves a little time since you don't have to pre-create all the accounts before starting the import. You can also import multiple files into an account at once, so you don't need to repeat the same steps for every file in every account.
|
||||
|
||||

|
||||
|
||||
The one pain point I've had with importing and managing accounts is category assignment. Categories are what allow you to break down your spending and see what you are spending money on, in general terms. HomeBank, unlike commercial services (and some commercial programs), requires you to manually set up all the assignments. But this is generally a one-time thing, and then the categories can be auto-applied as transactions are added/imported. There is also a button to analyze the account and auto-apply things that already exist, which speeds up categorizing a large import (like I did the first time). HomeBank comes with a large number of categories you can start with, and you can add your own as well.
|
||||
|
||||
HomeBank also has budgeting features, allowing you to plan for the months ahead.
|
||||
|
||||

|
||||
|
||||
The big win, for me, is HomeBank's reports feature. Not only is there a chart on the main screen showing where you are spending your money, but there are a whole host of other reports you can look at. If you use the budget feature, there is a report that tracks your spending against your budget. You can also view those reports as pie and bar charts. There is also a trend report and a balance report, so you can look back and see changes or patterns over time.
|
||||
|
||||
Overall, HomeBank is a very friendly, useful application to help you keep your finances in order. It is simple to use and really helpful if keeping track of your money is a major stress point in your life.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/1/productivity-tools-homebank
|
||||
|
||||
作者:[Kevin Sonney][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/ksonney (Kevin Sonney)
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: http://homebank.free.fr/en/index.php
|
||||
[2]: https://www.gnucash.org/
|
||||
[3]: https://en.wikipedia.org/wiki/Double-entry_bookkeeping_system
|
||||
@@ -0,0 +1,92 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Akira: The Linux Design Tool We’ve Always Wanted?)
|
||||
[#]: via: (https://itsfoss.com/akira-design-tool)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
|
||||
Akira: The Linux Design Tool We’ve Always Wanted?
|
||||
======
|
||||
|
||||
Let’s make it clear, I am not a professional designer – but I’ve used certain tools on Windows (like Photoshop, Illustrator, etc.) and [Figma][1] (which is a browser-based interface design tool). I’m sure there are a lot more design tools available for Mac and Windows.
|
||||
|
||||
Even on Linux, there is a limited number of dedicated [graphic design tools][2]. A few of these tools like [GIMP][3] and [Inkscape][4] are used by professionals as well. But most of them are not considered professional grade, unfortunately.
|
||||
|
||||
Even if there are a couple more solutions – I’ve never come across a native Linux application that could replace [Sketch][5], Figma, or Adobe **** XD. Any professional designer would agree to that, isn’t it?
|
||||
|
||||
### Is Akira going to replace Sketch, Figma, and Adobe XD on Linux?
|
||||
|
||||
Well, in order to develop something that would replace those awesome proprietary tools – [Alessandro Castellani][6] – came up with a [Kickstarter campaign][7] by teaming up with a couple of experienced developers –
|
||||
[Alberto Fanjul][8], [Bilal Elmoussaoui][9], and [Felipe Escoto][10].
|
||||
|
||||
So, yes, Akira is still pretty much just an idea- with a working prototype of its interface (as I observed in their [live stream session][11] via Kickstarter recently).
|
||||
|
||||
### If it does not exist, why the Kickstarter campaign?
|
||||
|
||||
![][12]
|
||||
|
||||
The aim of the Kickstarter campaign is to gather funds in order to hire the developers and take a few months off to dedicate their time in order to make Akira possible.
|
||||
|
||||
Nonetheless, if you want to support the project, you should know some details, right?
|
||||
|
||||
Fret not, we asked a couple of questions in their livestream session – let’s get into it…
|
||||
|
||||
### Akira: A few more details
|
||||
|
||||
![Akira prototype interface][13]
|
||||
Image Credits: Kickstarter
|
||||
|
||||
As the Kickstarter campaign describes:
|
||||
|
||||
> The main purpose of Akira is to offer a fast and intuitive tool to **create Web and Mobile interfaces** , more like **Sketch** , **Figma** , or **Adobe XD** , with a completely native experience for Linux.
|
||||
|
||||
They’ve also written a detailed description as to how the tool will be different from Inkscape, Glade, or QML Editor. Of course, if you want all the technical details, [Kickstarter][7] is the way to go. But, before that, let’s take a look at what they had to say when I asked some questions about Akira.
|
||||
|
||||
Q: If you consider your project – similar to what Figma offers – why should one consider installing Akira instead of using the web-based tool? Is it just going to be a clone of those tools – offering a native Linux experience or is there something really interesting to encourage users to switch (except being an open source solution)?
|
||||
|
||||
**Akira:** A native experience on Linux is always better and fast in comparison to a web-based electron app. Also, the hardware configuration matters if you choose to utilize Figma – but Akira will be light on system resource and you will still be able to do similar stuff without needing to go online.
|
||||
|
||||
Q: Let’s assume that it becomes the open source solution that Linux users have been waiting for (with similar features offered by proprietary tools). What are your plans to sustain it? Do you plan to introduce any pricing plans – or rely on donations?
|
||||
|
||||
**Akira** : The project will mostly rely on Donations (something like [Krita Foundation][14] could be an idea). But, there will be no “pro” pricing plans – it will be available for free and it will be an open source project.
|
||||
|
||||
So, with the response I got, it definitely seems to be something promising that we should probably support.
|
||||
|
||||
### Wrapping Up
|
||||
|
||||
What do you think about Akira? Is it just going to remain a concept? Or do you hope to see it in action?
|
||||
|
||||
Let us know your thoughts in the comments below.
|
||||
|
||||
![][15]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/akira-design-tool
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/ankush/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.figma.com/
|
||||
[2]: https://itsfoss.com/best-linux-graphic-design-software/
|
||||
[3]: https://itsfoss.com/gimp-2-10-release/
|
||||
[4]: https://inkscape.org/
|
||||
[5]: https://www.sketchapp.com/
|
||||
[6]: https://github.com/Alecaddd
|
||||
[7]: https://www.kickstarter.com/projects/alecaddd/akira-the-linux-design-tool/description
|
||||
[8]: https://github.com/albfan
|
||||
[9]: https://github.com/bilelmoussaoui
|
||||
[10]: https://github.com/Philip-Scott
|
||||
[11]: https://live.kickstarter.com/alessandro-castellani/live-stream/the-current-state-of-akira
|
||||
[12]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/01/akira-design-tool-kickstarter.jpg?resize=800%2C451&ssl=1
|
||||
[13]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/01/akira-mockup.png?ssl=1
|
||||
[14]: https://krita.org/en/about/krita-foundation/
|
||||
[15]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/01/akira-design-tool-kickstarter.jpg?fit=812%2C458&ssl=1
|
||||
@@ -0,0 +1,398 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How To Copy A File/Folder From A Local System To Remote System In Linux?)
|
||||
[#]: via: (https://www.2daygeek.com/linux-scp-rsync-pscp-command-copy-files-folders-in-multiple-servers-using-shell-script/)
|
||||
[#]: author: (Prakash Subramanian https://www.2daygeek.com/author/prakash/)
|
||||
|
||||
How To Copy A File/Folder From A Local System To Remote System In Linux?
|
||||
======
|
||||
|
||||
Copying a file from one server to another server or local to remote is one of the routine task for Linux administrator.
|
||||
|
||||
If anyone says no, i won’t accept because this is one of the regular activity wherever you go.
|
||||
|
||||
It can be done in many ways and we are trying to cover all the possible options.
|
||||
|
||||
You can choose the one which you would prefer. Also, check other commands as well that may help you for some other purpose.
|
||||
|
||||
I have tested all these commands and script in my test environment so, you can use this for your routine work.
|
||||
|
||||
By default every one go with SCP because it’s one of the native command that everyone use for file copy. But commands which is listed in this article are be smart so, give a try if you would like to try new things.
|
||||
|
||||
This can be done in below four ways easily.
|
||||
|
||||
* **`SCP:`** scp copies files between hosts on a network. It uses ssh for data transfer, and uses the same authentication and provides the same security as ssh.
|
||||
* **`RSYNC:`** rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon.
|
||||
* **`PSCP:`** pscp is a program for copying files in parallel to a number of hosts. It provides features such as passing a password to scp, saving output to files, and timing out.
|
||||
* **`PRSYNC:`** prsync is a program for copying files in parallel to a number of hosts. It provides features such as passing a password to ssh, saving output to files, and timing out.
|
||||
|
||||
|
||||
|
||||
### Method-1: Copy Files/Folders From A Local System To Remote System In Linux Using SCP Command?
|
||||
|
||||
scp command allow us to copy files/folders from a local system to remote system.
|
||||
|
||||
We are going to copy the `output.txt` file from my local system to `2g.CentOS.com` remote system under `/opt/backup` directory.
|
||||
|
||||
```
|
||||
# scp output.txt root@2g.CentOS.com:/opt/backup
|
||||
|
||||
output.txt 100% 2468 2.4KB/s 00:00
|
||||
```
|
||||
|
||||
We are going to copy two files `output.txt` and `passwd-up.sh` files from my local system to `2g.CentOS.com` remote system under `/opt/backup` directory.
|
||||
|
||||
```
|
||||
# scp output.txt passwd-up.sh root@2g.CentOS.com:/opt/backup
|
||||
|
||||
output.txt 100% 2468 2.4KB/s 00:00
|
||||
passwd-up.sh 100% 877 0.9KB/s 00:00
|
||||
```
|
||||
|
||||
We are going to copy the `shell-script` directory from my local system to `2g.CentOS.com` remote system under `/opt/backup` directory.
|
||||
|
||||
This will copy the `shell-script` directory and associated files under `/opt/backup` directory.
|
||||
|
||||
```
|
||||
# scp -r /home/daygeek/2g/shell-script/ [email protected]:/opt/backup/
|
||||
|
||||
output.txt 100% 2468 2.4KB/s 00:00
|
||||
ovh.sh 100% 76 0.1KB/s 00:00
|
||||
passwd-up.sh 100% 877 0.9KB/s 00:00
|
||||
passwd-up1.sh 100% 7 0.0KB/s 00:00
|
||||
server-list.txt 100% 23 0.0KB/s 00:00
|
||||
```
|
||||
|
||||
### Method-2: Copy Files/Folders From A Local System To Multiple Remote System In Linux Using Shell Script with scp Command?
|
||||
|
||||
If you would like to copy the same file into multiple remote servers then create the following small shell script to achieve this.
|
||||
|
||||
To do so, get the servers list and add those into `server-list.txt` file. Make sure you have to update the servers list into `server-list.txt` file. Each server should be in separate line.
|
||||
|
||||
Finally mention the file location which you want to copy like below.
|
||||
|
||||
```
|
||||
# file-copy.sh
|
||||
|
||||
#!/bin/sh
|
||||
for server in `more server-list.txt`
|
||||
do
|
||||
scp /home/daygeek/2g/shell-script/output.txt [email protected]$server:/opt/backup
|
||||
done
|
||||
```
|
||||
|
||||
Once you done, set an executable permission to password-update.sh file.
|
||||
|
||||
```
|
||||
# chmod +x file-copy.sh
|
||||
```
|
||||
|
||||
Finally run the script to achieve this.
|
||||
|
||||
```
|
||||
# ./file-copy.sh
|
||||
|
||||
output.txt 100% 2468 2.4KB/s 00:00
|
||||
output.txt 100% 2468 2.4KB/s 00:00
|
||||
```
|
||||
|
||||
Use the following script to copy the multiple files into multiple remote servers.
|
||||
|
||||
```
|
||||
# file-copy.sh
|
||||
|
||||
#!/bin/sh
|
||||
for server in `more server-list.txt`
|
||||
do
|
||||
scp /home/daygeek/2g/shell-script/output.txt passwd-up.sh [email protected]$server:/opt/backup
|
||||
done
|
||||
```
|
||||
|
||||
The below output shows all the files twice as this copied into two servers.
|
||||
|
||||
```
|
||||
# ./file-cp.sh
|
||||
|
||||
output.txt 100% 2468 2.4KB/s 00:00
|
||||
passwd-up.sh 100% 877 0.9KB/s 00:00
|
||||
output.txt 100% 2468 2.4KB/s 00:00
|
||||
passwd-up.sh 100% 877 0.9KB/s 00:00
|
||||
```
|
||||
|
||||
Use the following script to copy the directory recursively into multiple remote servers.
|
||||
|
||||
```
|
||||
# file-copy.sh
|
||||
|
||||
#!/bin/sh
|
||||
for server in `more server-list.txt`
|
||||
do
|
||||
scp -r /home/daygeek/2g/shell-script/ [email protected]$server:/opt/backup
|
||||
done
|
||||
```
|
||||
|
||||
Output for the above script.
|
||||
|
||||
```
|
||||
# ./file-cp.sh
|
||||
|
||||
output.txt 100% 2468 2.4KB/s 00:00
|
||||
ovh.sh 100% 76 0.1KB/s 00:00
|
||||
passwd-up.sh 100% 877 0.9KB/s 00:00
|
||||
passwd-up1.sh 100% 7 0.0KB/s 00:00
|
||||
server-list.txt 100% 23 0.0KB/s 00:00
|
||||
|
||||
output.txt 100% 2468 2.4KB/s 00:00
|
||||
ovh.sh 100% 76 0.1KB/s 00:00
|
||||
passwd-up.sh 100% 877 0.9KB/s 00:00
|
||||
passwd-up1.sh 100% 7 0.0KB/s 00:00
|
||||
server-list.txt 100% 23 0.0KB/s 00:00
|
||||
```
|
||||
|
||||
### Method-3: Copy Files/Folders From A Local System To Multiple Remote System In Linux Using PSCP Command?
|
||||
|
||||
pscp command directly allow us to perform the copy to multiple remote servers.
|
||||
|
||||
Use the following pscp command to copy a single file to remote server.
|
||||
|
||||
```
|
||||
# pscp.pssh -H 2g.CentOS.com /home/daygeek/2g/shell-script/output.txt /opt/backup
|
||||
|
||||
[1] 18:46:11 [SUCCESS] 2g.CentOS.com
|
||||
```
|
||||
|
||||
Use the following pscp command to copy a multiple files to remote server.
|
||||
|
||||
```
|
||||
# pscp.pssh -H 2g.CentOS.com /home/daygeek/2g/shell-script/output.txt ovh.sh /opt/backup
|
||||
|
||||
[1] 18:47:48 [SUCCESS] 2g.CentOS.com
|
||||
```
|
||||
|
||||
Use the following pscp command to copy a directory recursively to remote server.
|
||||
|
||||
```
|
||||
# pscp.pssh -H 2g.CentOS.com -r /home/daygeek/2g/shell-script/ /opt/backup
|
||||
|
||||
[1] 18:48:46 [SUCCESS] 2g.CentOS.com
|
||||
```
|
||||
|
||||
Use the following pscp command to copy a single file to multiple remote servers.
|
||||
|
||||
```
|
||||
# pscp.pssh -h server-list.txt /home/daygeek/2g/shell-script/output.txt /opt/backup
|
||||
|
||||
[1] 18:49:48 [SUCCESS] 2g.CentOS.com
|
||||
[2] 18:49:48 [SUCCESS] 2g.Debian.com
|
||||
```
|
||||
|
||||
Use the following pscp command to copy a multiple files to multiple remote servers.
|
||||
|
||||
```
|
||||
# pscp.pssh -h server-list.txt /home/daygeek/2g/shell-script/output.txt passwd-up.sh /opt/backup
|
||||
|
||||
[1] 18:50:30 [SUCCESS] 2g.Debian.com
|
||||
[2] 18:50:30 [SUCCESS] 2g.CentOS.com
|
||||
```
|
||||
|
||||
Use the following pscp command to copy a directory recursively to multiple remote servers.
|
||||
|
||||
```
|
||||
# pscp.pssh -h server-list.txt -r /home/daygeek/2g/shell-script/ /opt/backup
|
||||
|
||||
[1] 18:51:31 [SUCCESS] 2g.Debian.com
|
||||
[2] 18:51:31 [SUCCESS] 2g.CentOS.com
|
||||
```
|
||||
|
||||
### Method-4: Copy Files/Folders From A Local System To Multiple Remote System In Linux Using rsync Command?
|
||||
|
||||
Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon.
|
||||
|
||||
Use the following rsync command to copy a single file to remote server.
|
||||
|
||||
```
|
||||
# rsync -avz /home/daygeek/2g/shell-script/output.txt [email protected]:/opt/backup
|
||||
|
||||
sending incremental file list
|
||||
output.txt
|
||||
|
||||
sent 598 bytes received 31 bytes 1258.00 bytes/sec
|
||||
total size is 2468 speedup is 3.92
|
||||
```
|
||||
|
||||
Use the following pscp command to copy a multiple files to remote server.
|
||||
|
||||
```
|
||||
# rsync -avz /home/daygeek/2g/shell-script/output.txt passwd-up.sh root@2g.CentOS.com:/opt/backup
|
||||
|
||||
sending incremental file list
|
||||
output.txt
|
||||
passwd-up.sh
|
||||
|
||||
sent 737 bytes received 50 bytes 1574.00 bytes/sec
|
||||
total size is 2537 speedup is 3.22
|
||||
```
|
||||
|
||||
Use the following rsync command to copy a single file to remote server overh ssh.
|
||||
|
||||
```
|
||||
# rsync -avzhe ssh /home/daygeek/2g/shell-script/output.txt root@2g.CentOS.com:/opt/backup
|
||||
|
||||
sending incremental file list
|
||||
output.txt
|
||||
|
||||
sent 598 bytes received 31 bytes 419.33 bytes/sec
|
||||
total size is 2.47K speedup is 3.92
|
||||
```
|
||||
|
||||
Use the following pscp command to copy a directory recursively to remote server over ssh. This will copy only files not the base directory.
|
||||
|
||||
```
|
||||
# rsync -avzhe ssh /home/daygeek/2g/shell-script/ root@2g.CentOS.com:/opt/backup
|
||||
|
||||
sending incremental file list
|
||||
./
|
||||
output.txt
|
||||
ovh.sh
|
||||
passwd-up.sh
|
||||
passwd-up1.sh
|
||||
server-list.txt
|
||||
|
||||
sent 3.85K bytes received 281 bytes 8.26K bytes/sec
|
||||
total size is 9.12K speedup is 2.21
|
||||
```
|
||||
|
||||
### Method-5: Copy Files/Folders From A Local System To Multiple Remote System In Linux Using Shell Script with rsync Command?
|
||||
|
||||
If you would like to copy the same file into multiple remote servers then create the following small shell script to achieve this.
|
||||
|
||||
```
|
||||
# file-copy.sh
|
||||
|
||||
#!/bin/sh
|
||||
for server in `more server-list.txt`
|
||||
do
|
||||
rsync -avzhe ssh /home/daygeek/2g/shell-script/ root@2g.CentOS.com$server:/opt/backup
|
||||
done
|
||||
```
|
||||
|
||||
Output for the above shell script.
|
||||
|
||||
```
|
||||
# ./file-copy.sh
|
||||
|
||||
sending incremental file list
|
||||
./
|
||||
output.txt
|
||||
ovh.sh
|
||||
passwd-up.sh
|
||||
passwd-up1.sh
|
||||
server-list.txt
|
||||
|
||||
sent 3.86K bytes received 281 bytes 8.28K bytes/sec
|
||||
total size is 9.13K speedup is 2.21
|
||||
|
||||
sending incremental file list
|
||||
./
|
||||
output.txt
|
||||
ovh.sh
|
||||
passwd-up.sh
|
||||
passwd-up1.sh
|
||||
server-list.txt
|
||||
|
||||
sent 3.86K bytes received 281 bytes 2.76K bytes/sec
|
||||
total size is 9.13K speedup is 2.21
|
||||
```
|
||||
|
||||
### Method-6: Copy Files/Folders From A Local System To Multiple Remote System In Linux Using Shell Script with scp Command?
|
||||
|
||||
In the above two shell script, we need to mention the file and folder location as a prerequiesties but here i did a small modification that allow the script to get a file or folder as a input. It could be very useful when you want to perform the copy multiple times in a day.
|
||||
|
||||
```
|
||||
# file-copy.sh
|
||||
|
||||
#!/bin/sh
|
||||
for server in `more server-list.txt`
|
||||
do
|
||||
scp -r $1 root@2g.CentOS.com$server:/opt/backup
|
||||
done
|
||||
```
|
||||
|
||||
Run the shell script and give the file name as a input.
|
||||
|
||||
```
|
||||
# ./file-copy.sh output1.txt
|
||||
|
||||
output1.txt 100% 3558 3.5KB/s 00:00
|
||||
output1.txt 100% 3558 3.5KB/s 00:00
|
||||
```
|
||||
|
||||
### Method-7: Copy Files/Folders From A Local System To Multiple Remote System In Linux With Non-Standard Port Number?
|
||||
|
||||
Use the below shell script to copy a file or folder if you are using Non-Standard port.
|
||||
|
||||
If you are using `Non-Standard` port, make sure you have to mention the port number as follow for SCP command.
|
||||
|
||||
```
|
||||
# file-copy-scp.sh
|
||||
|
||||
#!/bin/sh
|
||||
for server in `more server-list.txt`
|
||||
do
|
||||
scp -P 2222 -r $1 root@2g.CentOS.com$server:/opt/backup
|
||||
done
|
||||
```
|
||||
|
||||
Run the shell script and give the file name as a input.
|
||||
|
||||
```
|
||||
# ./file-copy.sh ovh.sh
|
||||
|
||||
ovh.sh 100% 3558 3.5KB/s 00:00
|
||||
ovh.sh 100% 3558 3.5KB/s 00:00
|
||||
```
|
||||
|
||||
If you are using `Non-Standard` port, make sure you have to mention the port number as follow for rsync command.
|
||||
|
||||
```
|
||||
# file-copy-rsync.sh
|
||||
|
||||
#!/bin/sh
|
||||
for server in `more server-list.txt`
|
||||
do
|
||||
rsync -avzhe 'ssh -p 2222' $1 root@2g.CentOS.com$server:/opt/backup
|
||||
done
|
||||
```
|
||||
|
||||
Run the shell script and give the file name as a input.
|
||||
|
||||
```
|
||||
# ./file-copy-rsync.sh passwd-up.sh
|
||||
sending incremental file list
|
||||
passwd-up.sh
|
||||
|
||||
sent 238 bytes received 35 bytes 26.00 bytes/sec
|
||||
total size is 159 speedup is 0.58
|
||||
|
||||
sending incremental file list
|
||||
passwd-up.sh
|
||||
|
||||
sent 238 bytes received 35 bytes 26.00 bytes/sec
|
||||
total size is 159 speedup is 0.58
|
||||
```
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/linux-scp-rsync-pscp-command-copy-files-folders-in-multiple-servers-using-shell-script/
|
||||
|
||||
作者:[Prakash Subramanian][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/prakash/
|
||||
[b]: https://github.com/lujun9972
|
||||
@@ -0,0 +1,141 @@
|
||||
微型计算机的始祖:Altair 8800
|
||||
======
|
||||
《大众电子》的订阅者是个复杂的群体,杂志编辑 Arthur Salsberg 不得不在 [1974 年 12 月刊][1] 中的前言部分指出这点。此前,杂志编辑组曾收到了对《如何搭建家庭媒体中心》文章的抱怨,称这篇文章激励了许多业余电视爱好者走出去,削弱了专业修理人员存在的必要性,这对许多人的电视造成了极大伤害。Salsberg 认为,这个担忧的产生可能是因为大家不清楚《大众电子》读者们的真实水平。他解释道,杂志内部调查的数据显示,52 % 的订阅者都是某方面的电子专家,并且其中的 150,000 人在最近 60 天之内都修过电视。此外,订阅者们平均在电子产品上花费了 470 美金(2018 年则是 3578 美金),并且他们有对万用表、真空管伏特计、电子管测试仪、晶体管测试仪、射频讯号产生器和示波器的需求。“《大众电子》的读者们并不全都是新手。”Salsberg 总结道。
|
||||
|
||||
熟悉《大众电子》的人居然会质疑它的订阅者,这令我十分吃惊。不过最近 60 天我的确没修过电视。我的电脑对我来说就是一块铝,我甚至没把它拆开看过。1974 年 12 月的《大众电子》刊登的像《驻波比是什么以及如何处理它》和《对万用表的测试》之类的特色文章,甚至连广告都令人生畏。它们中有个看起来像某种立体声系统的东西大胆地写道“除了‘四通道单元(即内建的 SQ、RM 和 CD-4 解码接收器)’,没有任何音频设备是被期待的”。这也表明了《大众电子》的订阅者一定对电子有很多深入的了解。
|
||||
|
||||
不过在 [1975 年 1 月刊][2] 中,杂志为读者们带来了一些他们从没见过的东西。在标题“发现项目”下面,杂志的封面是一个黑灰色的盒子,它的前面板上有一组开关和灯。这便是 Altair 8800,“世界上首个有商业竞争力的迷你计算机”,它的售价低于 400 美元。尽管 Altair 作为“迷你计算机”被宣传,但其实大家都将它称为“微机”和PC,它是首个商业上成功的新型电脑。Altair 十分小巧而且很便宜,以至于它成为了当时家家户户都能用起的电脑。正如 Salsberg 所写道,它在《大众电子》上的出现意味着:“家用电脑的时代终于到来了。”
|
||||
|
||||
![《大众电子》1975 年 1 月刊的封面][3]
|
||||
|
||||
此前,我曾写过 [关于 Altair 的文章][4],但我觉得 Altair 有让我再次介绍的价值。它在当时性能并不强(虽然它便宜很多),也不是首个装载微处理器(由至少三个微处理器组成)的通用计算机。但是 Altair 是一种可供我们所有人使用的计算机。它是历史上包括我们所拥有的设备中首台流行的计算机,早于 Altair 计算机都是完全不同的机器,它们由穿孔卡编程并且很少与用户交互。不过 Altair 也是台极其简单的计算机,它不附带任何操作系统甚至引导加载器。除非你购买其它外设,否则 Altair 就是一台装配 RAM 并且只有一组开关和灯泡的机器。由于 Altair 操作简单,学习计算的基本理论都成了十分简单的事情,就好像他们在数字世界冒险时遇上了旧世界的居民一样。
|
||||
|
||||
### Roberts 和他的公司
|
||||
|
||||
Altair 被一家名为 MITS 的公司设计和制造,这家公司位于美国新墨西哥州的阿尔布开克。MITS 由一个叫 H. Edward Roberts 运营。他们起初借 19 世纪 70 年代的热潮制造模型火箭的遥测系统。集成电路将计算器的成本降低到十分可观的数字,突然之间它就成了美国教授们的必需品。不幸的是,由于计算器市场竞争过于激烈,到了 1974 年,MITS 便负债累累。
|
||||
|
||||
1974 年在计算机界是<ruby>奇迹迭出的一年<rt>annus mirabilis</rt></ruby>。一月的时候,惠普公司推出了世界首个可编程的手持计算器 HP-65。四月的时候,Intel 发布了 Intel 8080,他们的第二款 8 位微处理器,它也是首款受欢迎的微处理器。接着,六月的时候,《Radio Electronics》杂志介绍了 Mark-8 这个自制迷你计算机,它使用了 Intel 在 1972 年推出的 Intel 8008 微处理器。Mark-8 是使用微处理器搭建的第三台电脑,它的首次登场是在杂志的封面上。Mark-8 在《Radio Electronics》上的出现促使了《大众电子》寻找微机项目的出现。
|
||||
|
||||
《大众电子》的订阅者们其实早在 1974 年 12 月就通过电邮获得了 1975 年 1 月刊的副本。他们公布的 Altair 为这个<ruby>奇迹迭出的一年<rt>annus mirabilis</rt></ruby>画上了圆满的句号。Altair 的出现是十分重要的,因为此前从未有过向公众提供的价格公道而又功能齐全的电脑。当时,作为最受欢迎的迷你计算机之一的 PDP-8 要几千美金才能买到。不过 Altair 搭载的 Intel 8080 芯片几乎能与 PDP-8 匹敌;8080 支持更广泛的指令集,而且 Altair 可以扩展到 64 kb 内存,显然强于仅有 4 kb 内存的 PDP-8。并且,Mark-8 也不是他的对手,因为它搭载的是只能处理 16 kb 内存的 Intel 8008。在 Mark-8 必须由用户按照说明书手动拼装的情况下,Altair 在购买时就已经被组装好了(不过由于后来 MITS 被大量订单淹没,最后真正能获得 Altair 的方式也只有买零件拼装了)。
|
||||
|
||||
对许多《大众电子》的读者来说,Altair 是他们了解数字计算的起点。1975 年 1 月刊上那篇介绍 Altair 的文章由 Roberts 和 Altair 的联合设计师 William Yates 所写。Roberts 和 Yates 煞费苦心地用电工和无线电狂热者们所熟悉的词汇来介绍了数字硬件和计算机编程的基本概念。他们写道:“一台计算机其实由一堆可变的硬件构成。仅需修改储存于内存之中的为组合形式,便可改变硬件设备的种类。”同时,Roberts 和 Yates 认为编程的基本概念是“足够简单并能在较短时间内掌握,但是想要成为一个高效的程序员必须经验丰富且富有创造力。”对此我十分认同。尽管已经组装好了,文章仍包含了用来讲解 Intel 8080 的组成的详细图表。文章解释了 CPU 和计算机内存单元的区别,堆栈指针的概念和汇编语言以及更高级的语言(例如 FORTRAN 和 BASIC)比起手动输入机器码所带来的巨大优势。
|
||||
|
||||
其实,《大众电子》在 1975 年 1 月刊之前就出版过 Roberts 撰写的系列文章。这一系列作为短期课程被收录在“数字逻辑”专栏中。在 1974 年 12 月刊中,Roberts 为读者们带来了关于构建“超低成本计算机终端”的文章,文章中介绍了可以用于 8 位电脑中输入值的八进制键盘。在介绍这个键盘时,Roberts 解释了晶体管到晶体管的逻辑工作原理,以及关于构建一种可以“记住”数字值的触发器的方法。Roberts 承诺说,这个键盘可以在下个月即将公布的 Altair 电脑中使用。
|
||||
|
||||
有多少《大众电子》的读者制作了这个键盘我们无从得知,但是那个键盘的确是个很有用的东西。如果没有键盘和其它输入设备,我们只能通过拨动 Altair 面板上的开关来输入值。Altair 的面板上有 16 行开关被用来设置地址,而下方的 8 个则是用来操作计算机的。16 行中最右边的开关是用来指定要储存在内存中的值的。这么做不无道理,因为 Intel 8080 使用 16 位的值来处理 8 位的信息。而这 16 个开关每一个都代表了一个位,当开关向上时代表 1,向下则代表 0。用这样的方式交互是个启示(一会儿我们就会讲到),因为 Altair 的面板是真正的二进制界面。这使得你可以触摸到裸露的金属。
|
||||
|
||||
尽管在当下 Altair 的界面对我们来说完全不像是人用的,不过在那个时候这可是不平凡的。比如 PDP-8 的面板上有个类似的但更漂亮的二进制输入装置,而且它被涂上了吸引人的黄色和橙色,不过讲真,它应该重新来过。然而 PDP-8 经常与纸带阅读器或电传打字机配合使用,这使得程序输入更加容易。这些 I/O 设备价格高昂,这意味着 Altair 的用户们大都会被面板卡住。正如你所想,通过这一堆开关进入一个大型程序是个繁重的工作。不过幸运的是,Altair 可以与盒式记录器连接,这样一来载入程序就不是什么难事了。Bill Gates 和 Paul Allen 进行了微软的首次商业合作,为 Altair 编写了 BASIC 语言,并在 1975 年以 MITS 许可证发行。此后,那些买得起电传打字机的用户就能 [通过纸带来将 BASIC 载入 Altair][5] 了,并能使得用户能够通过字符界面与 Altair 交互。之后,BASIC 便成为了学生们最爱的入门编程语言,并成了早期微机时代的标准接口。
|
||||
|
||||
### z80pack
|
||||
|
||||
多亏了网络上一些人,特别是 Udo Munk 的努力,你可以在你的电脑上运行 Altair 的模拟器。这个模拟器是在 Zilog Z80 CPU 的虚拟套件上构建的,这个 CPU 可以运行 Intel 8080 的软件。Altair 模拟器允许你像 Altair 的用户们一样调整面板上的开关。尽管点击这些开关的感觉不如拨动真实开关,但是使用 Altair 模拟器仍是一个能让你知道二进制人机交互效率有多低的途径,不过我觉得这同时也很简明直观。
|
||||
|
||||
z80pack 是 Udo Munk 开发的 Z80 模拟器套件,你可以在 z80pack 的官网上找到它的下载链接。我在 [上一篇介绍 Altair 的文章中][4] 写到过在 macOS 上使用它的详细过程。如果你能编译 FrontPanel 库和 `altairsim` 可执行程序,你应该能直接运行 `altairsim` 并看到这个窗口:
|
||||
|
||||
![模拟器中的 Altair 面板][6]
|
||||
|
||||
在新版的 z80pack 中(比如我正在使用的 1.36 版本),你可以使用一个叫 Tarbell boot ROM 的功能,我觉得这是用来加载磁盘镜像的。经我测试,它的意思是你不能写入 RAM 中的前几个信息。在编辑 `/altairsim/conf/system.conf` 之后,你可以构建带有一个 16 页 RAM 且没有 ROM 或引导加载器的 Altair。除此之外,你还可以用这个配置文件来扩大运行模拟器的窗口,不得不说这还是挺方便的。
|
||||
|
||||
Altair 的面板看起来就很吓人,不过事实上并没有我们想象中的这么可怕。[Altair 说明书][7] 对解释开关和指示灯起到了很大的作用,这个 [YouTube 视频][8] 也是。若想运行一个简易的程序,你只需要了解一点点东西。Altair 右上方标签为 D0 到 D7 的指示灯代表当前处理地址的信息。标签为 A0 到 A15 的指示灯标识当前的地址。地址指示灯下的 16 个开关可以用来设置新地址;当 “EXAMINE” 开关被向上推动时,数据指示灯将会更新,并显示新地址上的内容。用这个功能,你便能观察到内存中所有的信息了。你也可以将 “EXAMINE” 推下来自动检查下一个位置上的信息,这使得检索信息更容易了。
|
||||
|
||||
要将模式保存到信息中,请使用最左边的 8 个标签为 0 到 7 的开关。然后,请向上推动 “DEPOSIT” 按钮。
|
||||
|
||||
在《大众电子》 的 [1975 年 2 月刊][9] 中,Roberts 和 Yates 制作了一小段程序来确保用户们的 Altair 正常工作。这个程序从内存中读取两个整型数据并添加之后将它们存回内存中。这个小程序仅由 6 条指令组成,但是这 6 条指令包含了 14 条在一起的内存信息,所以要正确地输入它们需要一点时间。这个程序也被写入了 Altair 的说明书,原文如下:
|
||||
|
||||
| Address | Mnemonic | Bit Pattern | Octal Equivalent |
|
||||
| :------: | :------: | :------: | :------: |
|
||||
| 0 | LDA | 00 111 010 | 0 7 2 |
|
||||
| 1 | (address) | 10 000 000 | 2 0 0 |
|
||||
| 2 | (address) | 00 000 000 | 0 0 0 |
|
||||
| 3 | MOV B, A | 01 000 111 | 1 0 7 |
|
||||
| 4 | LDA | 00 111 010 | 0 7 2 |
|
||||
| 5 | (address) | 10 000 001 | 2 0 1 |
|
||||
| 6 | (address) | 00 000 000 | 0 0 0 |
|
||||
| 7 | ADD B | 10 000 000 | 2 0 0 |
|
||||
| 8 | STA | 00 110 010 | 0 6 2 |
|
||||
| 9 | (address) | 10 000 010 | 2 0 2 |
|
||||
| 10 | (address) | 00 000 000 | 0 0 0 |
|
||||
| 11 | JMP | 11 000 011 | 3 0 3 |
|
||||
| 12 | (address) | 00 000 000 | 0 0 0 |
|
||||
| 13 | (address) | 00 000 000 | 0 0 0 |
|
||||
|
||||
如果你通过开关来输入上面这些值,最终会得到一个程序,它会读取内存 128 中的值,并将其添加至 129 中,最终将其保存至 130 中。每条指令都会占用一个地址,它们最开始会被给予最低有效位,这便是第二个字节总会被清零(没有高于 255 的地址)的原因了。在输入这个程序并在 128 和 129 中输入了一些值之后,你可以向下推动 “RUN” ,之后再将它推到 “STOP” 位置。因为程序循环执行,以一秒内执行上千次的速度反复地添加并保存那些值。并且最后得到的值总是相同的,如果你暂停程序并检查 130,你应该能找到正确答案。
|
||||
|
||||
我不知道普通的 Altair 用户是否使用过,不过 z80pack 包括了一个汇编程序 —— `z80asm`,意思是<ruby>适用于 Z80 的汇编程序<rt>Z80 assembly</rt></ruby>,所以它使用了不同的助记符。不过因为 Z80 是被设计来适配为 Intel 8080 写的软件的,所以即使助记符不一样,它们的操作码也是相同的。你可以直接将 `z80asm` 装载进 Altair:
|
||||
|
||||
```
|
||||
ORG 0000H
|
||||
START: LD A,(80H) ;Load from address 128.
|
||||
LD B,A ;Move loaded value from accumulator (A) to reg B.
|
||||
LD A,(81H) ;Load from address 129.
|
||||
ADD A,B ;Add A and B.
|
||||
LD (82H),A ;Store A at address 130.
|
||||
JP START ;Jump to start.
|
||||
```
|
||||
|
||||
编译之后,你可以调用汇编程序来将其转换为 Intel HEX 文件:
|
||||
|
||||
```shell
|
||||
$ ./z80asm -fh -oadd.hex add.asm
|
||||
```
|
||||
|
||||
我们用带有 `h` 参数的 `-f` 标识来定义输出的 HEX 文件。你可以用 `-x` 标识来传递 HEX 文件,从而使得 Altair 能够加载程序:
|
||||
|
||||
```shell
|
||||
$ ./altairsim -x add.hex
|
||||
```
|
||||
|
||||
这会在内存中自动设置前 14 个信息,就和你通过开关手动输入这些值一样。你可以直接使用 “RUN” 按钮来替代以前那些繁琐的步骤,这是如此的简单!
|
||||
|
||||
我不觉得有很多 Altair 用户以这种方式来编写软件。Altair BASIC 发布后,使得 BASIC 成为了 Altair 编程最简单的方法。z80pack 同时也包括了一些包含不同版本 Altair BASIC 的 HEX 文件;在模拟器中,你可以用这个方式加载 4.0 版本的 4K BASIC:
|
||||
|
||||
```shell
|
||||
$ ./altairsim -x basic4k40.hex
|
||||
```
|
||||
|
||||
当你开启模拟器并按下 “RUN” 按钮之后,你就会看到 BASIC 开始执行了,同时它会在终端中与你交互。它首先会提示你输入你内存的可用量,我们输入 4000 字节。随后,在显示 “OK” 提示符之前,它会问你几个问题,Gates 和 Allen 用这个来代替标准的 “READY” 并以此节省内存。在这之后,你便可以使用 BASIC 了:
|
||||
|
||||
```
|
||||
OK
|
||||
PRINT 3 + 4
|
||||
7
|
||||
```
|
||||
|
||||
尽管只有极小的 4 kb 空间来运行 BASIC,不过你仍迈出了使用面板操控电脑的重要一步。
|
||||
|
||||
很显然,Altair 远不及如今的家用电脑,并且比它晚十多年发布的 Mac 电脑看上去也是对 Altair 电脑的巨大飞跃。但是对亲手组装了 Altair 的《大众电子》的读者们来说,只用了低于 400 美金和一半的书柜空间的 Altair 才是第一个它们真正能拥有的全功能电脑。对那时只能用 [一叠卡片][10] 或一卷磁带来与计算机交互的人们来说,Altair 是个令人眼前一亮的玩意。这之后的微机基本都是在对 Altair 改进,使得它更易用。从某种意义上来说,我们甚至可以把它们看成更复杂的 Altair。Altair,一个野兽派的极简作品,却为之后的许多微机打下了铺垫。
|
||||
|
||||
如果你觉得这篇文章写的不错,你可以在推特上关注 [@TwoBitHistory][11] 或订阅 [RSS feed][12] 来获得我们文章的更新提醒。文章每两周就会更新一次!
|
||||
|
||||
TwoBitHistory 的上一篇文章是…………
|
||||
|
||||
> “跟我一起来进行这振奋人心的冒险吧!只需要十分钟,你就能了解到 10 年都没人用过的软件。” <https://t.co/R9zA5ibFMs>
|
||||
>
|
||||
> — TwoBitHistory (@TwoBitHistory) [写于 2018 年 7 月 7 日][13]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://twobithistory.org/2018/07/22/dawn-of-the-microcomputer.html
|
||||
|
||||
作者:[Two-Bit History][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[zhs852](https://github.com/zhs852)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://twobithistory.org
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1974/Poptronics-1974-12.pdf
|
||||
[2]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1975/Poptronics-1975-01.pdf
|
||||
[3]: https://twobithistory.org/images/jan1975-altair.jpg
|
||||
[4]: https://twobithistory.org/2017/12/02/simulating-the-altair.html
|
||||
[5]: https://www.youtube.com/watch?v=qv5b1Xowxdk
|
||||
[6]: https://www.autometer.de/unix4fun/z80pack/altair.png
|
||||
[7]: http://www.classiccmp.org/dunfield/altair/d/88opman.pdf
|
||||
[8]: https://www.youtube.com/watch?v=suyiMfzmZKs
|
||||
[9]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1975/Poptronics-1975-02.pdf
|
||||
[10]: https://twobithistory.org/2018/06/23/ibm-029-card-punch.html
|
||||
[11]: https://twitter.com/TwoBitHistory
|
||||
[12]: https://twobithistory.org/feed.xml
|
||||
[13]: https://twitter.com/TwoBitHistory/status/1015647820353867776?ref_src=twsrc%5Etfw
|
||||
@@ -0,0 +1,87 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (oneforalone)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Two Years With Emacs as a CEO (and now CTO))
|
||||
[#]: via: (https://www.fugue.co/blog/2018-08-09-two-years-with-emacs-as-a-cto.html)
|
||||
[#]: author: (Josh Stella https://www.fugue.co/blog/author/josh-stella)
|
||||
|
||||
作为 CEO 使用 Emacs 的两年经验之谈(现任 CTO)
|
||||
======
|
||||
|
||||
两年前,我写了一篇[博客][1],并取得了一些反响。这让我有点受宠若惊。那篇博客写的是我准备将 Emacs 作为我的主办公软件,当时我还是 CEO,现在已经转为 CTO 了。现在回想起来,我发现我之前不是做程序员就是做软件架构师,而且那时我也喜欢用 Emacs 写代码。重新考虑 Emacs 是一次很不错的尝试,但我不太清楚具体该怎么实现。在网上,那篇博客也是褒贬不一,但是还是有数万的阅读量,所以总的来说,我写的还是不错的。在 [Reddit][2] 和 [HackerNews][3] 上有些令人哭笑不得的回复,说我的手会变形,或者说我会因白色的背景而近视。在这里我可以很肯定的回答 —— 完全没有这回事,相反,我的手腕还因此变得更灵活了。还有一些人担心,说使用 Emacs 会耗费一个 CEO 的精力。把 Fugue 从在家得到的想法变成强大的产品,并有一大批忠实的顾客,我觉得 Emacs 可以让你从复杂的事务中解脱出来。我现在还在用白色的背景。
|
||||
|
||||
近段时间那篇博客又被翻出来了,并发到了 [HackerNews][4] 上。我收到了大量的跟帖者问我现在怎么样了,所以我写这篇博客来回应他们。在本文中,我还将重点讨论为什么 Emacs 和函数式编程有很高的相关性,以及我们是怎样使用 Emacs 来开发我们的产品 —— Fugue,一个使用函数式编程的自动化的云计算平台。由于我收到了很多反馈,比较有用的是一些细节的详细程度和有关背景色的注解,因此这篇博客比较长,而我确实也需要费点精力来解释我的想法,但这篇文章的主要内容还是反映了我担任 CEO 时处理的事务。而我想在之后更频繁地用 Emacs 写代码,所以需要提前做一些准备。一如既往,本文因人而异,后果自负。
|
||||
|
||||
### 意外之喜
|
||||
|
||||
我大部分时间都在不断得处理公司内外沟通。交流是解决问题的唯一方法,但也是反思及思考困难或是复杂问题的敌人。对我来说,作为创业公司的 CEO,最需要的是有时间专注工作而不别打扰。一旦开始投入时间来学习一些命令,Emacs 就很适合这种情况。其他的应用弹出提示,但是配置好了的 Emacs 就可以完全的忽略掉,无论是视觉上还是精神上。除非你想修改,否则的话他不会变,而且没有比空白屏幕和漂亮的字体更干净的界面了。在我不断被打扰的情况下,这种简洁让我能够专注于我在想什么,而不是电脑。好的程序能够默默地对电脑的进行访问。
|
||||
|
||||
一些人指出,原来的帖子既是对现代图形界面的批判,也是对 Emacs 的赞许。我既不赞同,也不否认。现代的接口,特别是那些以应用程序为中心的方法(相对于以内容为中心的方法),既不是以用户为中心的,也不是面向进程的。Emacs 避免了这种错误,这也是我如此喜欢它的部分原因,而它也带来了其他优点。Emacs 是进入计算机本身的入口,这打开了一扇新世界的大门。它的核心是发现和创造属于自己的道路,对我来说这就是创造的定义。现代电脑的悲哀之处在于,它很大程度上是由带有闪亮界面的黑盒组成的,这些黑盒提供的是瞬间的满足感,而不是真正的满足感。这让我们变成了消费者,而不是技术的创造者。我不在乎你是谁或者你的背景是什么;你可以理解你的电脑,你可以用它做东西。它很有趣,令人满意,而且不是你想的那么难学!
|
||||
|
||||
我们常常低估了环境对我们心理的影响。Emacs 给人一种平静和自由的感觉,而不是紧迫感、烦恼或兴奋——后者是思想和沉思的敌人。我喜欢那些持久的,不碍事的东西,当我花时间去关注它们的时候,它们会给我带来真知灼见。Emacs 满足我的所有这些标准。我每天都使用 Emacs 来创建内容,我也很高兴我很少考虑它。Emacs 确实有一个学习曲线,但不会比学自行车更陡,而且一旦你完成了它,你会得到相应的回报,你就不必再去想它了,它赋予你一种其他工具所没有的自由感。这是一个优雅的工具,来自一个更加文明的时代。我很高兴我们步入了另一个计算机时代,而 Emacs 也将越来越受欢迎。
|
||||
|
||||
### 放弃用 Emacs 规划日程及处理待办事项
|
||||
|
||||
在原来的文章中,我花了一些时间介绍如何使用 Org 模式来规划日程。我放弃了使用 Org 模式来处理待办事项之类的,因为我每天都有很多会要开,很多电话要打, 而我也不能让其他人来适应我选的工具,我也没有时间将事务转换或是自动移动到 Org 上 。我们主要是用 Mac shop,使用谷歌日历等,原生的 Mac OS/iOS 工具可以很好的进行协作。我还有支比较旧的笔用来在会议中做笔记,因为我发现在会议中使用笔记本电脑或者说键盘很不礼貌,而且这也限制了我的聆听和思考。因此,我基本上放弃了用 Org 帮我规划日程或安排生活的想法。当然,Org 模式对其他的方面也很有用,它是我编写文档的首选,包括本文。换句话说,我与其作者背道而驰,但它在这方面做得很好。我也希望有一天也有人这么说我们在 Fugue 的工作。
|
||||
|
||||
### Emacs 在 Fugue 已经扩散
|
||||
|
||||
我在上篇博客就有说,你可能会喜欢 Emacs,也可能不会。因此,当 Fugue 的文档组将 Emacs 作为标准工具时,我是有点担心的,因为我觉得他们可能是受了我的影响。几年后,我确信他们做出了个正确的选择。那个组长是一个很聪明的程序员,但是那两个编写文档的人却没有怎么接触过技术。我想,如果这是一个经理强加错误工具的案例,我就会得到投诉并去解决,因为 Fugue 有反威权文化,大家不怕惹麻烦,包括我在内。之前的组长去年辞职了,但[文档组][5]现在有了一个灵活的集成的 CI/CD 工具链。并且文档组的人已经成为了 Emacs 的忠实用户。Emacs 有一条学习曲线,但即使很陡,也不会那么陡,翻过后对生产力和总体幸福感都有益。这也提醒我们,学文科的人在技术方面和程序员一样聪明,一样能干,也许不应该那么倾向于技术而产生派别歧视。
|
||||
|
||||
### 我的手腕得益于我的决定
|
||||
|
||||
上世纪80年代中期以来,我每天花12个小时左右在电脑前工作,这给我的手腕(以及后背)造成了很大的损伤,在此我强烈安利 Tag Capisco 的椅子。Emacs 和人机工程学键盘的结合让手腕的 [RSI][10](Repetitive Strain Injury/Repetitive Motion Syndrome) 问题消失了,我已经一年多没有想过这种问题了。在那之前,我的手腕每天都会疼,尤其是右手,如果你也遇到这种问题,你就知道这很让人分心和担心。有几个人问过键盘和鼠标的问题,如果你感兴趣的话,我现在用的是[这款键盘][6]。虽然在过去的几年里我主要使用的是真正符合人体工程学的键盘。我已经换成现在的键盘有几个星期了,而且我爱死它了。键帽的形状很神奇,因为你不用看就能知道自己在哪里,而拇指键设计的很合理,尤其是对于 Emacs, Control和Meta是你的固定伙伴。不要再用小指做高度重复的任务了!
|
||||
|
||||
我使用鼠标的次数比使用 Office 和 IDE 时要少得多,这对我有很大帮助,但我还是会用鼠标。我一直在使用外观相当过时,但功能和人体工程学明显优越的轨迹球,这是名副其实的。
|
||||
|
||||
撇开具体的工具不谈,最重要的一点是,事实证明,一个很棒的键盘,再加上避免使用鼠标,在减少身体的磨损方面很有效。Emacs 是这方面的核心,因为我不需要在菜单上滑动鼠标来完成任务,而且导航键就在我的手指下面。我肯定,手离开标准打字姿势会给我的肌腱造成很大的压力。这因人而异,我也不是医生。
|
||||
|
||||
### 还没完成大部分配置……
|
||||
|
||||
有人说我会在界面配置上花很多的时间。我想验证下他们说的对不对,所以我留意了下。我不仅让配置基本上不受影响,关注这个问题还让我意识到我使用的其他工具是多么的耗费我的精力和时间。Emacs 是我用过的维护成本最低的软件。Mac OS 和 Windows 一直要求我更新它,但在我我看来,这远没有 Adobe 套件和 Office 的更新的困恼那么大。我只是偶尔更新 Emacs,但也没什么变化,所以对我来说,它基本上是一个接近于零成本的操作,我高兴什么时候跟新就什么时候更新。
|
||||
|
||||
有一点然你们失望了,因为许多人想知道我为跟上 Emacs 社区的更新及其输出所做的事情,但是在过去的两年中,我只在配置中添加了一些内容。我认为也是成功的,因为 Emacs 只是一个工具,而不是我的爱好。也就是说,如果你想和我分享,我很乐意听到新的东西。
|
||||
|
||||
### 期望实现控制云端
|
||||
|
||||
我们在 Fugue 有很多 Emacs 的粉丝,所以我们有一段时间在用 [Ludwing 模式][7]。Ludwig 是我们用于自动化云基础设施和服务的声明式、功能性的 DSL。最近,Alex Schoof 利用飞机上和晚上的时间来构建 fugue 模式,它在 Fugue CLI 上充当 Emacs 控制台。要是你不熟悉 Fugue,我们会开发一个云自动化和管理工具,它利用函数式编程为用户提供与云的 api 交互的良好体验。它做的不止这些,但它也做了。fugue 模式很酷的原因有很多。它有一个不断报告云基础设备状态的缓冲区,而由于我经常修改这些设备,所以我可以快速看到编码的效果。Fugue 将云工作负载当成进程处理,fugue 模式非常类似于云工作负载的 top 模式。它还允许我执行一些操作,比如创建新的设备或删除过期的东西,而且也不需要太多输入。Fugue 模式只是个雏形,但它非常方便,而我现在也经常使用它。
|
||||
|
||||
![fugue-mode-edited.gif][8]
|
||||
|
||||
### 模式及监听
|
||||
|
||||
我添加了一些模式和集成插件,但并不是真正用于 CEO 工作。我喜欢在周末时写写 Haskell 和 Scheme,所以我添加了 haskell 模式和 geiser。Emacs 对具有 REPL 的语言很友好,因为你可以在不同的窗口中运行不同的模式,包括 REPL 和 shell。Geiser 和 Scheme 很配,要是你还没有这样做过,那么用 SICP 工作也不失为一种乐趣,在这个有很多土鳖编程的例子的时代,这可能是一种启发。安装 MIT Scheme 和 geiser,你就会感觉有点像 lore 的符号环境。
|
||||
|
||||
这就引出了我在 15 年的文章中没有提到的另一个话题:屏幕管理。我喜欢使用用竖屏来写作,我在家里和我的主要办公室都有这个配置。对于编程或混合使用,我喜欢 fuguer 提供的新的超宽显示器。对于宽屏,我更喜欢将屏幕分成三列,中间是主编辑缓冲区,左边是水平分隔的 shell 和 fugue 模式缓冲区,右边是文档缓冲区或另一个或两个编辑缓冲区。这个很简单,首先按 'Ctl-x 3' 两次,然后使用 'Ctl-x =' 使窗口的宽度相等。这将提供三个相等的列,你也可以使用 'Ctl-x 2' 进行水平分割。以下是我的截图。
|
||||
|
||||
![Emacs Screen Shot][9]
|
||||
|
||||
### 最后一篇 CEO/Emacs 文章……
|
||||
|
||||
首先,我现在是 Fugue 的 CTO,其次我也想要写一些其他方面的博客,而我现在刚好有时间。我还打算写些更深入的东西,比如说函数式编程、基础结构类型安全,以及我们即将推出一些的新功能,还有一些关于 Fugue 在云上可以做什么。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.fugue.co/blog/2018-08-09-two-years-with-emacs-as-a-cto.html
|
||||
|
||||
作者:[Josh Stella][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/oneforalone)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.fugue.co/blog/author/josh-stella
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://blog.fugue.co/2015-11-11-guide-to-emacs.html
|
||||
[2]: https://www.reddit.com/r/emacs/comments/7efpkt/a_ceos_guide_to_emacs/
|
||||
[3]: https://news.ycombinator.com/item?id=10642088
|
||||
[4]: https://news.ycombinator.com/item?id=15753150
|
||||
[5]: https://docs.fugue.co/
|
||||
[6]: https://shop.keyboard.io/
|
||||
[7]: https://github.com/fugue/ludwig-mode
|
||||
[8]: https://www.fugue.co/hubfs/Imported_Blog_Media/fugue-mode-edited-1.gif
|
||||
[9]: https://www.fugue.co/hs-fs/hubfs/Emacs%20Screen%20Shot.png?width=929&name=Emacs%20Screen%20Shot.png
|
||||
[10]: https://baike.baidu.com/item/RSI/21509642
|
||||
@@ -1,76 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (beamrolling)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (You (probably) don't need Kubernetes)
|
||||
[#]: via: (https://arp242.net/weblog/dont-need-k8s.html)
|
||||
[#]: author: (Martin Tournoij https://arp242.net/)
|
||||
|
||||
你(大概)不需要 Kubernetes
|
||||
======
|
||||
|
||||
这也许是一个不太受欢迎的观点,但大多数主流公司最好不要再使用 k8s 了。
|
||||
|
||||
你知道那个古老的“根据程序员技能写 Hello world ”笑话吗?它从一个新手程序员的 printf("hello, world\n") 语句开始,最后结束于高级软件架构工程师令人费解的 Java OOP 模式设计。使用 k8s 就有点像这样。
|
||||
|
||||
* 新手 SysOp:
|
||||
`./binary`
|
||||
* 有经验的 SysOp:
|
||||
在 EC2 上的 `./binary`
|
||||
* DevOp:
|
||||
在 EC2 上自部署的 CI 管道运行 `./binary`
|
||||
* 高级云编排工程师:
|
||||
在 EC2 上通过 k8s 编排的自部署 CI 管道运行 `./binary`
|
||||
|
||||
|
||||
|
||||
¯\\_(ツ)_/¯
|
||||
|
||||
这不意味着 Kubernetes 或者任何这样的东西本身都是坏的,就像 Java 或者 OOP 设计本身并不是坏的一样,但是,在很多情况下,它们被严重地误用,就像在一个 hello world 的程序中可怕地误用 Java 面向对象设计模式一样。对大多数公司而言,系统运维从根本上来说并不十分复杂,此时在这上面应用 k8s 起效甚微。
|
||||
|
||||
复杂性本质上来说创造了工作,我十分怀疑使用 k8s 对大多数使用者来说是省时的这一说法。这就好像花一天时间来写一个脚本,用来自动完成一些你一个月一次,每次只花 10 分钟完成的工作。这不是一个好的时间投资(特别是你可能会在未来由于扩展或调试这个脚本来进一步投入更多的时间)。
|
||||
|
||||
你的部署大概应该需要自动化 – 以免你 [最终像 Knightmare][1] 那样 – 但 k8s 通常可以被一个简单的 shell 脚本所替代。
|
||||
|
||||
在我们公司,sysops 团队用了很多时间来设置 k8s 。他们还不得不用了很大一部分时间来更新到新一点的版本(1.6 – 1.8)。结果是如果没有真正深入理解 k8s ,没人会真正明白一些东西,甚至连深入理解 k8s 这一点也很难(那些 YAML 文件,哦呦!)
|
||||
|
||||
在我能自己调试和修复问题之前——现在这更难了,我理解基本概念,但在真正调试实际问题的时候,它们并不是那么有用。我不经常用 k8s 足以证明这点。
|
||||
|
||||
k8s 真的很难这点并不是什么新看法,这也是为什么现在会有这么多“ k8s 简单学”的解决方案。在 k8s 上再添一层来“让它更简单”的方法让我觉得,呃,不明智。复杂性并没有消失,你只是把它藏起来了。
|
||||
|
||||
以前我说过很多次:在确定一样东西是否“简单”时,我最关心的不是写东西的时候有多简单,而是当失败的时候调试起来有多容易。包装 k8s 并不会让调试更加简单,恰恰相反,它让事情更加困难了。
|
||||
|
||||
Blaise Pascal 有一句名言:
|
||||
|
||||
> 几乎所有的痛苦都来自于我们不善于在房间里独处。
|
||||
|
||||
k8s —— 略微拓展一下,Docker ——似乎就是这样的例子。许多人似乎迷失在当下的兴奋中,觉得“ k8s 就是这么回事!”,就像有些人迷失在 Java OOP 刚出来时的兴奋中一样,所以一切都必须从“旧”方法转为“新”方法,即使“旧”方法依然可行。
|
||||
|
||||
有时候 IT 产业挺蠢的。
|
||||
|
||||
或者用 [一条推特][2] 来总结:
|
||||
|
||||
> 2014 - 我们必须采用 #微服务 来解决 monolith 的所有问题
|
||||
> 2016 - 我们必须采用 #docker 来解决微服务的所有问题
|
||||
> 2018 - 我们必须采用 #kubernetes 来解决 docker 的所有问题
|
||||
|
||||
你可以通过 [martin@arp242.net][3] 给我发邮件或者 [创建 GitHub issue][4] 来给我反馈或提出问题等。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://arp242.net/weblog/dont-need-k8s.html
|
||||
|
||||
作者:[Martin Tournoij][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[beamrolling](https://github.com/beamrolling)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://arp242.net/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://dougseven.com/2014/04/17/knightmare-a-devops-cautionary-tale/
|
||||
[2]: https://twitter.com/sahrizv/status/1018184792611827712
|
||||
[3]: mailto:martin@arp242.net
|
||||
[4]: https://github.com/Carpetsmoker/arp242.net/issues/new
|
||||
@@ -1,70 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (qhwdw)
|
||||
[#]: reviewer: ()
|
||||
[#]: publisher: ()
|
||||
[#]: url: ()
|
||||
[#]: subject: (Computer Laboratory – Raspberry Pi: Lesson 2 OK02)
|
||||
[#]: via: (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok02.html)
|
||||
[#]: author: (Robert Mullins http://www.cl.cam.ac.uk/~rdm34)
|
||||
|
||||
计算机实验室 – 树莓派:课程 2 OK02
|
||||
======
|
||||
|
||||
OK02 课程是在 OK01 课程的基础上构建,通过不停地打开和关闭 `OK` 或 `ACT` LED 指示灯来实现闪烁。假设你已经有了 [课程 1:OK01][1] 操作系统的代码,它将是这一节课的基础。
|
||||
|
||||
### 1、等待
|
||||
|
||||
等待是操作系统开发中非常有用的部分。操作系统经常发现自己无事可做,以及必须要延迟。在这个例子中,我们想去做等待,为了能够让这种等待可以看得见,让 LED 灯打开关闭闪烁起来。如果你只是打开和关闭它,你什么都看不到,因为计算机每秒种可以打开和关闭它好几千次。在后面的课程中,我们将看到精确的等待,但是现在,我们只要简单地去消耗时间就足够了。
|
||||
|
||||
```
|
||||
mov r2,#0x3F0000
|
||||
wait1$:
|
||||
sub r2,#1
|
||||
cmp r2,#0
|
||||
bne wait1$
|
||||
```
|
||||
|
||||
```
|
||||
sub reg,#val 从寄存器 reg 中的值上减去数字 val
|
||||
|
||||
cmp reg,#val 将寄存器中的值与数字 val 进行比较。
|
||||
|
||||
如果最后的比较结果是不相等,那么执行后面的 ne 命令。
|
||||
```
|
||||
|
||||
上面是一个很常见的产生延迟的代码片段,由于每个树莓派基本上是相同的,所以产生的延迟大致也是相同的。它的工作原理是,使用一个 `mov` 命令将值 3F0000<sub>16</sub> 推入到寄存器 r2 中,然后将这个值减 1,直到这个值减到 0 为止。在这里使用了三个新命令 `sub`、 `cmp` 和 `bne`。
|
||||
|
||||
`sub` 是减法命令,它只是简单地从第一个参数中的值减去第二个参数中的值。
|
||||
|
||||
`cmp` 是个很有趣的命令。它将第一个参数与第二个参数进行比较,然后将比较结果记录到一个称为当前处理器状态寄存器的专用寄存器中。你其实不用担心它,它记住的只是两个数谁大或谁小,或是相等而已。[^1]
|
||||
|
||||
`bne` 其实是一个伪装的分支命令。在 ARM 汇编语言家族中,任何指令都可以有条件运行。这意味着如果上一个比较结果是某个确定的结果,那个指令才会运行。这是个非常有意思的技巧,我们在后面将大量使用到它,但在本案例中,我们在 `b` 命令后面的 ne 后缀意思是 “只有在上一个比较的结果是值不相等,才去运行分支”。`ne` 后缀可以使用在任何命令上,其它几个(总共 16 个)条件也是如此,比如 `eq` 表示等于,而 `lt` 表示小于。
|
||||
|
||||
### 2、组合到一起
|
||||
|
||||
上一节讲我提到过,通过将 GPIO 地址偏移量设置为 28(即:str r1,[r0,#28])而不是 40 即可实现 LED 的关闭。因此,你需要去修改课程 OK01 的代码,在打开 LED 后,运行等待代码,然后再关闭 LED,再次运行等待代码,并包含一个回到开始位置的分支。注意,不需要重新启用 GPIO 的 16 号针脚的输出功能,这个操作只需要做一次就可以了。如果你想更高效,我建议你复用 r1 寄存器的值。所有课程都一样,你可以在 [下载页面][2] 找到所有的解决方案。需要注意的是,必须保证你的所有标签都是唯一的。当你写了 wait1\$: 你其它行上的标签就不能再使用 wait1\$ 了。
|
||||
|
||||
在我的树莓派上,它大约是每秒闪两次。通过改变我们所设置的 r2 寄存器中的值,可以很轻松地修改它。但是,不幸的是,我不能够精确地预测它的运行速度。如果你的树莓派未按预期正常工作,请查看我们的故障排除页面,如果它正常工作,恭喜你。
|
||||
|
||||
在这个课程中,我们学习了另外两个汇编命令:`sub` 和 `cmp`,同时学习了 ARM 中如何实现有条件运行。
|
||||
|
||||
在下一个课程,[课程 3:OK03][3] 中我们将学习如何编写代码,以及建立一些代码复用的标准,并且如果需要的话,可能会使用 C 或 C++ 来写代码。
|
||||
|
||||
[^1]:如果你点了这个链接,说明你一定想知道它的具体内容。CPSR 是一个由许多独立的比特位组成的 32 比特寄存器。它有一个位用于表示正数、零和负数。当一个 cmp 指令运行后,它从第一个参数上减去第二个参数,然后用这个位记下它的结果是正数、零还是负数。如果是零意味着它们相等(a-b=0 暗示着 a=b)如果为正数意味着 a 大于 b(a-b>0 暗示着 a>b),如果为负数意味着小于。还有其它比较指令,但 cmp 指令最直观。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok02.html
|
||||
|
||||
作者:[Robert Mullins][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: http://www.cl.cam.ac.uk/~rdm34
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok01.html
|
||||
[2]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/downloads.html
|
||||
[3]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok03.html
|
||||
@@ -0,0 +1,263 @@
|
||||
tmux - 适用于重度命令行 Linux 用户的强大终端复用器
|
||||
======
|
||||
|
||||
tmux 是终端复用的缩写,它允许用户在单个窗口中创建或启用多个终端(垂直或水平),当你处理不同的问题时,可以在单个窗口中轻松访问和控制。
|
||||
|
||||
它使用客户端-服务器模型,允许用户之间共享会话,也可以将终端连接到 tmux 会话。我们可以根据需要轻松移动或重新排列虚拟控制台。终端会话可以从一个虚拟控制台自由切换到另一个。
|
||||
|
||||
|
||||
tmux 依赖于 `libevent` 和 `ncurses` 库。tmux 在屏幕底部提供了一个状态行,它显示当前 tmux 会话的有关信息,例如当前窗口编号,窗口名称,用户名,主机名,当前时间和日期。
|
||||
|
||||
启动 tmux 时,它会在一个单独窗口上创建一个新的会话,并将其显示在屏幕上。它允许用户在同一个会话中创建任意数量的窗口。
|
||||
|
||||
许多人说它相当于一块屏幕,但我不这么认为,因为它提供了许多配置选项。
|
||||
|
||||
**注意:** `Ctrl+b` 是 tmux 中的默认前缀,因此,要在 tmux 中执行任何操作,你必须先输入前缀然后输入所需的选项。
|
||||
|
||||
**建议阅读:** [适用于 Linux 的终端仿真器列表][1]
|
||||
|
||||
### tmux 特性
|
||||
|
||||
* 创建任意数量的窗口
|
||||
* 在一个窗口中创建任意数量的窗格
|
||||
* 它允许垂直和水平分割
|
||||
* 分离并重新连接窗口
|
||||
* 客户端-服务器架构,这允许用户之间共享会话
|
||||
* tmux 提供许多配置技巧
|
||||
|
||||
**建议阅读:**
|
||||
**(#)** [tmate - 马上与其他人分享你的终端会话][2]
|
||||
**(#)** [Teleconsole - 一个与其他人分享终端会话的工具][3]
|
||||
|
||||
### 如何安装 tmux 命令
|
||||
|
||||
大多数 Linux 系统默认预安装 tmux 命令。如果没有,按照以下步骤安装。
|
||||
|
||||
对于 **`Debian/Ubuntu`**,使用 [APT-GET 命令][4]或 [APT 命令][5]来安装:
|
||||
```
|
||||
$ sudo apt install tmux
|
||||
```
|
||||
|
||||
对于 **`RHEL/CentOS`**,使用 [YUM 命令][6]来安装:
|
||||
```
|
||||
$ sudo yum install tmux
|
||||
```
|
||||
|
||||
对于 **`Fedora`**,使用 [DNF 命令][7]来安装:
|
||||
```
|
||||
$ sudo dnf install tmux
|
||||
```
|
||||
|
||||
对于 **`Arch Linux`**,使用 [Pacman 命令][8]来安装:
|
||||
```
|
||||
$ sudo pacman -S tmux
|
||||
```
|
||||
|
||||
对于 **`openSUSE`**,使用 [Zypper 命令][9]来安装:
|
||||
```
|
||||
$ sudo zypper in tmux
|
||||
```
|
||||
|
||||
### 如何使用 tmux
|
||||
|
||||
在终端上运行以下命令来启动 tmux 会话。启动 tmux 后,它会在一个新窗口中创建新会话,并将使用你的用户账户自动登录到你的默认 shell。
|
||||
```
|
||||
$ tmux
|
||||
```
|
||||
|
||||
![][11]
|
||||
|
||||
你会得到类似于我们上面的截图。tmux 附带状态栏,显示有关当前会话详细信息,日期,时间等。
|
||||
|
||||
状态栏信息如下:
|
||||
|
||||
* **`0 :`** 它表示由 tmux 服务器创建的会话号。默认情况下,它从 0 开始。
|
||||
* **`0:username@host: :`** ) 0 表示会话号。用户名和主机名是当前的使用窗口的人。
|
||||
* **`~ :`** 它表示当前目录(我们在家目录中)。
|
||||
* **`* :`** 这表示窗口现在处于活动状态。
|
||||
* **`Hostname :`** 显示服务器的完全主机名。
|
||||
* **`Date& Time:`** 显示当前日期和时间。
|
||||
|
||||
|
||||
### 如何拆分窗口
|
||||
|
||||
tmux 允许用户垂直或水平分割窗口。我们来看看如何做到这一点。
|
||||
|
||||
按下 `**(Ctrl+b), %**` 来垂直分割窗口。
|
||||
![][13]
|
||||
|
||||
Press `**(Ctrl+b), "**` 来水平分割窗口。
|
||||
![][14]
|
||||
|
||||
### 如何在窗格之间移动
|
||||
|
||||
假设,我们创建了一些窗格,希望在它们之间移动,这该怎么做?如果你不知道怎么做,那么使用 tmux 就没有意义了。使用以下控制键执行操作。在窗格之间移动有许多方法。
|
||||
|
||||
|
||||
按 `(Ctrl+b), 左箭头` - 来向左移动
|
||||
|
||||
按 `(Ctrl+b), 右箭头` - 来向右移动
|
||||
|
||||
按 `(Ctrl+b), 上箭头` - 来向上移动
|
||||
|
||||
按 `(Ctrl+b), 下箭头` - 来向下移动
|
||||
|
||||
按 `(Ctrl+b), {` - 来向左移动
|
||||
|
||||
按 `(Ctrl+b), }` - 来向右移动
|
||||
|
||||
按 `(Ctrl+b), o` - 切换到下一个窗格(从左到右,从上到下)
|
||||
|
||||
按 `(Ctrl+b), ;` - 移动到先前活动的窗格
|
||||
|
||||
出于测试目的,我们将在窗格之间移动。现在我们在 `pane2` 中,它 `lsb_release -a` 命令的输出。
|
||||
|
||||
![][15]
|
||||
|
||||
我们将移动到 `pane0`,它显示 `uname -a` 命令的输出。
|
||||
|
||||
![][16]
|
||||
|
||||
### 如何打开/创建新窗口
|
||||
|
||||
你可以在一个终端内打开任意数量的窗口。终端窗口可以垂直和水平分割,称为 `panes`。每个窗格都包含自己独立运行的终端实例。
|
||||
|
||||
按 `(Ctrl+b), c` 来创建一个新窗口。
|
||||
|
||||
按 `(Ctrl+b), n` 移动到下一个窗口
|
||||
|
||||
按 `(Ctrl+b), p` 移动到上一个窗口。
|
||||
|
||||
按 `(Ctrl+b), (0-9)` 立即移动到特定窗口。
|
||||
|
||||
按 `(Ctrl+b), l` 移动到先前选择的窗口。
|
||||
|
||||
我有两个窗口,第一个窗口有三个窗格,其中包含操作系统版本信息,top 命令输出和内核信息。
|
||||
![][17]
|
||||
|
||||
第二个窗口有两个窗格,其中包含 Linux 发行版 logo 信息。使用以下命令执行操作:
|
||||
![][18]
|
||||
|
||||
按 `(Ctrl+b), w` 以交互方式选择当前窗口。
|
||||
|
||||
![][19]
|
||||
|
||||
### 如何缩放窗格
|
||||
|
||||
你正在一些非常小的窗格中工作,并且你希望将其缩小以进行进一步的工作。要做到这一点,使用以下键绑定。
|
||||
|
||||
目前我们有三个窗格,我在 `pane1` 工作,它使用 **Top** 命令显示系统活动信息,我将缩放它。
|
||||
![][17]
|
||||
|
||||
缩放窗格时,它将隐藏所有其它窗格,并只显示窗口中的缩放窗格。
|
||||
|
||||
![][20]
|
||||
|
||||
按 `(Ctrl+b), z` 缩放窗格并再次按下它,使缩放窗格恢复原状。
|
||||
|
||||
### 显示窗格信息
|
||||
|
||||
要了解窗格编号及其大小,运行以下命令。
|
||||
|
||||
按 `(Ctrl+b), q` 可简单显示窗格索引。
|
||||
![][21]
|
||||
|
||||
### 显示窗口信息
|
||||
|
||||
要知道窗口编号,布局大小,与窗口关联的窗格数量及其大小等,运行以下命令。
|
||||
|
||||
只需运行 `tmux list-windows` 即可查看窗口信息。
|
||||
![][22]
|
||||
|
||||
### 如何调整窗格大小
|
||||
|
||||
你可能需要调整窗格大小来满足你的要求。你必须按下 `(Ctrl+b), :`,然后在页面底部的 `黄色(yellow)` 颜色条上输入以下详细信息。
|
||||
![][23]
|
||||
|
||||
在上一部分中,我们有打印了窗格索引,它同时也显示了窗格大小。为了测试,我们要向上增加 `10` 个单元。参考以下输出,该窗格将 pane1 和 pane2 的大小从 `55x21` 增加到 `55x31`。
|
||||
![][24]
|
||||
|
||||
**语法:** `(Ctrl+b), :` 然后输入 `resize-pane [options] [cells size]`
|
||||
|
||||
`(Ctrl+b), :` 然后输入 `resize-pane -D 10` 将当前窗格大小向下调整 10 个单元。
|
||||
|
||||
`(Ctrl+b), :` 然后输入 `resize-pane -U 10` 将当前窗格大小向上调整 10 个单元。
|
||||
|
||||
`(Ctrl+b), :` 然后输入 `resize-pane -L 10` 将当前窗格大小向左调整 10 个单元。
|
||||
|
||||
`(Ctrl+b), :` 然后输入 `resize-pane -R 10` 将当前窗格大小向右调整 10 个单元。
|
||||
|
||||
### 分离并重新连接 tmux 会话
|
||||
|
||||
tmux 最强大的功能之一是能够在需要时分离和重新连接会话。
|
||||
|
||||
运行一个长时间运行的进程,然后按下 `Ctrl+b`,接着按 `d`,通过离开正在运行的进程安全地分离你的 tmux 会话。
|
||||
|
||||
**建议阅读:** [如何在断开 SSH 会话后保持进程/命令继续运行][25]
|
||||
|
||||
现在,运行一个长时间运行的进程。出于演示目的,我们将把此服务器备份移动到另一个远程服务器以进行灾难恢复(DR)。
|
||||
|
||||
```
|
||||
$ rsync -avzhe ssh /backup root@192.168.0.161:/backups/week-1/
|
||||
```
|
||||
|
||||
在分离 tmux 会话之后,你将获得类似下面的输出。
|
||||
|
||||
```
|
||||
[detached (from session 0)]
|
||||
```
|
||||
|
||||
运行以下命令以列出可用的 tmux 会话。
|
||||
```
|
||||
$ tmux ls
|
||||
0: 3 windows (created Tue Jan 30 06:17:47 2018) [109x45]
|
||||
```
|
||||
|
||||
现在,使用适当的会话 ID 重新连接 tmux 会话,如下所示:
|
||||
```
|
||||
$ tmux attach -t 0
|
||||
```
|
||||
|
||||
### 如何关闭窗格和窗口
|
||||
|
||||
只需在相应的窗格中输入 `exit` 或按下 `Ctrl-d` 即可关闭它,和终端关闭类似。要关闭窗口,按下 `(Ctrl+b), &`。
|
||||
|
||||
好了,就到这里了,希望你喜欢上它。
|
||||
(to 校正:这句话是加的,感觉它结尾很突然,可以删掉。)
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/tmux-a-powerful-terminal-multiplexer-emulator-for-linux/
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.2daygeek.com/author/magesh/
|
||||
[1]:https://www.2daygeek.com/category/terminal-emulator/
|
||||
[2]:https://www.2daygeek.com/tmate-instantly-share-your-terminal-session-to-anyone-in-seconds/
|
||||
[3]:https://www.2daygeek.com/teleconsole-share-terminal-session-instantly-to-anyone-in-seconds/
|
||||
[4]:https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[5]:https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[6]:https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[7]:https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/
|
||||
[8]:https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/
|
||||
[9]:https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[10]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[11]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-1.png
|
||||
[13]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-2.png
|
||||
[14]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-3.png
|
||||
[15]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-4.png
|
||||
[16]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-5.png
|
||||
[17]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-8.png
|
||||
[18]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-6.png
|
||||
[19]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-7.png
|
||||
[20]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-9.png
|
||||
[21]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-10.png
|
||||
[22]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-14.png
|
||||
[23]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-11.png
|
||||
[24]:https://www.2daygeek.com/wp-content/uploads/2018/01/tmux-a-powerful-terminal-multiplexer-emulator-for-linux-13.png
|
||||
[25]:https://www.2daygeek.com/how-to-keep-a-process-command-running-after-disconnecting-ssh-session/
|
||||
@@ -0,0 +1,161 @@
|
||||
如何设置一个即时静态文件服务器
|
||||
======
|
||||
|
||||

|
||||
|
||||
曾经想通过网络共享你的文件或项目,但不知道怎么做?别担心!这里有一个名为 **serve** 的简单实用程序,可以通过网络即时共享你的文件。这个简单的实用程序会立即将你的系统变成一个静态文件服务器,允许你通过网络提供文件。你可以从任何设备访问这些文件,而不用担心它们的操作系统是什么。你所需的只是一个 Web 浏览器。这个实用程序还可以用来服务静态网站。它以前称为 “list” 或 “micri-list”,但现在名称已改为 “serve”,这更适合这个实用程序的目的。
|
||||
|
||||
### 使用 Serve 来设置一个静态文件服务器
|
||||
|
||||
要安装 "serve",首先你需要安装 NodeJS 和 NPM。参考以下链接在 Linux 中安装 NodeJS 和 NPM。
|
||||
|
||||
* [如何在 Linux 上安装 NodeJS](https://www.ostechnix.com/install-node-js-linux/)
|
||||
|
||||
NodeJS 和 NPM 安装完成后,运行以下命令来安装 "serve":
|
||||
```
|
||||
$ npm install -g serve
|
||||
```
|
||||
|
||||
完成!现在是时候 serve 文件或文件夹了。
|
||||
|
||||
使用 "serve" 的典型语法是:
|
||||
```
|
||||
$ serve [options] <path-to-files-or-folders>
|
||||
```
|
||||
|
||||
### Serve 特定文件或文件夹
|
||||
|
||||
例如,让我们共享 **Documents** 目录里的内容。为此,运行:
|
||||
```
|
||||
$ serve Documents/
|
||||
```
|
||||
|
||||
示例输出:
|
||||
![][2]
|
||||
|
||||
正如你在上图中看到的,给定目录的内容已通过两个 URL 提供网络支持。
|
||||
|
||||
要从本地系统访问内容,你只需打开 Web 浏览器,输入 **<http://localhost:5000/>** URL:
|
||||
![][3]
|
||||
|
||||
Serve 实用程序以简单的布局显示给定目录的内容。你可以下载(右键单击文件并选择“将链接另存为...”)或只在浏览器中查看它们。
|
||||
|
||||
如果想要在浏览器中自动打开本地地址,使用 **-o** 选项。
|
||||
```
|
||||
$ serve -o Documents/
|
||||
```
|
||||
|
||||
运行上述命令后,Serve 实用程序将自动打开 Web 浏览器并显示共享项的内容。
|
||||
|
||||
同样,要通过网络从远程系统访问共享目录,可以在浏览器地址栏中输入 **<http://192.168.43.192:5000>**。用你系统的 IP 替换 192.168.43.192。
|
||||
|
||||
**通过不同的端口 Serve 内容**
|
||||
|
||||
你可能已经注意到,默认情况下,serve 实用程序使用端口 **5000**。因此,确保防火墙或路由器中允许使用端口 5000。如果由于某种原因被阻止,你可以使用 **-p** 选项使用不同端口来提供内容。
|
||||
```
|
||||
$ serve -p 1234 Documents/
|
||||
```
|
||||
|
||||
上面的命令将通过端口 **1234** 提供 Documents 目录的内容。
|
||||
![][4]
|
||||
|
||||
要提供文件而不是文件夹,只需给它完整的路径,如下所示。
|
||||
```
|
||||
$ serve Documents/Papers/notes.txt
|
||||
```
|
||||
|
||||
只要知道路径,网络上的任何用户都可以访问共享目录的内容。
|
||||
|
||||
**Serve 整个 $HOME 目录**
|
||||
|
||||
打开终端输入
|
||||
```
|
||||
$ serve
|
||||
```
|
||||
|
||||
这将通过网络共享整个 $HOME 目录的内容。
|
||||
|
||||
要停止共享,按下 **CTRL+C**。
|
||||
|
||||
**Serve 选择的文件或文件夹**
|
||||
|
||||
你可能不想共享所有文件或目录,只想共享其中的一些。你可以使用 **-i** 选项排除文件或目录。
|
||||
```
|
||||
$ serve -i Downloads/
|
||||
```
|
||||
|
||||
以上命令将 serve 整个文件系统,除了 **Downloads** 目录。
|
||||
|
||||
**仅在本地主机上提供内容**
|
||||
|
||||
有时,你只想在本地系统而不是整个网络上 serve 内容。为此,使用 **-l** 标志,如下所示:
|
||||
```
|
||||
$ serve -l Documents/
|
||||
```
|
||||
|
||||
此命令会仅在本地提供 **Documents** 目录。
|
||||
|
||||
![][5]
|
||||
|
||||
当你在共享服务器上工作时,这可能会很有用。系统中的所有用户都可以访问共享,但远程用户不能。
|
||||
|
||||
**使用 SSL Serve 内容**
|
||||
|
||||
由于我们通过本地网络 serve 内容,因此我们不需要使用 SSL。但是,serve 实用程序可以使用 **-ssl** 选项来使用 SSL 共享内容。
|
||||
```
|
||||
$ serve --ssl Documents/
|
||||
```
|
||||
|
||||
![][6]
|
||||
|
||||
要通过 Web 浏览器访问共享,输入 “<https://localhost:5000”> 或 “<https://ip:5000”>.
|
||||
|
||||
![][7]
|
||||
|
||||
**通过身份验证 Serve 内容**
|
||||
|
||||
在上面的所以示例中,我们在没有任何身份验证的情况下 serve 内容,所以网络上的任何人都可以在没有任何身份验证的情况下访问共享内容。你可能会觉得应该使用用户名和密码访问某些内容。
|
||||
|
||||
为此,使用:
|
||||
```
|
||||
$ SERVE_USER=ostechnix SERVE_PASSWORD=123456 serve --auth
|
||||
```
|
||||
|
||||
现在用户需要输入用户名(即 **ostechnix**)和密码(123456)来访问共享。(译者注:123456 是非常不好的密码,仅在实验情况下使用)
|
||||
|
||||
![][8]
|
||||
|
||||
Serve 实用程序还有一些其它功能,例如禁用 [**Gzip 压缩**][9],设置 **CORS** 头以允许来自任河源的请求,防止自动复制地址到剪贴板等。通过以下命令,你可以阅读完整的帮助部分。
|
||||
```
|
||||
$ serve help
|
||||
```
|
||||
|
||||
好了,这就是全部了。希望这可以帮助到你。更多好东西要来了,敬请关注!
|
||||
|
||||
共勉!
|
||||
|
||||
来源:
|
||||
|
||||
* [Serve GitHub 仓库](https://github.com/zeit/serve)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-setup-static-file-server-instantly/
|
||||
|
||||
作者:[SK][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.ostechnix.com/author/sk/
|
||||
[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[2]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-1.png
|
||||
[3]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-2.png
|
||||
[4]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-4.png
|
||||
[5]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-3.png
|
||||
[6]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-6.png
|
||||
[7]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-5-1.png
|
||||
[8]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-7-1.png
|
||||
[9]:https://www.ostechnix.com/how-to-compress-and-decompress-files-in-linux/
|
||||
@@ -1,109 +0,0 @@
|
||||
4个值得一提的 Firefox 拓展插件
|
||||
======
|
||||
|
||||

|
||||
|
||||
自从大约12年前 V2.0 推出以来, 我一直是 Firefox (火狐浏览器)的用户。那时它不是最好的网络浏览器,但我仍旧因为一个理由使用它:我最喜爱的无可比拟的浏览器拓展插件
|
||||
|
||||
如今, 我喜欢 Firefox 的当前状态,因为它快速、可定制和开源,但我也很欣赏扩展插件来体现原开发人员从未想到的特点: 如果您想在没有鼠标的情况下浏览呢?如果您不喜欢盯着晚上从显示器里出来的强光呢?对于 YouTube 和其他视频托管网站为了更好的性能和扩展使用一个更专业的播放器又如何呢?如果您需要更复杂的方法来禁用跟踪器和加快加载页面, 该怎么办?
|
||||
|
||||
幸运的是, 这些问题都有答案, 我将展现给你我最喜爱的拓展--所有这些都是免费软件或开源的 (即, 在 [GNU GPL][1], [MPL][2],或 [Apache][3] 许可下) 并使一个优秀的浏览器更好。
|
||||
|
||||
尽管术语加载项和扩展具有微微不同的含义,,但我将在本文中交替使用它们。
|
||||
|
||||
### Tridactyl
|
||||
|
||||
![Tridactyl screenshot][5]
|
||||
|
||||
Tridactyl 的新选项卡页面,展示隐藏连接。
|
||||
|
||||
[Tridactyl][6] 使您能够在大多数浏览活动中使用键盘。它的灵感来自于现已解散的 [Vimperator][7] 和 [Pentadactyl][8] ,这是由 [Vim][9] 默认绑定值启发的。由于我已经习惯了 Vim 和其他命令行应用程序,我发现了一些功能,比如能够使用键值 `h/j/k/l` 进行导航,用 `f/F` 与超链接进行交互,并创建非常方便的自定义键绑定和命令。
|
||||
|
||||
Tridactyl 的可选本地信代理(目前,仅适用于GNU/Linux 和 Mac OSX), 最近才实现的,提供了更酷的功能来启动。例如, 有了它, 您可以隐藏 Firefox GUI 的一些元素(à la Vimperator 和 Pentadactyl),在外部程序中打开链接或当前页 (我经常用 [mpv][10] 和 [youtube-dl][11] 在视频上)通过按 `Ctrl-I` 用您喜爱的编辑器编辑文本内容(或者任意您选择的组合键)。
|
||||
|
||||
话虽如此, 但要记住,这是一个相对早期的项目,细节可能还是很粗糙。 另一方面,它的发展非常活跃, 当你回顾它早期的缺陷时, 使用它可能是一种乐趣。
|
||||
|
||||
### Open With
|
||||
|
||||
![Open With Screenshot][13]
|
||||
|
||||
Open With 提供的菜单。我可以在当前页面打开一个额外的列表。
|
||||
|
||||
说到与外部程序的互动,有时很高兴有能力用鼠标来做到这一点。这是 [Open With][14] 想法的来源.
|
||||
|
||||
除了添加的上下文菜单 (如屏幕截图所示) 外,您还可以通过单击加载项栏上的扩展图标来找到自己定义的命令。 [its page on Mozilla Add-ons][14] 建议作为它的图标和描述,它主要是为了与其他 web 浏览器一起工作, 但我也可以轻松地使用它与 mpv 和 youtube-dl 。
|
||||
|
||||
这里也提供键盘快捷方式,但它们受到严重限制。可以在扩展设置的下拉列表中选择的组合不超过三种。相反, Tridactyl 允许我将命令分配给几乎任何没有被 Firefox 阻止的东西。打开与是目前为鼠标,真的。
|
||||
|
||||
### Stylus
|
||||
|
||||
![Stylus Screenshot][16]
|
||||
|
||||
在这个屏幕截图中, 我刚刚搜索并安装了一个黑暗的主题, 我正在上 Stylus 的网站。即使是弹出窗口也可以定制风格 (称为 Deepdark Stylus)!
|
||||
|
||||
[Stylus][17] 是一个用户样式管理器,这意味着通过编写自定义 CSS 规则并将其加载到 Stylus 中,您可以更改任何网页的外观。如果你不知道 CSS ,有大量的风格在其他网站上,如 [userstyles.org][18] 。
|
||||
|
||||
现在,你可能会问,“这不正是什么 [Stylish][19] 么?” 你是对的!你看 Stylus 是基于 Stylish 并提供了更多的改进:它不包含任何遥测数据, 尊重您的隐私,所有开发都是公开的(尽管 Stylish 仍在积极开发, 我一直未能找到最新版本的源代码), 而且它还支持 [UserCSS][20]。
|
||||
|
||||
UserCSS 是一种有趣的格式,尤其是对于开发人员。我已经为不同的网站写了几种用户样式(主要是黑暗的主题和调整,以提高可读性),虽然 Stylus 的内部编辑器很好,我还是喜欢用 Neovim 编辑代码。为了做到这样我所需要做的就是用 ".user.css" 作为本地加载文件的后缀名,在 Stylus 里启动 "Live Reload" 选项,所有更改都会被应用只要我在 Neovim 中启保存和更改文件。远程 UserCSS 文件也支持,因此,每当我将更改推送到 Github 或任何基于 git 的开发平台时,它们将自动对用户可用。(我提供了指向该文件的原始版本的链接, 以便他们可以轻松地访问它。)
|
||||
|
||||
### uMatrix
|
||||
|
||||
![uMatrix Screenshot][22]
|
||||
|
||||
uMatrix 的用户使用界面,显示当前访问过的网页的当前规则。
|
||||
|
||||
Jeremy Garcia 提到了 uBlock Origin 在 [his article][23] 在 Opensource.com 作为一个优秀的 blocker 。我想推荐另一个拓展插件作者是 [gorhill][24]: uMatrix 。
|
||||
|
||||
[uMatrix][25] 允许您为网页上的某些请求设置阻止规则,可以通过点击加载项的弹出窗口来切换(在上面的屏幕截图中可以看到)。 这些请求的区别在于脚本的类别、 scripts, cookies, CSS rules, images, media content, frames,和其他被 uMatrix 标记为 "other" 的 。 例如,您可以设置全局规则, 以便在默认情况下允许所有请求, 并将特定请求添加到黑名单中(更方便的方法),或在默认情况下阻止所有内容, 并手动将某些请求列入白名单 (更安全的方法)。如果您一直在使用NoScript 或 RequestPolicy,你可以 [import][26] 你的白名单规则。
|
||||
|
||||
另外 uMatrix 支持 [hosts files ][27],可用于阻止来自某些网站的请求。 不能与原始 uBlock 的筛选列表相比, 其使用的语法是 Adblock Plus 。默认情况下, uMatrix 会在几个文件的帮助下阻止已知分发广告、跟踪器和恶意软件的服务器, 如果需要, 您可以添加更多外部源。
|
||||
|
||||
那么你将选择哪一个-- uBlock Origin 或 uMatrix ?就个人而言,我在电脑上两个都用,只在安卓手机上用 uMatrix 。两者之间会有重叠的部分 [according to gorhill][28] ,但他们有不同的用户和目标群,如果你想要的只是阻止跟踪器和广告的简单方法, uBlock Origine 是更好的选择, 另一方面,如果您希望对网页在浏览器中可以执行或不能执行的操作进行精细的控制, 即使需要一些时间来进行配置, 并且可能会阻止网站按预期运行, uMatrix 是更好的选择。
|
||||
|
||||
### 结论
|
||||
|
||||
目前, 这些是 Firefox 里我最喜欢的扩展。Tridactyl 是依靠键盘和与外部程序交互, 加快浏览导航速度;Open With 能让我用鼠标点击程序操作, Stylus 是明确的用户风格的管理器, 对用户和开发人员都有吸引力; uMatrix 本质上是 Firefox 的防火墙用于过滤未知的请求。
|
||||
|
||||
尽管我几乎完全讨论了这些加载项的好处,但没有一个软件是完美的。如果你喜欢他们中的任何一个,并认为他们可以以任何方式改进, 我建议你去他们的 Github 页面,并寻找他们的贡献指南。通常情况下,免费和开源软件的开发人员欢迎错误报告和提交请求。告诉你的朋友或道谢也是帮助开发者的好方法, 特别是如果他们在业余时间从事他们的项目。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/6/firefox-open-source-extensions
|
||||
|
||||
作者:[Zsolt Szakács][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[lixinyuxx](https://github.com/lixinyuxx)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/zsolt
|
||||
[1]:https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
[2]:https://www.mozilla.org/en-US/MPL/
|
||||
[3]:https://www.apache.org/licenses/LICENSE-2.0
|
||||
[4]:/file/398411
|
||||
[5]:https://opensource.com/sites/default/files/uploads/tridactyl.png "Tridactyl's new tab page, showcasing link hinting"
|
||||
[6]:https://addons.mozilla.org/en-US/firefox/addon/tridactyl-vim/
|
||||
[7]:https://github.com/vimperator/vimperator-labs
|
||||
[8]:https://addons.mozilla.org/en-US/firefox/addon/pentadactyl/
|
||||
[9]:https://www.vim.org/
|
||||
[10]:https://mpv.io/
|
||||
[11]:https://rg3.github.io/youtube-dl/index.html
|
||||
[12]:/file/398416
|
||||
[13]:https://opensource.com/sites/default/files/uploads/openwith.png "A context menu provided by Open With. I can open the current page with one of the external programs listed here."
|
||||
[14]:https://addons.mozilla.org/en-US/firefox/addon/open-with/
|
||||
[15]:/file/398421
|
||||
[16]:https://opensource.com/sites/default/files/uploads/stylus.png "In this screenshot, I've just searched for and installed a dark theme for the site I'm currently on with Stylus. Even the popup has custom style (called Deepdark Stylus)!"
|
||||
[17]:https://addons.mozilla.org/en-US/firefox/addon/styl-us/
|
||||
[18]:https://userstyles.org/
|
||||
[19]:https://addons.mozilla.org/en-US/firefox/addon/stylish/
|
||||
[20]:https://github.com/openstyles/stylus/wiki/Usercss
|
||||
[21]:/file/398426
|
||||
[22]:https://opensource.com/sites/default/files/uploads/umatrix.png "The user interface of uMatrix, showing the current rules for the currently visited webpage."
|
||||
[23]:https://opensource.com/article/18/5/firefox-extensions
|
||||
[24]:https://addons.mozilla.org/en-US/firefox/user/gorhill/
|
||||
[25]:https://addons.mozilla.org/en-US/firefox/addon/umatrix
|
||||
[26]:https://github.com/gorhill/uMatrix/wiki/FAQ
|
||||
[27]:https://en.wikipedia.org/wiki/Hosts_(file)
|
||||
[28]:https://github.com/gorhill/uMatrix/issues/32#issuecomment-61372436
|
||||
@@ -0,0 +1,132 @@
|
||||
Perform robust unit tests with PyHamcrest
|
||||
使用 PyHamcrest 执行健壮的单元测试
|
||||
======
|
||||
|
||||

|
||||
|
||||
在[测试金字塔][1]的底部是单元测试。单元测试每次只测试一个代码单元,通常是一个函数或方法。
|
||||
|
||||
通常,设计单个单元测试是为了测试通过函数或特定分支选择的特定流,这使得失败的单元测试和导致失败的 bug 之间的映射变得容易。
|
||||
|
||||
理想情况下,单元测试使用很少或不使用外部资源,从而隔离它们并使它们更快。
|
||||
|
||||
_好_ 测试通过尽早发现 bug 并加快测试速度来提高开发人员的工作效率。_坏_ 测试降低了开发人员的工作效率。
|
||||
|
||||
单元测试套件通过在开发过程的早期发现问题来帮助维护高质量的产品。有效的单元测试在代码离开开发人员机器之前捕获 bug,或者至少在特定分支上的持续集成环境中捕获 bug。这标志着好的和坏的单元测试之间的区别:好的测试通过尽早捕获 bug 并使测试更快来提高开发人员的生产力。坏的测试降低了开发人员的工作效率。
|
||||
|
||||
当测试 _附带的特性_ 时,生产率通常会降低。当代码更改时测试失败,即时它仍然是正确的。发生这种情况是因为输出不同,但在某种程度上它不是函数契约的一部分。
|
||||
|
||||
因此,一个好的单元测试可以帮助执行函数所提交的契约。
|
||||
|
||||
如果单元测试中断,那意味着契约被违反了,应该明确修改(通过更改文档和测试),或者被修复(通过修复代码并保持测试不变)。
|
||||
|
||||
虽然将测试限制为只执行公共契约是一项需要学习的复杂技能,但有一些工具可以提供帮助。
|
||||
|
||||
其中一个工具是 [Hamcrest][2],一个用于编写断言的框架。最初是为基于 Java 的单元测试而发明的,它现在支持多种语言,包括 [Python][3]。
|
||||
|
||||
Hamcrest 旨在使测试断言更容易编写和更精确。
|
||||
|
||||
```
|
||||
def add(a, b):
|
||||
return a + b
|
||||
|
||||
from hamcrest import assert_that, equal_to
|
||||
|
||||
def test_add():
|
||||
assert_that(add(2, 2), equal_to(4))
|
||||
```
|
||||
|
||||
这是一个用于简单功能的断言。如果我们想要断言更复杂的怎么办?
|
||||
```
|
||||
def test_set_removal():
|
||||
my_set = {1, 2, 3, 4}
|
||||
my_set.remove(3)
|
||||
assert_that(my_set, contains_inanyorder([1, 2, 4]))
|
||||
assert_that(my_set, is_not(has_item(3)))
|
||||
```
|
||||
|
||||
注意,我们可以简单地断言结果的顺序为 `1`, `2` 和 `4`,因为集合不保证顺序。
|
||||
|
||||
我们也可以很容易用 `is_not` 来否定断言。这有助于我们编写 _精确的断言_,使我们能够把自己限制在执行职能的公共契约方面。
|
||||
|
||||
然而,有时候,内置功能都不是我们 _真正_ 需要的。在这些情况下,Hamcrest 允许我们编写自己的匹配器。
|
||||
|
||||
想象一下以下功能:
|
||||
```
|
||||
def scale_one(a, b):
|
||||
scale = random.randint(0, 5)
|
||||
pick = random.choice([a,b])
|
||||
return scale * pick
|
||||
```
|
||||
|
||||
我们可以自信地断言结果均匀地划分为至少一个输入。(to 校正:???什么意思)
|
||||
|
||||
匹配器继承自 `hamcrest.core.base_matcher.BaseMatcher`,重写两个方法:
|
||||
```
|
||||
class DivisibleBy(hamcrest.core.base_matcher.BaseMatcher):
|
||||
def __init__(self, factor):
|
||||
self.factor = factor
|
||||
|
||||
def _matches(self, item):
|
||||
return (item % self.factor) == 0
|
||||
|
||||
def describe_to(self, description):
|
||||
description.append_text('number divisible by')
|
||||
description.append_text(repr(self.factor))
|
||||
```
|
||||
|
||||
编写高质量的 `describe_to` 方法很重要,因为这是测试失败时显示的消息的一部分。
|
||||
```
|
||||
def divisible_by(num):
|
||||
return DivisibleBy(num)
|
||||
```
|
||||
|
||||
按照惯例,我们将匹配器包装在一个函数中。有时这给了我们进一步处理输入的机会,但在这种情况下,我们不需要进一步处理。
|
||||
```
|
||||
def test_scale():
|
||||
result = scale_one(3, 7)
|
||||
assert_that(result,
|
||||
any_of(divisible_by(3),
|
||||
divisible_by(7)))
|
||||
```
|
||||
|
||||
请注意,我们将 `divisible_by` 匹配器与内置的 `any_of` 匹配器结合起来,以确保我们只测试函数提交的内容。
|
||||
|
||||
在编辑这篇文章时,我听到一个传言,“Hamcrest” 这个名字被认为是 “matches” 的字谜。人力资源管理...
|
||||
```
|
||||
>>> assert_that("matches", contains_inanyorder(*"hamcrest")
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
File "/home/moshez/src/devops-python/build/devops/lib/python3.6/site-packages/hamcrest/core/assert_that.py", line 43, in assert_that
|
||||
_assert_match(actual=arg1, matcher=arg2, reason=arg3)
|
||||
File "/home/moshez/src/devops-python/build/devops/lib/python3.6/site-packages/hamcrest/core/assert_that.py", line 57, in _assert_match
|
||||
raise AssertionError(description)
|
||||
AssertionError:
|
||||
Expected: a sequence over ['h', 'a', 'm', 'c', 'r', 'e', 's', 't'] in any order
|
||||
but: no item matches: 'r' in ['m', 'a', 't', 'c', 'h', 'e', 's']
|
||||
```
|
||||
|
||||
经过进一步的研究,我找到了谣言的来源:它是 “matchers” 的字谜。
|
||||
```
|
||||
>>> assert_that("matchers", contains_inanyorder(*"hamcrest"))
|
||||
>>>
|
||||
```
|
||||
|
||||
如果你还没有为你的 Python 代码编写单元测试,那么现在是开始的好时机。如果你正在为你的 Python 代码编写单元测试,那么使用 Hamcrest 将允许你使你的断言更加 _精确_,既不会比你想要测试的多也不会少。这将在修改代码时减少误报,并减少修改工作代码的测试所花费的时间。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/8/robust-unit-tests-hamcrest
|
||||
|
||||
作者:[Moshe Zadka][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/moshez
|
||||
[1]:https://martinfowler.com/bliki/TestPyramid.html
|
||||
[2]:http://hamcrest.org/
|
||||
[3]:https://www.python.org/
|
||||
@@ -0,0 +1,109 @@
|
||||
5款开源的Linux策略模拟游戏
|
||||
======
|
||||
|
||||

|
||||
|
||||
长久以来,游戏都是 Linux 的软肋。近些年,Steam,GOG等游戏发布平台上不少商业游戏都开始支持 Linux,这对于 Linux 的游戏生态来说是件好事,但是我们能在这些平台上玩到的游戏通常是不开源的商业作品。当然,这些游戏在一个开源的操作系统上运行,但对于一个开源提倡者来说这似乎还不够纯粹。
|
||||
|
||||
那么,我们能找到既免费开源又能给玩家带来完整游戏体验的优质游戏吗?当然!虽然绝大多数的开源游戏很难和3A 商业游戏大作竞争,但仍然有不少各种类型的开源游戏,不仅内容有趣而且直接可以通过几大 Linux 发行版本库中直接安装。就算某个游戏在不在某个发行版本的库中,我们也可以在这个游戏项目的网站上找到直接的安装方法。
|
||||
|
||||
本篇文章将会介绍策略和模拟类游戏。我已经写了街机游戏、桌面卡牌游戏、解谜游戏、竞速飞行游戏以及角色扮演游戏。
|
||||
|
||||
### Freeciv 开源“文明”
|
||||
|
||||

|
||||
|
||||
[Freeciv][6] 可以被视为是文明系列游戏的开源版本。游戏玩法和文明系列最早期的游戏十分类似, Freeciv 可以让玩家选择选用文明 1 或者文明 2 中的游戏规则设置。Freeciv 中包含了很多元素,例如建造城市、探索世界地图、发展科技以及和其他扩张中的文明竞争。胜利条件包括打败所有其他的文明或建立一个外星殖民地,如果在前两者都没有达成的话,在游戏时间期限前存活下来也可以算作胜利。这个游戏可以和其他玩家联机也可以和 AI 对战,不同的地图集可以改变游戏的外观。
|
||||
|
||||
安装 Freeciv,你只需要在终端下运行以下指令。
|
||||
|
||||
* Fedora 用户: `dnf install freeciv`
|
||||
|
||||
* Debian/Ubuntu 用户:`apt install freeciv`
|
||||
|
||||
|
||||
### MegaGlest
|
||||
|
||||

|
||||
|
||||
[MegaGlest][8] 是一个开源的实时战略游戏,类似暴雪公司制作的游戏魔兽世界和星际争霸。玩家控制不同派别的人员、建造新建筑、招募士兵、拓展领土并与敌人作战。在游戏比赛的最开始,玩家仅能建造最基础的建筑和招募最基础的士兵。为了建造更高级的建筑并招募级别更高的人员,玩家必须通过增加建筑和人员从而一路提高科技树、解锁更加高级的选项。当敌人进入国土领域之中,战斗单元必须迎战。但是最好的应对策略是,通过控制战斗单元直接操控每一场战斗。在管理新建筑的建立,新人员的招募的同时控制战斗局势听上去十分困难,但是这就是RTS(实时战略游戏)游戏的精华所在。MegaGlest 这个游戏提供了大量的人员派类,玩家可以不断尝试这些不同的技巧。
|
||||
|
||||
安装 MegaGlest,你只需要在终端下运行以下指令:
|
||||
|
||||
* Fedora 用户: `dnf install megaglest`
|
||||
* Debian/Ubuntu 用户:`apt install megaglest`
|
||||
|
||||
|
||||
|
||||
### OpenTTD 开源版“运输大亨”
|
||||
|
||||

|
||||
|
||||
[OpenTTD][11] (见我们的 [评测][12] )是一个开源实现的 [运输大亨][13] 。该游戏的目的在于创建一个交通运输网络并获得金钱,从而建立更加复杂的运输网络。这个运输网络包括了船只、巴士、火车、货车和飞机。默认的游戏时间在1950和2050之间,玩家的目标就是在规定时间内拿到最高的游戏分数。游戏的最终分数基于很多因素,例如货物运输的数量、玩家所拥有的汽车数量以及他们赚到的钱。
|
||||
|
||||
安装 OpenTTD,你只需要在终端运行以下指令:
|
||||
|
||||
* Fedora 用户: `dnf install openttd`
|
||||
* Debian/Ubuntu 用户 `apt install openttd`
|
||||
|
||||
|
||||
|
||||
### The Battle for Wesnoth 韦诺之战
|
||||
|
||||

|
||||
|
||||
[韦诺之战][14] 是目前最完善的开源游戏之一。这个回合制游戏在一个奇幻的故事设定下。游戏在一个六角形网格中进行,各个单元可以互相操作进行战斗。每个类型的单元都有它独特的能力和弱点,因此玩家需要根据这些特点来设计不同的行动。韦诺之战中有很多不同的行动分支,每个行动分支都有它特别的故事线和目标。The 韦诺之战同时也有一个地图编辑器,感兴趣的玩家可以创作自己的地图以及行动分支。
|
||||
|
||||
安装韦诺之战,你只需要在终端运行以下指令:
|
||||
|
||||
* Fedora 用户: `dnf install wesnoth `
|
||||
* Debian/Ubuntu 用户: `apt install wesnoth`
|
||||
|
||||
|
||||
|
||||
### UFO: Alien Invasion (UFO:外星入侵)
|
||||
|
||||

|
||||
|
||||
[UFO: Alien Invasion][15] 是一个开源策略游戏,基于幽浮系列 [X-COM series][20]。 有两个不同的游戏模式: geoscape 和tactical。在 geoscape 模式下,玩家控制大局、管理基地、开发新技术以及掌控整体策略。 在tactical 游戏模式下,玩家控制一群士兵并且以回合制的形式直接迎战外星侵略者。两个游戏模式提供了不同的游戏玩法,两者都需要相当复杂的策略和战术。
|
||||
|
||||
安装 UFO:外星入侵,你只需要在终端下运行以下指令:
|
||||
|
||||
* Debian/Ubuntu 用户: `apt install ufoai`
|
||||
|
||||
遗憾的是,UFO: 外星入寝不支持 Fedora 发行版。
|
||||
|
||||
如果你知道除了这些以外的开源策略模拟游戏的话,欢迎在评论中分享。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/8/strategy-simulation-games-linux
|
||||
|
||||
作者:[Joshua Allen Holm][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[Scoutydren](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/holmja
|
||||
[1]:https://opensource.com/article/18/1/arcade-games-linux
|
||||
[2]:https://opensource.com/article/18/3/card-board-games-linux
|
||||
[3]:https://opensource.com/article/18/6/puzzle-games-linux
|
||||
[4]:https://opensource.com/article/18/7/racing-flying-games-linux
|
||||
[5]:https://opensource.com/article/18/8/role-playing-games-linux
|
||||
[6]:http://www.freeciv.org/
|
||||
[7]:https://en.wikipedia.org/wiki/Civilization_(series)
|
||||
[8]:https://megaglest.org/
|
||||
[9]:https://en.wikipedia.org/wiki/Warcraft
|
||||
[10]:https://en.wikipedia.org/wiki/StarCraft
|
||||
[11]:https://www.openttd.org/
|
||||
[12]:https://opensource.com/life/15/7/linux-game-review-openttd
|
||||
[13]:https://en.wikipedia.org/wiki/Transport_Tycoon#Transport_Tycoon_Deluxe
|
||||
[14]:https://www.wesnoth.org/
|
||||
[15]:https://ufoai.org/
|
||||
[16]:https://opensource.com/downloads/cheat-sheets?intcmp=7016000000127cYAAQ
|
||||
[17]:https://opensource.com/alternatives?intcmp=7016000000127cYAAQ
|
||||
[18]:https://opensource.com/tags/linux?intcmp=7016000000127cYAAQ
|
||||
[19]:https://developers.redhat.com/cheat-sheets/advanced-linux-commands/?intcmp=7016000000127cYAAQ
|
||||
[20]:https://en.wikipedia.org/wiki/X-COM
|
||||
Reference in New Issue
Block a user