mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-21 02:10:11 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
4bc6248f0c
@ -0,0 +1,177 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12252-1.html)
|
||||
[#]: subject: (3 Python templating languages you should (probably) never use)
|
||||
[#]: via: (https://opensource.com/article/20/4/python-templating-languages)
|
||||
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
|
||||
|
||||
你应该(或许)没使用过的 3 种 Python 模板语言
|
||||
======
|
||||
|
||||
> 包括这 3 个模板语言在内,Python 积累了许多模板语言。
|
||||
|
||||

|
||||
|
||||
当需要使用模板语言来编写 [Python][2] Web 应用时,有很多健壮的解决方案。
|
||||
|
||||
有 [Jinja2][3]、[Genshi 和 Mako][4]。甚至还有 [Chameleon][5] 之类的解决方案,虽然有些陈旧,但仍被 [Pyramid][6] 框架推荐。
|
||||
|
||||
Python 已经存在了很长时间。此时,在系统的深处,它积累了一些几乎被遗忘的模板语言,它们都是值得一试的。
|
||||
|
||||
这些语言就像桉树上可爱的考拉一样,在自己的生态圈里快乐地生活着,有时也会有危险的工作,这些都是很少有人听说过的模板语言,使用过的应该更少。
|
||||
|
||||
### 3、string.Template
|
||||
|
||||
你是否曾经想过:“如何获得一种没有任何特性的模板语言,而且同时也不需要 `pip install` 安装任何东西?” Python 标准库已经为你提供了答案。虽然没有循环和条件,但 `string.Template` 类是一种最小的模板语言。
|
||||
|
||||
使用它很简单。
|
||||
|
||||
```
|
||||
>>> import string
|
||||
>>> greeting = string.Template("Hello, $name, good $time!")
|
||||
>>> greeting.substitute(name="OpenSource.com", time="afternoon")
|
||||
'Hello, OpenSource.com, good afternoon!'
|
||||
```
|
||||
|
||||
### 2、twisted.web.template
|
||||
|
||||
你会给一个包罗万象的库送什么礼物?
|
||||
|
||||
当然,不是模板语言,因为它已经有了。twisted.web.template 中嵌套了两种模板语言。一种是基于 XML 的,并有一个[很棒的文档][7]。
|
||||
|
||||
但是它还有另一种,一种基于使用 Python 作为领域特定语言(DSL)来生成 HTML 文档。
|
||||
|
||||
它基于两个原语:包含标签对象的 `twisted.web.template.tags` 和渲染它们的 `twisted.web.template.flattenString`。由于它是 Twisted 的一部分,因此它内置支持高效异步渲染。
|
||||
|
||||
此例将渲染一个小页面:
|
||||
|
||||
```
|
||||
async def render(reactor):
|
||||
my_title = "A Fun page"
|
||||
things = ["one", "two", "red", "blue"]
|
||||
template = tags.html(
|
||||
tags.head(
|
||||
tags.title(my_title),
|
||||
),
|
||||
tags.body(
|
||||
tags.h1(my_title),
|
||||
tags.ul(
|
||||
[tags.li(thing) for thing in things],
|
||||
),
|
||||
tags.p(
|
||||
task.deferLater(reactor, 3, lambda: "Hello "),
|
||||
task.deferLater(reactor, 3, lambda: "world!"),
|
||||
)
|
||||
)
|
||||
)
|
||||
res = await flattenString(None, template)
|
||||
res = res.decode('utf-8')
|
||||
with open("hello.html", 'w') as fpout:
|
||||
fpout.write(res)
|
||||
```
|
||||
|
||||
该模板是使用 `tags.<TAGNAME>` 来指示层次结构的常规 Python 代码。原生支持渲染字符串,因此任何字符串都正常。
|
||||
|
||||
要渲染它,你需要做的是添加调用:
|
||||
|
||||
```
|
||||
from twisted.internet import task, defer
|
||||
from twisted.web.template import tags, flattenString
|
||||
|
||||
def main(reactor):
|
||||
return defer.ensureDeferred(render(reactor))
|
||||
```
|
||||
|
||||
最后写上:
|
||||
|
||||
|
||||
```
|
||||
task.react(main)
|
||||
```
|
||||
|
||||
只需 3 秒(而不是 6 秒),它将渲染一个不错的 HTML 页面。在实际中,这些 `deferLater` 可以是对 HTTP API 的调用:它们将并行发送和处理,而无需付出任何努力。我建议你阅读关于[更好地使用 Twisted][8]。不过,这已经可以工作了。
|
||||
|
||||
### 1、Quixote
|
||||
|
||||
你会说:“但是 Python 并不是针对 HTML 领域而优化的领域特定语言。” 如果有一种语言可以[转化][9]到 Python,但是更适合定义模板,而不是像 Python 那样按原样解决呢?如果可以的话,请使用“Python 模板语言”(PTL)。
|
||||
|
||||
编写自己的语言,有时被说成是一个攻击假想敌人的唐吉坷德项目。当 Quixote(可在 [PyPI][10] 中找到)的创造者决定这样做时,并没有受此影响。
|
||||
|
||||
以下将渲染与上面 Twisted 相同的模板。*警告:以下不是有效的 Python 代码*:
|
||||
|
||||
```
|
||||
import time
|
||||
|
||||
def render [html] ():
|
||||
my_title = "A Fun page"
|
||||
things = ["one", "two", "red", "blue"]
|
||||
"<html><head><title>"
|
||||
my_title
|
||||
"</head></title><body><h1>"
|
||||
my_title
|
||||
"</h1>"
|
||||
"<ul>"
|
||||
for thing in things:
|
||||
"<li>"
|
||||
thing
|
||||
"</li>"
|
||||
"<p>"
|
||||
time.sleep(3)
|
||||
(lambda: "Hello ")()
|
||||
time.sleep(3)
|
||||
(lambda: "world!")()
|
||||
"</p>"
|
||||
"</body></html>"
|
||||
|
||||
def write():
|
||||
result = render()
|
||||
with open("hello.html", 'w') as fpout:
|
||||
fpout.write(str(result))
|
||||
```
|
||||
|
||||
但是,如果将它放到 `template.ptl` 文件中,那么可以将其导入到 Quixote 中,并写出可以渲染模板的版本:
|
||||
|
||||
|
||||
```
|
||||
>>> from quixote import enable_ptl
|
||||
>>> enable_ptl()
|
||||
>>> import template
|
||||
>>> template.write()
|
||||
```
|
||||
|
||||
Quixote 安装了一个导入钩子,它会将 PTL 文件转换为 Python。请注意,此渲染需要 6 秒,而不是 3 秒。你不再获得自由的异步性。
|
||||
|
||||
### Python 中的模板太多
|
||||
|
||||
Python 库的历史悠久且曲折,其中一些库可以或多或少都能达到类似结果(例如,Python [包管理][11])。
|
||||
|
||||
我希望你喜欢探索这三种*可以*用 Python 创建模板的方式。另外,我建议从[这三个库之一][4]开始了解。
|
||||
|
||||
你是否有另一种深奥的模板方法?请在下面的评论中分享!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/4/python-templating-languages
|
||||
|
||||
作者:[Moshe Zadka][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/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/python-programming-code-keyboard.png?itok=fxiSpmnd (Hands on a keyboard with a Python book )
|
||||
[2]: https://opensource.com/resources/python
|
||||
[3]: https://opensource.com/article/20/2/jinja2-cheat-sheet
|
||||
[4]: https://opensource.com/resources/python/template-libraries
|
||||
[5]: https://chameleon.readthedocs.io/en/latest/
|
||||
[6]: https://opensource.com/article/18/5/pyramid-framework
|
||||
[7]: https://twistedmatrix.com/documents/13.1.0/web/howto/twisted-templates.html
|
||||
[8]: https://opensource.com/article/20/3/treq-python
|
||||
[9]: https://en.wikipedia.org/wiki/Source-to-source_compiler
|
||||
[10]: https://pypi.org/project/Quixote/
|
||||
[11]: https://opensource.com/article/19/4/managing-python-packages
|
@ -1,8 +1,8 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12251-1.html)
|
||||
[#]: subject: (Why strace doesn't work in Docker)
|
||||
[#]: via: (https://jvns.ca/blog/2020/04/29/why-strace-doesnt-work-in-docker/)
|
||||
[#]: author: (Julia Evans https://jvns.ca/)
|
||||
@ -10,7 +10,7 @@
|
||||
为什么 strace 在 Docker 中不起作用?
|
||||
======
|
||||
|
||||
在编辑“容器如何工作”杂志的能力页面时,我想试着解释一下为什么 `strace` 在 Docker 容器中无法工作。
|
||||
在编辑“容器如何工作”爱好者杂志的能力页面时,我想试着解释一下为什么 `strace` 在 Docker 容器中无法工作。
|
||||
|
||||
这里的问题是 —— 如果我在笔记本上的 Docker 容器中运行 `strace`,就会出现这种情况:
|
||||
|
||||
@ -27,7 +27,7 @@ strace: ptrace(PTRACE_TRACEME, ...): Operation not permitted
|
||||
docker run --cap-add=SYS_PTRACE -it ubuntu:18.04 /bin/bash
|
||||
```
|
||||
|
||||
但我对如何修复它不感兴趣,我想知道为什么会出现这种情况。那么,为什么 `strace` 不能工作,为什么`--cap-add=SYS_PTRACE` 可以解决这个问题?
|
||||
但我对如何修复它不感兴趣,我想知道为什么会出现这种情况。为什么 `strace` 不能工作,为什么`--cap-add=SYS_PTRACE` 可以解决这个问题?
|
||||
|
||||
### 假设 1:容器进程缺少 `CAP_SYS_PTRACE` 能力。
|
||||
|
||||
@ -49,13 +49,13 @@ CAP_SYS_PTRACE
|
||||
* Trace arbitrary processes using ptrace(2);
|
||||
```
|
||||
|
||||
所以,`CAP_SYS_PTRACE` 的作用是让你像 root 一样,可以对任何用户拥有的**任意**进程进行 `ptrace` 。你不需要用它来只是对一个由你的用户拥有的普通进程进行 `ptrace ` 。
|
||||
所以,`CAP_SYS_PTRACE` 的作用是让你像 root 一样,可以对任何用户拥有的**任意**进程进行 `ptrace`。你不需要用它来对一个只是由你的用户拥有的普通进程进行 `ptrace` 。
|
||||
|
||||
我用第三种方法测试了一下 —— 我用 `docker run --cap-add=SYS_PTRACE -it ubuntu:18.04 /bin/bash` 运行了一个 Docker 容器,去掉了 `CAP_SYS_PTRACE` 能力,但我仍然可以跟踪进程,虽然我已经没有这个能力了。什么?为什么?
|
||||
我用第三种方法测试了一下(LCTT 译注:此处可能原文有误) —— 我用 `docker run --cap-add=SYS_PTRACE -it ubuntu:18.04 /bin/bash` 运行了一个 Docker 容器,去掉了 `CAP_SYS_PTRACE` 能力,但我仍然可以跟踪进程,虽然我已经没有这个能力了。什么?为什么?!
|
||||
|
||||
### 假设 2:关于用户命名空间的事情?
|
||||
|
||||
我的下一个(没有那么充分的依据的)假设是“嗯,也许这个过程是在不同的用户命名空间里,而 `strace` 不能工作,因为某种原因而行不通?”这个问题其实并不连贯,但这是我观察时想到的。
|
||||
我的下一个(没有那么充分的依据的)假设是“嗯,也许这个过程是在不同的用户命名空间里,而 `strace` 不能工作,因为某种原因而行不通?”这个问题其实并不相关,但这是我观察时想到的。
|
||||
|
||||
容器进程是否在不同的用户命名空间中?嗯,在容器中:
|
||||
|
||||
@ -111,7 +111,7 @@ execve("/bin/ls", ["ls"], 0x7ffc69a65580 /* 8 vars */) = 0
|
||||
|
||||
Go 语言的好处是,因为依赖关系通常是在一个 Go 仓库里,你可以通过 `grep` 来找出做某件事的代码在哪里。所以我克隆了 `github.com/moby/moby`,然后对一些东西进行 `grep`,比如 `rg CAP_SYS_PTRACE`。
|
||||
|
||||
我认为是这样的。在 `containerd` 的 seccomp 实现中,在 [contrib/seccomp/seccomp/seccomp_default.go][3] 中,有一堆代码确保如果一个进程有一个能力,那么它也会(通过 seccomp 规则)获得访问权限,以使用与该能力相关的系统调用。
|
||||
我认为是这样的。在 `containerd` 的 seccomp 实现中,在 [contrib/seccomp/seccomp/seccomp_default.go][3] 中,有一堆代码来确保如果一个进程有一个能力,那么它也会(通过 seccomp 规则)获得访问权限,以使用与该能力相关的系统调用。
|
||||
|
||||
```
|
||||
case "CAP_SYS_PTRACE":
|
@ -0,0 +1,71 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (David vs Goliath! Microsoft and an Obscure KDE Project Fight Over “MAUI”)
|
||||
[#]: via: (https://itsfoss.com/microsoft-maui-kde-row/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
David vs Goliath! Microsoft and an Obscure KDE Project Fight Over “MAUI”
|
||||
======
|
||||
|
||||
Remember the [interview with Uri Herrera][1], the creator of [Nitrux Linux][2]? Uri also works on couple of other Linux-related projects and one of them is Maui project.
|
||||
|
||||
The MauiKit (styled as MAUI) is an acronym for Multi-Adaptable User Interfaces. It is an open source framework for developing cross-platform applications. It’s been in development since 2018 and it is now a [part of KDE’s incubation program KDE Invent][3].
|
||||
|
||||
Why am I talking about Maui? Because Microsoft has [renamed one of its project (Xamarin.Forms) to .NET MAUI][4]. This MAUI in .NET MAUI stands for Multi-platform App UI. It is also a framework for building cross-platform application.
|
||||
|
||||
You see the confusion here? Both MAUI projects are frameworks for building cross-platform applications.
|
||||
|
||||
### The debate over the use of “MAUI”
|
||||
|
||||
![][5]
|
||||
|
||||
MauiKit developers are obviously [not happy with this move by Microsoft][6].
|
||||
|
||||
> We like to believe that this an unfortunate event caused by an oversight during the brainstorming session to select a new and appealing name for their product and not an attempt at using the brand weight and marketing-might that a corporation such as Microsoft and their subsidiary Xamarin possess to step over a competing framework. A UI framework that, as of today, is still the first result in Google when searching for the term “Maui UI framework” but that due to the might of GitHub (another Microsoft subsidiary) and Microsoft’s website (specifically, their blog) SEO that will change over time.
|
||||
|
||||
A couple of issues were opened on the GitHub repository of .NET MAUI to bring their attention to this name clash.
|
||||
|
||||
The discussion got heated as some Microsoft MVPs and contributors (not Microsoft employees) started making arguments like MauiKit is a small project with fewer GitHub stars and no big companies use it.
|
||||
|
||||
Microsoft’s Program Manager [David Ortinau][7] closed the thread with the message, “official legal name is .NET Multi-platform App UI and MAUI is an acronym, code name. This has been through legal review”.
|
||||
|
||||
![Microsoft’s official response][8]
|
||||
|
||||
This is the [main thread][9] that you can follow on GitHub if you want.
|
||||
|
||||
### Is it really an issue?
|
||||
|
||||
It may seem like a non-issue at the first glance but two projects with the same aim and same name are bound to create confusion. It would have been best that Microsoft had avoided it altogether.
|
||||
|
||||
By the way, this is not the first time Microsoft has a name clash with a Linux-related project. As [Phoronix noted][10], a few years ago it was GNOME developers frustrated with Microsoft over naming a project GVFS (later renamed to Virtual File System for Git) as it collided with their GVFS (GNOME Virtual File-System)
|
||||
|
||||
By the looks of it, Microsoft is not going to backtrack on MAUI. It could even go ahead and trademark MAUI. They have got all the money and power after all.
|
||||
|
||||
I wonder what would have been the case if an obscure small project used the same name as one of Microsoft’s projects.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/microsoft-maui-kde-row/
|
||||
|
||||
作者:[Abhishek Prakash][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/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/nitrux-linux/
|
||||
[2]: https://nxos.org/
|
||||
[3]: https://invent.kde.org/maui/mauikit
|
||||
[4]: https://devblogs.microsoft.com/dotnet/introducing-net-multi-platform-app-ui/
|
||||
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/david-vs-goliath.jpg?ssl=1
|
||||
[6]: https://nxos.org/news/official-statement-regarding-xamarin-forms-rebranding-as-maui/
|
||||
[7]: https://github.com/davidortinau
|
||||
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/05/microsoft-response-maui.png?ssl=1
|
||||
[9]: https://github.com/dotnet/maui/issues/35
|
||||
[10]: https://www.phoronix.com/scan.php?page=news_item&px=Microsoft-KDE-MAUI
|
@ -0,0 +1,95 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (In Free Software, the Community is the Most Important Ingredient: Jerry Bezencon of Linux Lite [Interview])
|
||||
[#]: via: (https://itsfoss.com/linux-lite-interview/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
In Free Software, the Community is the Most Important Ingredient: Jerry Bezencon of Linux Lite [Interview]
|
||||
======
|
||||
|
||||
You are probably aware of [Linux Lite][1]. It is a [lightweight Linux distribution][2] based on Ubuntu. If you have an older system with 1 GB of RAM, Linux Lite becomes an excellent choice for you.
|
||||
|
||||
We have covered Linux Lite releases several times on It’s FOSS and if you are a regular reader, you would have come across it.
|
||||
|
||||
![][3]
|
||||
|
||||
We talked to Jerry Bezencon, the creator of Linux Lite project, to know some background details on this project.
|
||||
|
||||
### Interview with Jerry Bezencon of Linux Lite
|
||||
|
||||
Jerry is based in Auckland, New Zealand, and he devotes a good deal of time and effort on Linux Lite project. Jerry shares his vision of the project in this interview.
|
||||
|
||||
_**Tell us about the origins of Linux Lite. When did you create it first and what made you create it in the first place?**_
|
||||
|
||||
Linux Lite was started in 2012 for 3 important reasons. One, I wanted to dispel myths that a Linux based operating system was hard to use. Two, at that time, there was a shortage of simple, intuitive desktop experiences on Linux that offered long-term support. Three, I had used Linux for over 10 years before starting Linux Lite.
|
||||
|
||||
I felt I needed to give back to a community that had given so much to me. A community that taught me that by sharing code and knowledge, one could have a dramatically positive impact over peoples computing experiences.
|
||||
|
||||
_**How is Linux Lite different from so many other Ubuntu-based distributions?**_
|
||||
|
||||
Our approach to problem solving and our support. The first sits within the system itself. Lite Tweaks is a good example of this. We try to think of all the things that could possibly go wrong with a computer system, then write applications that fix those problems as easily as possible, should they occur. There is a lot of foresight in the team.
|
||||
|
||||
The second is our approach to support. This mainly comes in 2 forms. Our massive built-in and online Help Manual and [our large forum community][4] full of some of the nicest people I’ve ever dealt with in the free software and open source community.
|
||||
|
||||
_**How do you and your team work on developing Linux Lite?**_
|
||||
|
||||
There are 24 hours in a day. With 6 – 8 hours for sleep and another 6 – 8 hours for my other job, that’s more than enough time to put towards any project, hobby or job, or all 3.
|
||||
|
||||
I take a more professional approach to code writing. I’ll come up with an idea, mock-up the UI then write the base code, or the whole application myself. If I need help, I prefer to hire and pay via our generous donators, freelancers.
|
||||
|
||||
That way I can set a budget, the user gets a solid, well-written application by a qualified professional who is fluent in that language, and get I exactly what I ask for on time and without the usual flame wars and egos that can exist in some teams.
|
||||
|
||||
By using professional, paid programmers, I avoid all the negativity completely. Application writing has become an extremely peaceful and rewarding exercise.
|
||||
|
||||
_**What are you most proud of about this project?**_
|
||||
|
||||
![Linux Lite Interview][5]
|
||||
|
||||
I’m most proud of the community that has stayed loyal to us throughout the years. In a business, your staff are your most valuable asset, in free software, the community is the most important ingredient.
|
||||
|
||||
_**What are your future plans with Linux Lite?**_
|
||||
|
||||
To always strive to look for ways to make a person’s computing experience simpler, faster and trouble free. Our target audience shouldn’t have to dive into the terminal to try and fix things. To continue to build a feature-complete operating system that is light on resources.
|
||||
|
||||
_**What new features can we expect in Linux Lite in upcoming versions?**_
|
||||
|
||||
Due to tradition, we like to keep those as surprises. I never run out of ideas. Some nights I get no sleep because my mind is buzzing with ideas for our next application, or how to solve an ongoing, difficult bug.
|
||||
|
||||
_**Are there any features that you really want to implement but haven’t been able to do so far?**_
|
||||
|
||||
You can always do more to enhance an operating system. I’m currently working on our most ambitious application to date. One that doesn’t need a GUI and that sits within the system, anticipates problems and solves them before they are seen by the user. It will have a Reports feature so that those who like to know what is going on, can see for themselves what the code is doing. It will, of course, be free software. My first foray into A.I. that I hope other Linux systems can benefit from in the future.
|
||||
|
||||
_**Have you achieved the goal for which you started the project?**_
|
||||
|
||||
Goal setting is ongoing. There’s no such thing as the perfect operating system. But there is no harm in aiming for that.
|
||||
|
||||
_**How can the users and readers help the project?**_
|
||||
|
||||
In the usual ways. Documentation, coding, volunteering on the Forums, buying merchandise, writing blogs, donating, making videos, starting websites like yours – the list goes on.
|
||||
|
||||
* * *
|
||||
|
||||
We hope you like reading about the background of open source projects. You may [read more interviews with various project leaders][6].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/linux-lite-interview/
|
||||
|
||||
作者:[Abhishek Prakash][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/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.linuxliteos.com/
|
||||
[2]: https://itsfoss.com/lightweight-linux-beginners/
|
||||
[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/Linux_Lite.jpg?ssl=1
|
||||
[4]: https://www.linuxliteos.com/forums/
|
||||
[5]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/05/linux-lite-interview.png?ssl=1
|
||||
[6]: https://itsfoss.com/interviews/
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (Zioyi)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -0,0 +1,132 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to manage network services with firewall-cmd)
|
||||
[#]: via: (https://fedoramagazine.org/how-to-manage-network-services-with-firewall-cmd/)
|
||||
[#]: author: (dan01 https://fedoramagazine.org/author/dan01/)
|
||||
|
||||
How to manage network services with firewall-cmd
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
In a previous article, you explored how to [control the firewall at the command line][2] in Fedora.
|
||||
|
||||
Now you are going to see how to see how _add_, _remove_, and _list_ _services_, _protocols_ and _ports_ in order to _block_ or _allow_ them.
|
||||
|
||||
### A short recap
|
||||
|
||||
First, it’s a good idea to check the _status_ of your firewall, see if it’s running or not. You do this, as we previously learned, by using the state option (_firewall-cmd_ ‐‐_state_).
|
||||
|
||||
The next step is to get the zone for the desired network interface. For example, I use a desktop that has two network interfaces: a _physical_ interface (_enp0s3_), representing my actual _network card_ and a _virtual_ interface (_virbr0_) used by virtualization software like _KVM_. To see what zones are active, run _firewall-cmd ‐‐get-active-zones_.
|
||||
|
||||
Now that you know what zone you’re interested in, you can list the rules for the zone with _firewall-cmd ‐‐info-zone=FedoraWorkstation_.
|
||||
|
||||
### Reading zone information
|
||||
|
||||
To display information for a particular _zone_, run _firewall-cmd ‐‐zone=ZoneName ‐‐list-all_, or simply display information for the default zone with:
|
||||
|
||||
```
|
||||
[dan@localhost ~]$ firewall-cmd --list-all
|
||||
FedoraWorkstation (active)
|
||||
target: default
|
||||
icmp-block-inversion: no
|
||||
interfaces: enp0s3
|
||||
sources:
|
||||
services: dhcpv6-client mdns samba-client ssh
|
||||
ports: 1025-65535/udp 1025-65535/tcp
|
||||
protocols:
|
||||
masquerade: no
|
||||
forward-ports:
|
||||
source-ports:
|
||||
icmp-blocks:
|
||||
rich rules:
|
||||
```
|
||||
|
||||
Now, let’s explore the output. The first line is showing which _zone_ the following information applies to and if that zone is currently in use.
|
||||
|
||||
The _target_ : _default_ simply tells us this is the default zone. This can be set or retrieved via the _‐‐set-default-zone=ZoneName_ and _‐‐get-default-zone_.
|
||||
|
||||
_icmp-block-inversion_, indicates if [ICMP][3] requests are blocked. For example if the machine responds to _ping_ requests from other machines on the network. The _interfaces_ field shows all interfaces that adopt this zone.
|
||||
|
||||
### Handling services, ports, and protocols
|
||||
|
||||
Now focus on the _services_, _ports_, and _protocols_ rows. By default, the firewall will block all ports, services and protocols. Only the listed ones will be allowed.
|
||||
|
||||
You can see the allowed services are very basic client services in this case. For example, accessing a shared folder on the network (_samba-client_), to talk to a _DNS_ server or connect to a machine via SSH (the _ssh_ service). You can think of a _service_ as a protocol in combination to a port, for instance the ssh service is using the SSH protocol and, by convention, port 22. By allowing the ssh service, what you’re really doing is allowing incoming connections that use the ssh protocol at default port 22.
|
||||
|
||||
Notice, services that have the _client_ word in their name, as a rule of thumb, refer to outgoing connections, i.e. _connections_ that you make with your IP as source going to the outside, as opposed to the SSH **service, for example, that will accept incoming connections (listening to connection coming from outside at you).
|
||||
|
||||
You can look up services in the file _/etc/services_. For example if you wish to know what port and protocol these service uses:
|
||||
|
||||
```
|
||||
[dan@localhost ~]$ cat /etc/services | grep ssh
|
||||
ssh 22/tcp # The Secure Shell (SSH) Protocol
|
||||
ssh 22/udp # The Secure Shell (SSH) Protocol
|
||||
```
|
||||
|
||||
You can see SSH uses both TCP and UDP port 22. Also, if you wish to see all available services, just use _firewall-cmd ‐‐get-services_.
|
||||
|
||||
#### Opening a port
|
||||
|
||||
If you want to block a port, service, or protocol, all you have to do if make sure it’s not listed here. By extension, if you want to allow a service, you need add it to your list.
|
||||
|
||||
Let’s say you want to open the port _5000_ for _TCP_ ****connection. To do this, run:
|
||||
|
||||
```
|
||||
sudo firewall-cmd --zone=FedorwaWorkstation --permanent --add-port=5000/tcp
|
||||
```
|
||||
|
||||
Notice that you need to specify the zone for which the rule applies. When you add the rule, you also need to specify if it is a _TCP_ or _UDP_ port via as indicated above. The _permanent_ parameter sets the rule to persist even after a system reboot.
|
||||
|
||||
Look at the information for your zone again:
|
||||
|
||||
```
|
||||
[dan@localhost ~]$ firewall-cmd --list-all
|
||||
FedoraWorkstation (active)
|
||||
target: default
|
||||
icmp-block-inversion: no
|
||||
interfaces: enp0s3
|
||||
sources:
|
||||
services: dhcpv6-client mdns samba-client ssh
|
||||
ports: 1025-65535/udp 1025-65535/tcp 5000/tcp
|
||||
protocols:
|
||||
masquerade: no
|
||||
forward-ports:
|
||||
source-ports:
|
||||
icmp-blocks:
|
||||
rich rules:
|
||||
```
|
||||
|
||||
Similarly, if you wish to remove this port from the list, run:
|
||||
|
||||
```
|
||||
sudo firewall-cmd --zone=FedorwaWorkstation --permanent --remove-port=5000/tcp
|
||||
```
|
||||
|
||||
The very same _remove_ (_‐‐remove-protocol_, _‐‐remove-service_) and _add_ (_‐‐add-protocol_, _‐‐add-service_) options are also available for _services_ and _protocols_.
|
||||
|
||||
* * *
|
||||
|
||||
_Photo by [T. Kaiser][4] on [Unsplash][5]_.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/how-to-manage-network-services-with-firewall-cmd/
|
||||
|
||||
作者:[dan01][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/dan01/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2020/05/services-firewall-cmd-816x345.jpg
|
||||
[2]: https://fedoramagazine.org/control-the-firewall-at-the-command-line/
|
||||
[3]: https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol
|
||||
[4]: https://unsplash.com/@tkaiser?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[5]: https://unsplash.com/s/photos/poke-hole?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
172
sources/tech/20200515 The pieces of Fedora Silverblue.md
Normal file
172
sources/tech/20200515 The pieces of Fedora Silverblue.md
Normal file
@ -0,0 +1,172 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (The pieces of Fedora Silverblue)
|
||||
[#]: via: (https://fedoramagazine.org/pieces-of-fedora-silverblue/)
|
||||
[#]: author: (Nick Hardiman https://fedoramagazine.org/author/nickhardiman/)
|
||||
|
||||
The pieces of Fedora Silverblue
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
Fedora Silverblue provides a useful workstation build on an immutable operating system. In “[What is Silverblue?][2]“, you learned about the benefits that an immutable OS provides. But what pieces go into making it? This article examines some of the technology that powers Silverblue.
|
||||
|
||||
### The filesystem
|
||||
|
||||
Fedora Workstation users may find the idea of an immutable OS to be the most brain-melting part of Silverblue. What does that mean? Find some answers by taking a look at the filesystem.
|
||||
|
||||
At first glance, the layout looks pretty much the same as a regular Fedora file system. It has some differences, like making _/home_ a symbolic link to _/var/home_. And you can get more answers by looking at how libostree works. libostree treats the whole tree like it’s an object, checks it into a code repository, and checks out a copy for your machine to use.
|
||||
|
||||
#### libostree
|
||||
|
||||
The [libostree project][3] supplies the goods for managing Silverblue’s file system. It is an upgrade system that the user can control using [rpm-ostree commands][4].
|
||||
|
||||
libostree knows nothing about packages—an upgrade means replacing one complete file system with another complete file system. libostree treats the file system tree as one atomic object (an unbreakable unit). In fact, the forerunner to Silverblue was named [Project Atomic][5].
|
||||
|
||||
The libostree project provides a library and set of tools. It’s an upgrade system that carries out these tasks.
|
||||
|
||||
1. Pull in a new file system
|
||||
2. Store the new file system
|
||||
3. Deploy the new file system
|
||||
|
||||
|
||||
|
||||
##### Pull in a new file system
|
||||
|
||||
Pulling in a new file system means copying an object (the entire file system) from a remote source to its own store. If you’ve worked with virtual machine image files, you already understand the concept of a file system object that you can copy.
|
||||
|
||||
##### Store the new file system
|
||||
|
||||
The libostree store has some source code control qualities—it stores many file system objects, and checks one out to be used as the root file system. libostree’s store has two parts:
|
||||
|
||||
* a repository database at _/sysroot/ostree/repo/_
|
||||
* file systems in _/sysroot/ostree/deploy/fedora/deploy/_
|
||||
|
||||
|
||||
|
||||
libostree keeps track of what’s been checked in using commit IDs. Each commit ID can be found in a directory name, nested deep inside _/sysroot_ .A libostree commit ID is a long checksum, and looks similar to a git commit ID.
|
||||
|
||||
```
|
||||
$ ls -d /sysroot/ostree/deploy/fedora/deploy/*/
|
||||
/sysroot/ostree/deploy/fedora/deploy/c4bf7a6339e6be97d0ca48a117a1a35c9c5e3256ae2db9e706b0147c5845fac4.0/
|
||||
```
|
||||
|
||||
_rpm-ostree status_ gives a little more information about that commit ID. The output is a little confusing; it can take a while to see this file system is Fedora 31.
|
||||
|
||||
```
|
||||
$ rpm-ostree status
|
||||
State: idle
|
||||
AutomaticUpdates: disabled
|
||||
Deployments:
|
||||
● ostree://fedora:fedora/31/x86_64/silverblue
|
||||
Version: 31.1.9 (2019-10-23T21:44:48Z)
|
||||
Commit: c4bf7a6339e6be97d0ca48a117a1a35c9c5e3256ae2db9e706b0147c5845fac4
|
||||
GPGSignature: Valid signature by 7D22D5867F2A4236474BF7B850CB390B3C3359C4
|
||||
```
|
||||
|
||||
##### Deploy the new filesystem
|
||||
|
||||
libostree deploys a new file system by checking out the new object from its store. libostree doesn’t check out a file system by copying all the files—it uses hard links instead. If you look inside the commit ID directory, you see something that looks suspiciously like the root directory. That’s because it _is_ the root directory. You can see these two directories are pointing to the same place by checking their inodes.
|
||||
|
||||
```
|
||||
$ ls -di1 / /sysroot/ostree/deploy/fedora/deploy/*/
|
||||
260102 /
|
||||
260102 /sysroot/ostree/deploy/fedora/deploy/c4bf7a6339e6be97d0ca48a117a1a35c9c5e3256ae2db9e706b0147c5845fac4.0/
|
||||
```
|
||||
|
||||
This is a fresh install, so there’s only one commit ID. After a system update, there will be two. If more copies of the file system are checked into libostree’s repo, more commit IDs appear here.
|
||||
|
||||
##### Upgrade process
|
||||
|
||||
Putting the pieces together, the update process looks like this:
|
||||
|
||||
1. libostree checks out a copy of the file system object from the repository
|
||||
2. DNF installs packages into the copy
|
||||
3. libostree checks in the copy as a new object
|
||||
4. libostree checks out the copy to become the new file system
|
||||
5. You reboot to pick up the new system files
|
||||
|
||||
|
||||
|
||||
In addition to more safety, there is more flexibility. You can do new things with libostree’s repo, like store a few different file systems and check out whichever one you feel like using.
|
||||
|
||||
#### Silverblue’s root file system
|
||||
|
||||
Fedora keeps its system files in all the usual Linux places, such as _/boot_ for boot files, _/etc_ for configuration files, and _/home_ for user home directories. The root directory in Silverblue looks much like the root directory in traditional Fedora, but there are some differences.
|
||||
|
||||
* The filesystem has been checked out by libostree
|
||||
* Some directories are now symbolic links to new locations. For example, _/home_ is a symbolic link to _/var/home_
|
||||
* _/usr_ is a read-only directory
|
||||
* There’s a new directory named _/sysroot_. This is libostree’s new home
|
||||
|
||||
|
||||
|
||||
#### Juggling file systems
|
||||
|
||||
You can store many file systems and switch between them. This is called _rebasing_, and it’s similar to git rebasing. In fact, upgrading Silverblue to the next Fedora version is not a big package install—it’s a pull from a remote repository and a rebase.
|
||||
|
||||
You could store three copies with three different desktops: one KDE, one GNOME, and one XFCE. Or three different OS versions: how about keeping the current version, the nightly build, and an old classic? Switching between them is a matter of rebasing to the appropriate file system object.
|
||||
|
||||
Rebasing is also how you upgrade from one Fedora release to the next. See “[How to rebase to Fedora 32 on Silverblue][6]” for more information.
|
||||
|
||||
### Flatpak
|
||||
|
||||
The [Flatpak project][7] provides a way of installing applications like LibreOffice. Applications are pulled from remote repositories like [Flathub][8]. It’s a kind of package manager, although you won’t find the word _package_ in the [docs][9]. Traditional Fedora variants like Fedora Workstation can also use Flatpak, but the sandboxed nature of flatpaks make it particularly good for Silverblue. This way you do not have to do the entire ostree update process every time you wish to install an application.
|
||||
|
||||
Flatpak is well-suited to desktop applications, but also works for command line applications. You can install the [vim][10] editor with the command _flatpak install flathub org.vim.Vim_ and run it with _flatpak run org.vim.Vim_.
|
||||
|
||||
### toolbox
|
||||
|
||||
The [toolbox project][11] provides a traditional operating system inside a container. The idea is that you can mess with the mutable OS inside your toolbox (the Fedora container) as much as you like, and leave the immutable OS outside your toolbox untouched. You pack as many toolboxes as you want on your system, so you can keep work separated. Behind the scenes, the executable _/usr/bin/toolbox_ is a shell script that uses [podman][12].
|
||||
|
||||
A fresh install does not include a default toolbox. The _toolbox create_ command checks the OS version (by reading _/usr/lib/os-release_), looks for a matching version at the Fedora container registry, and downloads the container.
|
||||
|
||||
```
|
||||
$ toolbox create
|
||||
Image required to create toolbox container.
|
||||
Download registry.fedoraproject.org/f31/fedora-toolbox:31 (500MB)? [y/N]: y
|
||||
Created container: fedora-toolbox-31
|
||||
Enter with: toolbox enter
|
||||
```
|
||||
|
||||
Hundreds of packages are installed inside the toolbox. The _dnf_ command and the usual Fedora repos are set up, ready to install more. The _ostree_ and _rpm-ostree_ commands are not included – no immutable OS here.
|
||||
|
||||
Each user’s home directory is mounted on their toolbox, for storing content files outside the container.
|
||||
|
||||
### Put the pieces together
|
||||
|
||||
Spend some time exploring Fedora Silverblue and it will become clear how these components fit together. Like other Fedora variants, all these of tools come from open source projects. You can get as up close and personal as you want, from reading their docs to contributing code. Or you can [contribute to Silverblue][13] itself.
|
||||
|
||||
Join the Fedora Silverblue conversations on [discussion.fedoraproject.org][14] or in [#silverblue on Freenode IRC][15].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/pieces-of-fedora-silverblue/
|
||||
|
||||
作者:[Nick Hardiman][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/nickhardiman/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2020/04/silverblue-pieces-816x345.png
|
||||
[2]: https://fedoramagazine.org/what-is-silverblue/
|
||||
[3]: https://ostree.readthedocs.io/en/latest/
|
||||
[4]: https://rpm-ostree.readthedocs.io/en/latest/manual/administrator-handbook/#administering-an-rpm-ostree-based-system
|
||||
[5]: https://www.projectatomic.io/
|
||||
[6]: https://fedoramagazine.org/how-to-rebase-to-fedora-32-on-silverblue/
|
||||
[7]: https://github.com/flatpak/flatpak
|
||||
[8]: https://flathub.org/
|
||||
[9]: http://docs.flatpak.org/en/latest/index.html
|
||||
[10]: https://www.vim.org/
|
||||
[11]: https://github.com/containers/toolbox
|
||||
[12]: https://github.com/containers/libpod
|
||||
[13]: https://silverblue.fedoraproject.org/contribute
|
||||
[14]: https://discussion.fedoraproject.org/c/desktop/silverblue
|
||||
[15]: https://webchat.freenode.net/#silverblue
|
@ -0,0 +1,208 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Using Fedora to implement REST API in JavaScript: part 2)
|
||||
[#]: via: (https://fedoramagazine.org/using-fedora-to-implement-rest-api-in-javascript-part-2/)
|
||||
[#]: author: (Vaclav Keil https://fedoramagazine.org/author/vaclavk/)
|
||||
|
||||
Using Fedora to implement REST API in JavaScript: part 2
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
In [part 1][2] previously, you saw how to quickly create a simple API service using Fedora Workstation, Express, and JavaScript. This article shows you the simplicity of how to create a new API. This part shows you how to:
|
||||
|
||||
* Install a DB server
|
||||
* Build a new route
|
||||
* Connect a new datasource
|
||||
* Use Fedora terminal to send and receive data
|
||||
|
||||
|
||||
|
||||
### Generating an app
|
||||
|
||||
Please refer to the [previous article][2] for more details. But to make things simple, change to your work directory and generate an app skeleton.
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
$ cd our-work-directory
|
||||
$ npx express-generator –no-view –git /myApp
|
||||
$ cd myApp
|
||||
$ npm i
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
### Installing a database server
|
||||
|
||||
In this part, we’ll install MariaDB database. MariaDB is the Fedora default database.
|
||||
|
||||
```
|
||||
$ dnf module list mariadb | sort -u ## lists the streams available
|
||||
$ sudo dnf module install mariadb:10.3 ##10.4 is the latest
|
||||
```
|
||||
|
||||
_Note: the default profile is mariadb/server_.
|
||||
|
||||
For those who need to spin up a Docker container a ready made container with Fedora 31 is available.
|
||||
|
||||
```
|
||||
$ docker pull registry.fedoraproject.org/f31/mariadb
|
||||
$ docker run -d --name mariadb_database -e MYSQL_USER=user -e MYSQL_PASSWORD=pass -e MYSQL_DATABASE=db -p 3306:3306 registry.fedoraproject.org/f31/mariadb
|
||||
```
|
||||
|
||||
Now start the MariaDB service.
|
||||
|
||||
```
|
||||
$ sudo systemctl start mariadb
|
||||
```
|
||||
|
||||
If you’d like the service to start at boot, you can also enable it in systemd:
|
||||
|
||||
```
|
||||
$ sudo systemctl enable mariadb ## start at boot
|
||||
```
|
||||
|
||||
Next, setup the database as needed:
|
||||
|
||||
```
|
||||
$ mysql -u root -p ## root password is blank
|
||||
MariaDB> CREATE DATABASE users;
|
||||
MariaDB> create user dbuser identified by ‘123456‘;
|
||||
MariaDB> grant select, insert, update, create, drop on users.* to dbuser;
|
||||
MariaDB> show grants for dbuser;
|
||||
MariaDB> \q
|
||||
```
|
||||
|
||||
A database connector is needed to use the database with Node.js.
|
||||
|
||||
```
|
||||
$ npm install mariadb ## installs MariaDB Node.js connector
|
||||
```
|
||||
|
||||
We’ll leverage Sequelize in this sample API. Sequelize is a promise-based Node.js ORM (Object Relational Mapper) for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server.
|
||||
|
||||
```
|
||||
$ npm install sequelize ## installs Sequelize
|
||||
```
|
||||
|
||||
### Connecting a new datasource
|
||||
|
||||
Now, create a new _db_ folder and create a new file _sequelize.js_ there:
|
||||
|
||||
```
|
||||
const Sequelize = require('sequelize'),
|
||||
sequelize = new Sequelize(process.env.db_name || 'users', process.env.db_user || 'dbuser', process.env.db_pass || '123456', {
|
||||
host: 'localhost',
|
||||
dialect: 'mariadb',
|
||||
ssl: true
|
||||
})
|
||||
|
||||
module.exports = sequelize
|
||||
```
|
||||
|
||||
_Note: For the sake of completeness I‘m including a link to the related Github repo: <https://github.com/vaclav18/express-api-mariadb>_
|
||||
|
||||
Let‘s create a new file _models/user.js_. A nice feature of a Sequelize model is that it helps us to create the necessary tables and colums automatically. The code snippet responsible for doing this is seen below:
|
||||
|
||||
```
|
||||
sequelize.sync({
|
||||
force: false
|
||||
})
|
||||
```
|
||||
|
||||
Note: never switch to true with a production database – it would _drop your tables at app start_!
|
||||
|
||||
We will refer to the earlier created sequelize.js this way:
|
||||
|
||||
```
|
||||
const sequelize = require('../db/sequelize')
|
||||
```
|
||||
|
||||
### Building new routes
|
||||
|
||||
Next, you’ll create a new file _routes/user.js_. You already have _routes/users.js_ from the previous article. You can copy and paste the code in and proceed with editing it.
|
||||
|
||||
You’ll also need a reference to the previously created model.
|
||||
|
||||
```
|
||||
const User = require('../models/user')
|
||||
```
|
||||
|
||||
Change the route path to _/users_ and also create a new **post** method route.
|
||||
|
||||
Mind the async – await keywords there. An interaction with a database will take some time and this one will do the trick. Yes, an async function returns a promise and this one makes promises easy to use.
|
||||
|
||||
_Note: This code is not production ready, since it would also need to include an authentication feature._
|
||||
|
||||
We‘ll make the new route working this way:
|
||||
|
||||
```
|
||||
const userRouter = require('./routes/user')
|
||||
app.use(userRouter)
|
||||
```
|
||||
|
||||
Let‘s also remove the existing _usersRouter_. The _routes/users.js_ can be deleted too.
|
||||
|
||||
```
|
||||
$ npm start
|
||||
```
|
||||
|
||||
With the above command, you can launch your new app.
|
||||
|
||||
### Using the terminal to send and retrieve data
|
||||
|
||||
Let’s create a new database record through the post method:
|
||||
|
||||
```
|
||||
$ curl -d 'name=Adam' http://localhost:3000/users
|
||||
```
|
||||
|
||||
To retrieve the data created through the API, do an HTTP GET request:
|
||||
|
||||
```
|
||||
$ curl http://localhost:3000/users
|
||||
```
|
||||
|
||||
The console output of the curl command is a JSON array containing data of all the records in the _Users_ table.
|
||||
|
||||
_Note: This is not really the usual end result — an application consumes the API finally. The API will usually also have endpoints to update and remove data._
|
||||
|
||||
### More automation
|
||||
|
||||
Let‘s assume we might want to create an API serving many tables. It‘s possible and very handy to automatically generate models for Sequelize from our database. Sequelize-auto will do the heavy lifting for us. The resulting files (_models.js_) would be placed and imported within the _/models_ directory.
|
||||
|
||||
```
|
||||
$ npm install sequelize-auto
|
||||
```
|
||||
|
||||
A node.js connector is needed to use this one and we have it already installed for MariaDB.
|
||||
|
||||
### Conclusion
|
||||
|
||||
It‘s possible to develop and run an API using Fedora, Fedora default MariaDB, JavaScript and efficiently develop a solution like with a noSQL database. For those used to working with MongoDB or a similar noSQL database, Fedora and MariaDB are important open-source enablers.
|
||||
|
||||
* * *
|
||||
|
||||
_Photo by [Mazhar Zandsalimi][3] on [Unsplash][4]._
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/using-fedora-to-implement-rest-api-in-javascript-part-2/
|
||||
|
||||
作者:[Vaclav Keil][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/vaclavk/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2020/05/javascript-api-2-816x345.jpg
|
||||
[2]: https://fedoramagazine.org/using-fedora-to-quickly-implement-rest-api-with-javascript/
|
||||
[3]: https://unsplash.com/@m47h4r?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
||||
[4]: https://unsplash.com/s/photos/javascript?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
|
@ -0,0 +1,140 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Fedora Silverblue, an introduction for developers)
|
||||
[#]: via: (https://fedoramagazine.org/fedora-silverblue-brings-future-tech-to-the-desktop/)
|
||||
[#]: author: (Nick Hardiman https://fedoramagazine.org/author/nickhardiman/)
|
||||
|
||||
Fedora Silverblue, an introduction for developers
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
The Fedora [Silverblue project][2] takes Fedora workstation, libostree and podman, puts them in a blender, and creates a new Immutable Fedora Workstation. Fedora Silverblue is an OS that stops you from changing the core system files arbitrarily, and readily allows you to change the environment system files. The article [What is Silverblue][3] describes the big picture, and this article drills down into details for the developer.
|
||||
|
||||
Fedora Silverblue ties together a few different projects to make a system that is a git-like object, capable of layering packages, and has a container focused work flow. Silverblue is not the only distribution going down this road. It is the desktop equivalent of [CoreOS][4], the server OS used by [Red Hat Openshift][5].
|
||||
|
||||
Silverblue’s idea of ‘immutable’ has nothing to do with immutable layers in a container. Silverblue keeps system files immutable by making them read-only.
|
||||
|
||||
### Why immutable?
|
||||
|
||||
Has an upgrade left your system in an unusable state? Have you wondered why one server in a pool of identical machines is being weird? These problems can happen when one system library – one tiny little file out of hundreds – is corrupted, badly configured or the wrong version. Or maybe your upgrade works fine but it’s not what you’d hoped for, and you want to roll back to the previous state.
|
||||
|
||||
An immutable OS is intended to stop problems like these biting you. This is not an easy thing to achieve – simple changes, like flipping the file system between read-write and read-only, may only change a fault-finding headache to a maintenance headache.
|
||||
|
||||
Freezing the system is good news for sysadmins, but what about developers? Setting up a development environment means heavily customizing the system, and filling it with living code that changes over time. The answer is partly a case of combining components, and partly the ability to swap between OS versions.
|
||||
|
||||
### How it works
|
||||
|
||||
So how do you get the benefits of immutability without losing the ability to do your work? If you’re thinking ‘containers’, good guess – part of the solution uses [podman][6]. But much of the work happens underneath the container layer, at the OS level.
|
||||
|
||||
Fedora Silverblue ties together a few different projects to turn an immutable OS into a usable workstation. Silverblue uses libostree to provide the base system, lets you edit config files in /etc/, and provides three different ways to install packages.
|
||||
|
||||
* [rpm-ostree][7] installs RPM packages, similar to DNF in the traditional Fedora workstation. Use this for things that shouldn’t go in containers, like KVM/libvirt.
|
||||
* [flatpak][8] installs packages from a central flathub repo. This is the one-stop shop for graphical desktop apps like LibreOffice.
|
||||
* The traditional _dnf install_ still works, but only inside a [toolbox][9] (a Fedora container). A developer’s workbench goes in a toolbox.
|
||||
|
||||
|
||||
|
||||
If you want to know more about these components, check out [Pieces of Silverblue][10].
|
||||
|
||||
### Rolling back and pinning upgrades
|
||||
|
||||
All operating systems need upgrades. Features are added, security holes are plugged and bugs are squashed. But sometimes an upgrade is not a developer’s friend.
|
||||
|
||||
A developer depends on many things to get the job done. A good development environment is stuffed with libraries, editors, toolchains and apps that are controlled by the OS, not the developer. An upgrade may cause trouble. Have any of these situations happened to you?
|
||||
|
||||
* A new encryption library is too strict, and an upgrade stopped an API working.
|
||||
* Code works well, but has deprecated syntax. An upgrade brought error-throwing misery.
|
||||
* The development environment is lovingly hand-crafted. An upgrade broke dependencies and added conflicts.
|
||||
|
||||
|
||||
|
||||
In a traditional environment, unpicking a troublesome upgrade is hard. In Silverblue, it’s easy. Silverblue keeps two copies of the OS – your current upgrade and your previous version. Point the OS at the previous version, reboot, and you’ve got your old system files back.
|
||||
|
||||
You aren’t limited to two copies of your file system – you can keep more by pinning your favorite versions. Dusty Mabe, one of the engineers who has been working on the system since the [Project Atomic][11] days, describes how to pin extra copies of the OS in his article [Pinning Deployments in OSTree Based Systems][12].
|
||||
|
||||
Your home directory is not affected by rolling back. Rpm-ostree does not touch /etc/ and /var/.
|
||||
|
||||
### System updates and package installs
|
||||
|
||||
Silverblue’s rpm-ostree treats all the files as one object, stored in a repository. The working file system is a checked-out copy of this object. After a system update, you get two objects in that repository – one current object and one updated object. The updated object is checked out and becomes the new file system.
|
||||
|
||||
You install your workhorse applications in toolboxes, which provide container isolation. And you install your desktop applications using Flatpak.
|
||||
|
||||
This new OS requires a shift in approach. For instance, you don’t have to keep only one copy of your system files – you can store a few and select which one you use. That means you can swap back and forth between an old Fedora release and the rawhide (development) version in a matter of minutes.
|
||||
|
||||
### Build your own Silverblue VM
|
||||
|
||||
You can safely install Fedora Silverblue in a VM on your workstation. If you’ve got a hypervisor and half an hour to spare (10 minutes for ISO download, and 20 minutes for the build), you can see for yourself.
|
||||
|
||||
1. Download Fedora Silverblue ISO from
|
||||
2. <https://silverblue.fedoraproject.org/download> (not Fedora workstation from <https://getfedora.org/>).
|
||||
3. Boot a VM with the Fedora Silverblue ISO. You can squeeze Fedora into compute resources of 1 CPU, 1024MiB of memory and 12GiB of storage, but bigger is better.
|
||||
4. Answer [Anaconda][13]’s questions.
|
||||
5. Wait for the [Gnome][14] desktop to appear.
|
||||
6. Answer [Initial Setup][15]’s questions.
|
||||
|
||||
|
||||
|
||||
Then you’re ready to set up your developer’s tools. If you’re looking for an IDE, check these out. Use flatpak on the desktop to install them.
|
||||
|
||||
* [Gnome Builder][16] (Gnome’s official IDE)
|
||||
* [Eclipse][17]
|
||||
* [Code::Blocks][18]
|
||||
|
||||
|
||||
|
||||
Finally, use the CLI to create your first toolbox. Load it with modules using [npm][19], [gem][20], [pip][21], [git][22] or your other favorite tools.
|
||||
|
||||
### Help!
|
||||
|
||||
If you get stuck, ask questions at the [forum][23].
|
||||
|
||||
If you’re looking for ideas about how to use Silverblue, read articles in the [magazine][24].
|
||||
|
||||
### Is Silverblue for you?
|
||||
|
||||
Silverblue is full of shiny new tech. That in itself is enough to attract the cool kids, like moths to a flame. But this OS is not for everyone. It’s a young system, so some bugs will still be lurking in there. And pioneering tech requires a change of habit – that’s extra cognitive load that the new user may not want to take on.
|
||||
|
||||
The OS brings immutable benefits, like keeping your system files safe. It also brings some drawbacks, like the need to reboot after adding system packages. Silverblue also enables new ways of working. If you want to explore new directions in the OS, find out if Silverblue brings benefits to your work.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/fedora-silverblue-brings-future-tech-to-the-desktop/
|
||||
|
||||
作者:[Nick Hardiman][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/nickhardiman/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2020/04/silverblue-introfordev-816x345.png
|
||||
[2]: https://silverblue.fedoraproject.org/
|
||||
[3]: https://fedoramagazine.org/what-is-silverblue/
|
||||
[4]: http://coreos.com/
|
||||
[5]: https://www.openshift.com/products/container-platform
|
||||
[6]: https://github.com/containers/libpod
|
||||
[7]: https://rpm-ostree.readthedocs.io/en/latest/
|
||||
[8]: https://docs.flatpak.org/en/latest/
|
||||
[9]: https://github.com/containers/toolbox
|
||||
[10]: https://fedoramagazine.org/pieces-of-fedora-silverblue/
|
||||
[11]: https://www.projectatomic.io/
|
||||
[12]: https://www.projectatomic.io/blog/2018/05/pinning-deployments-ostree-based-systems/
|
||||
[13]: https://fedoraproject.org/wiki/Anaconda
|
||||
[14]: https://www.gnome.org/
|
||||
[15]: https://fedoraproject.org/wiki/InitialSetup
|
||||
[16]: https://wiki.gnome.org/Apps/Builder
|
||||
[17]: https://www.eclipse.org/ide/
|
||||
[18]: http://www.codeblocks.org/
|
||||
[19]: https://www.npmjs.com/package/package
|
||||
[20]: https://rubygems.org/
|
||||
[21]: https://pypi.org/
|
||||
[22]: https://git-scm.com/
|
||||
[23]: https://discussion.fedoraproject.org/c/desktop/silverblue/6
|
||||
[24]: https://fedoramagazine.org/?s=silverblue
|
@ -0,0 +1,84 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (EU Parliament Strongly Recommends Developing and Using Open Source Software)
|
||||
[#]: via: (https://itsfoss.com/eu-parliament-recommends-open-source/)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
|
||||
EU Parliament Strongly Recommends Developing and Using Open Source Software
|
||||
======
|
||||
|
||||
Europe is choosing open source more than ever. Not just limited to [EU Commissions’ decision to use Signal messaging app][1] but also [open science][2] and the [adoption of open source software by European universities][3].
|
||||
|
||||
Now, in a recent [press release][4] by the [European Pirate Party][5], it looks like the EU Parliament is urging EU institutions to use open-source software. All thanks to the Pirate amendments for encouraging the use of open-source software.
|
||||
|
||||
The EU Parliament not just encourages the use of open-source software, but they have also advised to prioritize development of open-source software by the EU institutions.
|
||||
|
||||
So, not just aiming to adopt using open-source software but to develop open-source software. And, that’s definitely good news!
|
||||
|
||||
More use of open-source software, why not? To give you some more details, here’s what they mentioned in the press release:
|
||||
|
||||
> **In practice, from now on, all IT solutions developed by and for the EU institutions will first need to be assessed against the possibility of using Open Source solutions. Assessments will then have to be reported back to the Budgetary Control Committee of the Parliament on an annual basis, during the discharge procedure. This is a strong call for enhancing our important citizens right to transparent and trustworthy information.**
|
||||
|
||||
### Important decision to remove vendor lock-ins
|
||||
|
||||
![Public Money Public Code Campaign][6]
|
||||
|
||||
No matter who made this happen — this decision of preferring open-source software over proprietary will not just help the open-source community but also helps the EU institutions in a variety of ways.
|
||||
|
||||
Especially, relying on open-source software removes the overhead of vendor lock-ins. In other words, an EU institution does not have to rely on vendor to manage/maintain the software.
|
||||
|
||||
The press release also addressed this by mentioning:
|
||||
|
||||
> It is essential for the European institutions to retain control over its own technical systems, especially in a context of disinformation and foreign interference. Open Source promotes local technical support, leads to rapid development of software and helps to avoid dependency on specific suppliers or vendor lock-in effects, which exist when only one company is in charge of software or even the entire IT infrastructure supply.
|
||||
|
||||
Any responsible local organization can take up the task while the community can still help in any way it can. This could also reduce the cost of maintaining the software among other things like improving the security of a software in a collaborative manner.
|
||||
|
||||
### Is this a big win for open-source community?
|
||||
|
||||
![][7]
|
||||
|
||||
Yes, and no. We’ve seen a lot of recommendations made by the governments (or the EU government in general) to choose open-source software to keep things more secure yet transparent.
|
||||
|
||||
Pirate’s Vice-President of EU Parliament, **Marcel Kolaja**, mentions some advantages of this decision as well:
|
||||
|
||||
_It’s a milestone for transparent and open digitization of the European institutions. From now on, the Open Source ecosystem has a stepping ground for offering Open Source solutions and the Pirates will gladly play the role of the guardians and will try to solve and highlight any attempt to bypass this strong recommendation. It’s a really important step to remove vendor lock-ins in the Parliament“_
|
||||
|
||||
So, this will definitely help them earn trust of their citizens by providing digital transparency while also encouraging public participation to improve the software as well. Of course, this will also help introduce the concept of open-source software to many who were unaware of it in some way.
|
||||
|
||||
Also, ensuring open-source software for publicly financed software will enhance the meaning of freedom of speech/privacy/press.
|
||||
|
||||
In a nutshell, these decisions do have a positive impact in one way or the other.
|
||||
|
||||
But, the implementations of these decisions will decide how effective it’s going to be to put the words in action.
|
||||
|
||||
### Wrapping Up
|
||||
|
||||
I’m happy with the decision by EU Parliament here — even though I’m not a European. I guess, this should encourage other government bodies to take similar decisions or steps to ensure digital transparency while earning the trust of their citizens.
|
||||
|
||||
To get more details on the decision, you can refer to the [official press release by the European Pirate Party][4].
|
||||
|
||||
What do you think about it? Let me know your thoughts in the comments below!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/eu-parliament-recommends-open-source/
|
||||
|
||||
作者:[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://itsfoss.com/eu-commission-switches-to-signal/
|
||||
[2]: https://ec.europa.eu/research/openscience/index.cfm?pg=openaccess
|
||||
[3]: https://opensource.com/article/20/5/open-source-higher-education
|
||||
[4]: https://european-pirateparty.eu/european-parliament-strongly-recommends-any-software-developed-by-and-for-the-eu-institutions-to-be-made-publicly-available-under-free-and-open-source-software-licence/
|
||||
[5]: https://en.wikipedia.org/wiki/European_Pirate_Party
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/public-money-public-code.png?resize=800%2C420&ssl=1
|
||||
[7]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/05/eu-parliament-open-source.jpg?ssl=1
|
@ -0,0 +1,159 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Execute a Command or Script at Reboot or Startup)
|
||||
[#]: via: (https://www.2daygeek.com/execute-run-linux-scripts-command-at-reboot-startup/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
How to Execute a Command or Script at Reboot or Startup
|
||||
======
|
||||
|
||||
Well known services on Linux can be added on boot without any problems.
|
||||
|
||||
For example, if you want to add Apache Httpd **[service on boot][1]**, you can do this with the help of the chkconfig and systemctl command.
|
||||
|
||||
Sometimes you need to add a custom script or command or service on boot, and how to do it?
|
||||
|
||||
You can do this using the below three methods.
|
||||
|
||||
In this article, we will show you how to use these methods with examples.
|
||||
|
||||
### Method-1: How to Run Script or Command at Reboot or Startup Using /etc/rc.d/rc.local File
|
||||
|
||||
The **“/etc/rc.local”** file is traditionally executed after all normal computer services have been started at the end of the process of switching to a multiuser runlevel.
|
||||
|
||||
This method also works on the systemd system.
|
||||
|
||||
You need to add the location of your script to the “/etc/rc.d/rc.local” file to run on boot.
|
||||
|
||||
Make sure the file has permission to run.
|
||||
|
||||
```
|
||||
# chmod +x /etc/rc.d/rc.local
|
||||
```
|
||||
|
||||
To demonstrate this, we are going to create a simple sample script. You can create any script as needed.
|
||||
|
||||
```
|
||||
# vi /opt/scripts/run-script-on-boot.sh
|
||||
|
||||
#!/bin/bash
|
||||
date > /root/on-boot-output.txt
|
||||
hostname > /root/on-boot-output.txt
|
||||
```
|
||||
|
||||
Once the script is ready, set the executable permission.
|
||||
|
||||
```
|
||||
# chmod +x /opt/scripts/run-script-on-boot.sh
|
||||
```
|
||||
|
||||
Finally add the script to the bottom of the file.
|
||||
|
||||
```
|
||||
# vi /etc/rc.d/rc.local
|
||||
|
||||
/opt/scripts/run-script-on-boot.sh
|
||||
```
|
||||
|
||||
**[Restart your system][2]** to check this.
|
||||
|
||||
```
|
||||
# reboot
|
||||
```
|
||||
|
||||
### Method-2: How to Execute a Command or Script at Reboot or Startup Using the crontab
|
||||
|
||||
cron executes scheduled jobs automatically in the backend at a specific time.
|
||||
|
||||
This can be easily accomplished using a special string called **“@reboot”** with **[cron job][3]**.
|
||||
|
||||
@reboot is a special string and allows the user to run any command or script at startup (boot time).
|
||||
|
||||
This example runs the “/opt/scripts/run-script-on-boot.sh” file on the system restart.
|
||||
|
||||
We are going to use the same script as above.
|
||||
|
||||
To do so, just add the following entry in the crontab file.
|
||||
|
||||
```
|
||||
# crontab -e
|
||||
|
||||
@reboot /opt/scripts/run-script-on-boot.sh
|
||||
```
|
||||
|
||||
Restart your system to check this.
|
||||
|
||||
```
|
||||
# reboot
|
||||
```
|
||||
|
||||
### Method-3: How to Run a Command or Script at Reboot or Startup Using the systemd service unit
|
||||
|
||||
This method only works on the systemd system. This method is very straightforward.
|
||||
|
||||
We are going to use the same script above to demonstrate this.
|
||||
|
||||
To do so, you need to create a systemd startup script and place it in the **“/etc/systemd/system/”** directory.
|
||||
|
||||
This is our sample systemd startup unit script.
|
||||
|
||||
```
|
||||
# vi sample-on-boot-script.service
|
||||
|
||||
[Unit]
|
||||
Description=Run a Custom Script at Startup
|
||||
After=default.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/opt/scripts/run-script-on-boot.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
```
|
||||
|
||||
Once you place the unit script in the systemd location, run the following command to update the systemd configuration files and enable the service.
|
||||
|
||||
```
|
||||
# systemctl daemon-reload
|
||||
# systemctl enable sample-on-boot-script.service
|
||||
```
|
||||
|
||||
Restart your system to check this.
|
||||
|
||||
```
|
||||
# reboot
|
||||
```
|
||||
|
||||
### Bonus Tips:
|
||||
|
||||
If you want to run a script in the background, you need to add the trailing ampersand “&” symbol.
|
||||
|
||||
```
|
||||
/Path/To/My_Script &
|
||||
```
|
||||
|
||||
If you want to run the command as a different user, use the following format.
|
||||
|
||||
```
|
||||
su - $USER -c /Path/To/My_Script
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/execute-run-linux-scripts-command-at-reboot-startup/
|
||||
|
||||
作者:[Magesh Maruthamuthu][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/magesh/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.2daygeek.com/enable-disable-services-on-boot-linux-chkconfig-systemctl-command/
|
||||
[2]: https://www.2daygeek.com/6-commands-to-shutdown-halt-poweroff-reboot-the-linux-system/
|
||||
[3]: https://www.2daygeek.com/linux-crontab-cron-job-to-schedule-jobs-task/
|
@ -0,0 +1,314 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Manipulate an Ethernet Card Using the ethtool Command)
|
||||
[#]: via: (https://www.2daygeek.com/linux-ethtool-command-view-change-ethernet-adapter-settings-nic-card/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
How to Manipulate an Ethernet Card Using the ethtool Command
|
||||
======
|
||||
|
||||
Ethtool is used to view and modify network device driver parameters and hardware settings, especially for wired ethernet devices.
|
||||
|
||||
You can change ethernet card parameters as required, including auto-negotiation, Speed, Duplex and Wake-on LAN.
|
||||
|
||||
The configuration of your Ethernet card allows your computer to communicate effectively over the network.
|
||||
|
||||
This tool provides many information about Ethernet devices connected to your Linux system.
|
||||
|
||||
In this article, we will show you how to change the below parameters and how to view them.
|
||||
|
||||
This article will help you troubleshoot Ethernet card related problems on a Linux system.
|
||||
|
||||
The following information will help you understand how Ethernet card works.
|
||||
|
||||
* **Half Duplex:** Half-duplex mode allows a device to either send or receive packets at a time.
|
||||
* **Full Duplex:** Full-duplex mode allows a device to send and receive packets simultaneously.
|
||||
* **Auto-Negotiation:** Auto-negotiation is a mechanism that allows a device to automatically choose the best network speed and mode of operation (full-duplex or half-dual mode).
|
||||
* **Speed:** By default it uses maximum speed and you can change it according to your need.
|
||||
* **Link detection:** Link detection shows the status of the network interface card. If it shows “no” then try restarting the interface. If the link detection still says “no”, check if there are any issues with the cables connected between the switch and the system.
|
||||
|
||||
|
||||
|
||||
### How to Install ethtool on Linux
|
||||
|
||||
By default ethtool should already be installed on most systems. If not, you can install it from the distribution official repository.
|
||||
|
||||
For **RHEL/CentOS 6/7** systems, use the **[yum command][1]** to install ethtool.
|
||||
|
||||
```
|
||||
$ sudo yum install -y ethtool
|
||||
```
|
||||
|
||||
For **RHEL/CentOS 8** and **Fedora** systems, use the **[dnf command][2]** to install ethtool.
|
||||
|
||||
```
|
||||
$ sudo yum install -y ethtool
|
||||
```
|
||||
|
||||
For **Debian** based systems, use the **[apt command][3]** or **[apt-get command][4]** to install ethtool.
|
||||
|
||||
```
|
||||
$ sudo apt-get install ethtool
|
||||
```
|
||||
|
||||
For **openSUSE** systems, use the **[zypper command][5]** to install ethtool.
|
||||
|
||||
```
|
||||
$ sudo zypper install -y ethtool
|
||||
```
|
||||
|
||||
For **Arch Linux** systems, use the **[pacman command][6]** to install ethtool.
|
||||
|
||||
```
|
||||
$ sudo pacman -S ethtool
|
||||
```
|
||||
|
||||
### How to Check the Available Network Interface on Linux
|
||||
|
||||
You can use the **[ip command][7]** or the **ifconfig command** (deprecated in modern distribution) to verify the name and other details of the available and active network interfaces.
|
||||
|
||||
```
|
||||
# ip a
|
||||
or
|
||||
# ifconfig
|
||||
|
||||
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
|
||||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
||||
inet 127.0.0.1/8 scope host lo
|
||||
valid_lft forever preferred_lft forever
|
||||
2: eth0: mtu 1500 qdisc mq state UP group default qlen 1000
|
||||
link/ether 00:10:22:35:23:sf brd ff:ff:ff:ff:ff:ff
|
||||
inet 192.164.23.100/24 brd 192.164.23.255 scope global eth0
|
||||
valid_lft forever preferred_lft forever
|
||||
```
|
||||
|
||||
### How to Check Network Interface Card (NIC) Information on Linux
|
||||
|
||||
Once you have the Ethernet interface name, you can easily check the details of it using the ethtool command as shown below.
|
||||
|
||||
On Linux, each network interface card (NIC) is assigned unique names, such as ethX, enpXXX, and so on.
|
||||
|
||||
* The older Linux distribution used the **eth[X]** format. For example, RHEL 6 and their older versions.
|
||||
* Modern Linux distributions use **enp[XXX]** or **ens[XXX]** formats. For example, most of the modern Linux distribution uses this format, including RHEL 7, Debian 10, Ubuntu 16.04 LTS.
|
||||
|
||||
|
||||
|
||||
```
|
||||
# ethtool eth0
|
||||
|
||||
Settings for eth0:
|
||||
Supported ports: [ TP ]
|
||||
Supported link modes: 1000baseT/Full
|
||||
10000baseT/Full
|
||||
Supported pause frame use: No
|
||||
Supports auto-negotiation: No
|
||||
Supported FEC modes: Not reported
|
||||
Advertised link modes: Not reported
|
||||
Advertised pause frame use: No
|
||||
Advertised auto-negotiation: No
|
||||
Advertised FEC modes: Not reported
|
||||
Speed: 10000Mb/s
|
||||
Duplex: Full
|
||||
Port: Twisted Pair
|
||||
PHYAD: 0
|
||||
Transceiver: internal
|
||||
Auto-negotiation: off
|
||||
MDI-X: Unknown
|
||||
Supports Wake-on: uag
|
||||
Wake-on: d
|
||||
Link detected: yes
|
||||
```
|
||||
|
||||
### How to Check Ethernet Card Driver and Firmware Version on Linux
|
||||
|
||||
You can check driver version, firmware version, and bus details using the ethtool command with the **“-i”** option as shown below.
|
||||
|
||||
```
|
||||
# ethtool -i eth0
|
||||
|
||||
driver: vmxnet3
|
||||
version: 1.4.16.0-k-NAPI
|
||||
firmware-version:
|
||||
expansion-rom-version:
|
||||
bus-info: 0000:0b:00.0
|
||||
supports-statistics: yes
|
||||
supports-test: no
|
||||
supports-eeprom-access: no
|
||||
supports-register-dump: yes
|
||||
supports-priv-flags: no
|
||||
```
|
||||
|
||||
### How to Check Network Usage Statistics on Linux
|
||||
|
||||
You can view network usage statistics using the ethtool command with the **“-S”** option. It shows the bytes transferred, received, errors etc.
|
||||
|
||||
```
|
||||
# ethtool -S eth0
|
||||
|
||||
NIC statistics:
|
||||
Tx Queue#: 0
|
||||
TSO pkts tx: 2053
|
||||
TSO bytes tx: 7167572
|
||||
ucast pkts tx: 4028081
|
||||
ucast bytes tx: 399093197
|
||||
mcast pkts tx: 0
|
||||
mcast bytes tx: 0
|
||||
bcast pkts tx: 0
|
||||
bcast bytes tx: 0
|
||||
pkts tx err: 0
|
||||
pkts tx discard: 0
|
||||
drv dropped tx total: 0
|
||||
too many frags: 0
|
||||
giant hdr: 0
|
||||
hdr err: 0
|
||||
tso: 0
|
||||
ring full: 0
|
||||
pkts linearized: 0
|
||||
hdr cloned: 0
|
||||
giant hdr: 0
|
||||
Tx Queue#: 1
|
||||
TSO pkts tx: 1955
|
||||
TSO bytes tx: 6536945
|
||||
ucast pkts tx: 3711838
|
||||
ucast bytes tx: 346309662
|
||||
mcast pkts tx: 0
|
||||
mcast bytes tx: 0
|
||||
bcast pkts tx: 1186
|
||||
bcast bytes tx: 49812
|
||||
pkts tx err: 0
|
||||
pkts tx discard: 0
|
||||
drv dropped tx total: 0
|
||||
too many frags: 0
|
||||
giant hdr: 0
|
||||
hdr err: 0
|
||||
tso: 0
|
||||
ring full: 0
|
||||
pkts linearized: 0
|
||||
hdr cloned: 0
|
||||
giant hdr: 0
|
||||
Rx Queue#: 0
|
||||
LRO pkts rx: 0
|
||||
LRO byte rx: 0
|
||||
ucast pkts rx: 5084776
|
||||
ucast bytes rx: 4673133395
|
||||
mcast pkts rx: 0
|
||||
mcast bytes rx: 0
|
||||
bcast pkts rx: 154143
|
||||
bcast bytes rx: 45415676
|
||||
pkts rx OOB: 0
|
||||
pkts rx err: 0
|
||||
drv dropped rx total: 0
|
||||
err: 0
|
||||
fcs: 0
|
||||
rx buf alloc fail: 0
|
||||
Rx Queue#: 1
|
||||
LRO pkts rx: 0
|
||||
LRO byte rx: 0
|
||||
ucast pkts rx: 6346769
|
||||
ucast bytes rx: 4835534292
|
||||
mcast pkts rx: 0
|
||||
mcast bytes rx: 0
|
||||
bcast pkts rx: 3464
|
||||
bcast bytes rx: 714646
|
||||
pkts rx OOB: 0
|
||||
pkts rx err: 0
|
||||
drv dropped rx total: 0
|
||||
err: 0
|
||||
fcs: 0
|
||||
rx buf alloc fail: 0
|
||||
tx timeout count: 0
|
||||
```
|
||||
|
||||
### How to Change the Speed of Ethernet Device on Linux
|
||||
|
||||
You can change the speed of the Ethernet as needed. When you make this change the interface will automatically go offline and you will need to bring it back online using the **[ifup command][8]** or the ip command or the nmcli command.
|
||||
|
||||
```
|
||||
# ethtool -s eth0 speed 100
|
||||
# ip link set eth0 up
|
||||
```
|
||||
|
||||
### How to Enable/Disable Auto-Negotiation for Ethernet Device on Linux
|
||||
|
||||
You can enable or disable Auto-Negotiation using the ethtool command with the **“autoneg”** option as shown below.
|
||||
|
||||
```
|
||||
# ethtool -s eth0 autoneg off
|
||||
# ethtool -s eth0 autoneg on
|
||||
```
|
||||
|
||||
### How to Change Multiple Parameters at Once
|
||||
|
||||
If you want to change multiple parameters of the Ethernet interface simultaneously using the ethtool command, use the format below.
|
||||
|
||||
```
|
||||
Syntax:
|
||||
ethtool –s [device_name] speed [10/100/1000] duplex [half/full] autoneg [on/off]
|
||||
```
|
||||
|
||||
```
|
||||
# ethtool –s eth0 speed 1000 duplex full autoneg off
|
||||
```
|
||||
|
||||
### How to Check Auto-negotiation, RX and TX of a Particular Interface on Linux
|
||||
|
||||
To view auto-negotiation details about a specific Ethernet device, use the below format.
|
||||
|
||||
```
|
||||
# ethtool -a eth0
|
||||
```
|
||||
|
||||
### How to Identify a Specific NIC from Multiple Devices (Blink LED Port of NIC Card)
|
||||
|
||||
This option is very useful if you want to identify a specific physical interface port among others. The below ethtool command blink the LED of the eth0 port.
|
||||
|
||||
```
|
||||
# ethtool -p eth0
|
||||
```
|
||||
|
||||
### How to Set These Parameters in Linux Permanently
|
||||
|
||||
After a system restarts the changes you made with ethtool will be reverted by default.
|
||||
|
||||
To make custom settings permanent, you need to update your value in the network configuration file. Depending on your Linux distribution you may need to update this value to the correct file.
|
||||
|
||||
For RHEL based systems. You must use the ETHTOOL_OPTS variables.
|
||||
|
||||
```
|
||||
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
|
||||
|
||||
ETHTOOL_OPTS="speed 1000 duplex full autoneg off"
|
||||
```
|
||||
|
||||
For **Debian** based systems.
|
||||
|
||||
```
|
||||
# vi /etc/network/interfaces
|
||||
|
||||
post-up ethtool -s eth0 speed 1000 duplex full autoneg off
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/linux-ethtool-command-view-change-ethernet-adapter-settings-nic-card/
|
||||
|
||||
作者:[Magesh Maruthamuthu][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/magesh/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.2daygeek.com/linux-yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[2]: https://www.2daygeek.com/linux-dnf-command-examples-manage-packages-fedora-centos-rhel-systems/
|
||||
[3]: https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[4]: https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[5]: https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[6]: https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/
|
||||
[7]: https://www.2daygeek.com/ip-command-configure-network-interface-usage-linux/
|
||||
[8]: https://www.2daygeek.com/enable-disable-up-down-nic-network-interface-port-linux-using-ifconfig-ifdown-ifup-ip-nmcli-nmtui/
|
@ -0,0 +1,139 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Properly Install and Setup KDE Plasma on Arch Linux)
|
||||
[#]: via: (https://itsfoss.com/install-kde-arch-linux/)
|
||||
[#]: author: (Dimitrios Savvopoulos https://itsfoss.com/author/dimitrios/)
|
||||
|
||||
How to Properly Install and Setup KDE Plasma on Arch Linux
|
||||
======
|
||||
|
||||
I believe you followed the [fantastic It’s FOSS guide on installing Arch Linux][1]. The guide ends with steps mentioning the installation procedure for [GNOME desktop][2].
|
||||
|
||||
Now, not everyone is a GNOME fan and several readers requested that we show them how to configure the [KDE desktop][3] on [Arch Linux][4].
|
||||
|
||||
And thus I created this guide to demonstrate the steps for properly installing and configuring KDE desktop (also known as KDE Plasma desktop) on Arch Linux.
|
||||
|
||||
### How to install and setup KDE desktop environment on Arch Linux
|
||||
|
||||
![][5]
|
||||
|
||||
Please keep in mind that KDE doesn’t allow login as root directly. If you have installed Arch Linux and using it as root, you should create a new user and give it sudo rights for running commands as root.
|
||||
|
||||
If you just have a bare minimum installation of Arch Linux, you probably are logging into a TTY terminal. If you are using some other desktop environment, steps remain the same.
|
||||
|
||||
Let’s go!
|
||||
|
||||
#### Step 1: Create a sudo user (if you have only root user)
|
||||
|
||||
You can use the [useradd command][6] for creating a new user. I am creating user named dimitrios (that’s my name). You can use something that matches your name.
|
||||
|
||||
The option -m creates a home directory for the newly created user.
|
||||
|
||||
```
|
||||
useradd -m dimitrios
|
||||
```
|
||||
|
||||
You should also set a password for this user. Use this command:
|
||||
|
||||
```
|
||||
passwd dimitrios
|
||||
```
|
||||
|
||||
Now that you have created the user, give it sudo access. First, install sudo and a [command line text editor][7] like [nano][8]:
|
||||
|
||||
```
|
||||
pacman -S sudo nano
|
||||
```
|
||||
|
||||
The configuration file for sudo is /etc/sudoers. It should always be edited with the visudo command. visudo locks the sudoers file, saves edits to a temporary file, and checks that file’s grammar before copying it to /etc/sudoers.
|
||||
|
||||
To use nano as the visudo editor, use:
|
||||
|
||||
```
|
||||
EDITOR=nano visudo
|
||||
```
|
||||
|
||||
Add the following line like I do in the example, then save and exit.
|
||||
|
||||
```
|
||||
dimitrios ALL=(ALL) ALL
|
||||
```
|
||||
|
||||
![Adding Sudoer in Arch Linux][9]
|
||||
|
||||
Save your changes and exit the editor. You now have a sudo user on Arch Linux.
|
||||
|
||||
#### Step 2: Installing KDE Plasma desktop
|
||||
|
||||
To run KDE desktop, you need the following packages:
|
||||
|
||||
* [Xorg][10] group
|
||||
* [KDE Plasma][3] Desktop Environment
|
||||
* [Wayland][11] session for KDE Plasma
|
||||
* [KDE applications][12] group (consists of KDE specific applications including the Dolphin manager and other useful apps)
|
||||
|
||||
|
||||
|
||||
You can install of the above using the following command:
|
||||
|
||||
```
|
||||
pacman -S xorg plasma plasma-wayland-session kde-applications
|
||||
```
|
||||
|
||||
Once installed, enable the Display Manager and Network Manager services:
|
||||
|
||||
```
|
||||
systemctl enable sddm.service
|
||||
systemctl enable NetworkManager.service
|
||||
```
|
||||
|
||||
Almost there. Shutdown your system:
|
||||
|
||||
```
|
||||
shutdown now
|
||||
```
|
||||
|
||||
Power on your system and you should see the KDE login. Do you remember the password you set up for your sudo user? Use it to login.
|
||||
|
||||
![Arch KDE Plasma Desktop][13]
|
||||
|
||||
#### What next?
|
||||
|
||||
You may want to explore the [essential pacman commands][14], to know what’s going on with the [Arch User Repository][15] and learn more about [AUR helpers][16].
|
||||
|
||||
I hope you found this tutorial helpful in installing KDE desktop on Arch Linux. Please let us know in the comments below, if you encountered any obstacle or difficulty during the installation.
|
||||
|
||||
What’s your favourite Desktop environment or Window Manager? Let us know and don’t forget to subscribe on our social media.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/install-kde-arch-linux/
|
||||
|
||||
作者:[Dimitrios Savvopoulos][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/dimitrios/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/install-arch-linux/
|
||||
[2]: https://www.gnome.org/
|
||||
[3]: https://kde.org/plasma-desktop
|
||||
[4]: https://www.archlinux.org/
|
||||
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/install-kde-arch-linux.png?ssl=1
|
||||
[6]: https://linuxhandbook.com/useradd-command/
|
||||
[7]: https://itsfoss.com/command-line-text-editors-linux/
|
||||
[8]: https://www.nano-editor.org/
|
||||
[9]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/05/adding-sudoer-arch-linux.png?ssl=1
|
||||
[10]: https://wiki.archlinux.org/index.php/Xorg
|
||||
[11]: https://wiki.archlinux.org/index.php/Wayland
|
||||
[12]: https://www.archlinux.org/groups/x86_64/kde-applications/
|
||||
[13]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/05/Arch-Plasma-desktop.jpg?fit=800%2C450&ssl=1
|
||||
[14]: https://itsfoss.com/pacman-command/
|
||||
[15]: https://itsfoss.com/aur-arch-linux/
|
||||
[16]: https://itsfoss.com/best-aur-helpers/
|
@ -0,0 +1,198 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Remove Files Older than N Days Using Tmpwatch/Tmpreaper on Linux)
|
||||
[#]: via: (https://www.2daygeek.com/how-to-remove-files-older-than-n-days-using-tmpwatch-tmpreaper-on-linux/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
How to Remove Files Older than N Days Using Tmpwatch/Tmpreaper on Linux
|
||||
======
|
||||
|
||||
You may have missed deleting files that are no longer needed on your computer in some directory.
|
||||
|
||||
This can be “Download” or any other directory.
|
||||
|
||||
It may have grown up over a period of time.
|
||||
|
||||
If you have enough storage, you should remove them, as this will slow down your system when you list files.
|
||||
|
||||
Also, it can be clumsy when you have thousands of files in one directory.
|
||||
|
||||
It is very difficult to find a file in a specific directory when you do not know the file name you want to check.
|
||||
|
||||
We can do this by using the find command with some combination, and we have written an article about this in the past.
|
||||
|
||||
* [**Bash Script to Delete Files/Folders Older Than “X” Days in Linux**][1]
|
||||
* [**How To Find And Delete Files Older Than “X” Days And “X” Hours In Linux?**][1]
|
||||
* [**How To Automatically Delete Or Clean Up /tmp Folder Contents In Linux?**][1]
|
||||
|
||||
|
||||
|
||||
Today we are going to show you how to achieve this using the Tmpwatch utility on Linux.
|
||||
|
||||
### What is Tmpwatch
|
||||
|
||||
Tmpwatch recursively removes files that have not been accessed for a specified period of time in the specified directories.
|
||||
|
||||
Typically, it is used to automatically clean directories used for temporary file systems, such as / tmp and /var/tmp.
|
||||
|
||||
It only remove empty directories, regular files, and symbolic links.
|
||||
|
||||
It doesn’t switch to other file systems, and avoids the “lost+found” directory belonging to the root user.
|
||||
|
||||
By default, tmpwatch deletes files based on their atime (access time), not their mtime (conversion time).
|
||||
|
||||
You can change this behavior by adding other parameters in the tmpwatch command.
|
||||
|
||||
**WARNING:** Please do not run “tmpwatch” or “tmpreaper” in “/” because there is no mechanism in the program to protect against this.
|
||||
|
||||
### How to Install Tmpwatch on Linux
|
||||
|
||||
Tmpwatch can be installed as follows from the distribution official repository.
|
||||
|
||||
For **RHEL/CentOS 6** systems, use the **[yum command][2]** to install Tmpwatch.
|
||||
|
||||
```
|
||||
$ sudo yum install -y tmpwatch
|
||||
```
|
||||
|
||||
For **Debian** and **Ubuntu** systems, use the **[apt command][3]** or **[apt-get command][4]** to install Tmpreaper.
|
||||
|
||||
```
|
||||
$ sudo apt-get install tmpreaper
|
||||
```
|
||||
|
||||
For **openSUSE** systems, use the **[zypper command][5]** to install Tmpwatch.
|
||||
|
||||
```
|
||||
$ sudo zypper install -y tmpwatch
|
||||
```
|
||||
|
||||
For **Fedora** systems, use the **[dnf command][6]** to install Tmpwatch.
|
||||
|
||||
```
|
||||
$ sudo dnf install -y tmpwatch
|
||||
```
|
||||
|
||||
**Make a note:** If you are using Debian-based systems, use “tmpreaper” instead of tmpwatch. All examples will work as expected.
|
||||
|
||||
### Understanding Key Options and Arguments
|
||||
|
||||
* **atime** (File Last Access Time) – Access time shows the last time the data from a file was accessed by any of the process such as command or script, etc,.
|
||||
* **mtime** (File Last Modify Time) – mtime shows when you modify a file contents or save a file. Most of the times ctime and mtime will be the same, unless the file attributes are updated.
|
||||
* **ctime** (File Last Change Time) – ctime shows when your file metadata got changed. It means when the file attributes are changed like ownership or group, etc,.
|
||||
* **dirmtime** (Directory Last modification time) – dirmtime shows when your directory last modified.
|
||||
|
||||
|
||||
|
||||
The time parameter defines the threshold for removing files.
|
||||
|
||||
* d – for days
|
||||
* h – for hours
|
||||
* m – for minutes
|
||||
* s – for seconds
|
||||
|
||||
|
||||
|
||||
### How to Removes Files That Haven’t Been Accessed for a Period of Time Using the Tmpwatch Command
|
||||
|
||||
As I said at the beginning of the article, Tmpwatch deletes files by default (atime) depending on the time of access to the files. Also, since hours are the default parameter, you do not need to add the suffix to time if the action is performed using the hour unit.
|
||||
|
||||
For example, run the command below to recursively remove files that have not been accessed for the past 5 hours.
|
||||
|
||||
```
|
||||
# tmpwatch 5 /tmp
|
||||
```
|
||||
|
||||
Run the command below to delete files that have not been modified for the last 10 hours. If you want to delete files using mtime, you need to add the “-m” option with the tmpwatch command.
|
||||
|
||||
```
|
||||
# tmpwatch -m 10 /home/daygeek/Downloads
|
||||
```
|
||||
|
||||
### How to Delete Files That Haven’t Been Accessed more than “X” Days Using the Tmpwatch Command
|
||||
|
||||
If you want to delete files using days, you need to add the suffix “d”. The example below deletes files older than 30 days.
|
||||
|
||||
```
|
||||
# tmpwatch 30d /home/daygeek/Downloads
|
||||
```
|
||||
|
||||
### How to Delete All Files That Haven’t Been Accessed for a Period of Time Using the Tmpwatch Command
|
||||
|
||||
The below command removes all file types, not just regular files, symbolic links and directories based on mtime.
|
||||
|
||||
```
|
||||
# tmpwatch -am 12 /tmp
|
||||
```
|
||||
|
||||
### How to Exclude a Directory with Tmpwatch
|
||||
|
||||
The below command will delete all files and excludes directories that haven’t been modified for the past 10 hours.
|
||||
|
||||
```
|
||||
# tmpwatch -am 10 --nodirs /home/daygeek/Downloads
|
||||
```
|
||||
|
||||
### How to Exclude a Specific Path with Tmpwatch
|
||||
|
||||
The command below will delete all files except the directory below which has not been modified for the past 10 hours.
|
||||
|
||||
```
|
||||
# tmpwatch -am 10 --exclude=/home/daygeek/Downloads/Movies /home/daygeek/Downloads
|
||||
```
|
||||
|
||||
### How to Exclude Specific Pattern with Tmpwatch
|
||||
|
||||
The command below will delete all files except the Pattern below which has not been modified for the past 10 hours.
|
||||
|
||||
```
|
||||
# tmpwatch -am 10 --exclude-pattern='*.pdf' /home/daygeek/Downloads
|
||||
```
|
||||
|
||||
### How to Perform Dry Run with Tmpwatch Command
|
||||
|
||||
Run the below command if you want to perform dry run.
|
||||
|
||||
```
|
||||
# tmpwatch -t 5h /home/daygeek/Downloads
|
||||
```
|
||||
|
||||
### How to Setup a Cronjob to Delete files Periodically Using Tmpwatch
|
||||
|
||||
By default it leaves a **[cronjob][7]** file under the **“/etc/cron.daily/tmpreaper”** directory. This cronjob works according to the configuration file located in **“/etc/timereaper.conf”**. You can customize the file according to your needs.
|
||||
|
||||
It runs once a day and deletes files older than 7 days.
|
||||
|
||||
Alternatively, if you would like to perform an action routinely, you can manually add a conjob based on your needs.
|
||||
|
||||
```
|
||||
# crontab -e
|
||||
|
||||
0 10 * * * /usr/sbin/tmpwatch 15d /home/daygeek/Downloads
|
||||
```
|
||||
|
||||
The above cronjob will delete files that are older than 15 days daily at 10AM.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/how-to-remove-files-older-than-n-days-using-tmpwatch-tmpreaper-on-linux/
|
||||
|
||||
作者:[Magesh Maruthamuthu][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/magesh/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.2daygeek.com/bash-script-to-delete-files-folders-older-than-x-days-in-linux/
|
||||
[2]: https://www.2daygeek.com/linux-yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[3]: https://www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[4]: https://www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/
|
||||
[5]: https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[6]: https://www.2daygeek.com/linux-dnf-command-examples-manage-packages-fedora-centos-rhel-systems/
|
||||
[7]: https://www.2daygeek.com/linux-crontab-cron-job-to-schedule-jobs-task/
|
@ -0,0 +1,155 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (LanguageTool Review: Free and Open Source Grammar Checker)
|
||||
[#]: via: (https://itsfoss.com/languagetool-review/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
LanguageTool Review: Free and Open Source Grammar Checker
|
||||
======
|
||||
|
||||
This week’s open source software highlight is [LanguageTool][1]. It is a proofreading software that checks the grammar, style and spelling in more than 20 languages.
|
||||
|
||||
I have been using it for past several days and I feel confident enough to review it and share my experience with it. I have used the popular proofreading tool [Grammarly][2] in the past and I’ll make some comparison between these two tools.
|
||||
|
||||
### LanguageTool: Open source proofreading software
|
||||
|
||||
![][3]
|
||||
|
||||
[LanguageTool][1] grammar checker is available in [multiple formats][4]:
|
||||
|
||||
* You can copy-paste your text on its website.
|
||||
* You can install browser extension that will check for errors as you type anything, anywhere in the web browser.
|
||||
* You can install a Java-based desktop application for offline usage.
|
||||
* You can install add-on for LibreOffice and MS Office.
|
||||
* Add-ons are also [available for a number of other software][5] like Sublime Text, Thunderbird, Vim, Visual Studio Code etc.
|
||||
* [Android app][6] is also available.
|
||||
* API is also available if you want to use LanguageTool in your software or service. API offering comes under premium services.
|
||||
|
||||
|
||||
|
||||
You can find source code of LanguageTool and its related assets on [their GitHub repository][7].
|
||||
|
||||
[LanguageTool also has a premium version][8] that you can purchase. The premium version offers additional error checks.
|
||||
|
||||
I am using LanguageTool premium version as a browser extension. Almost all the writing I do is online and thus the browser extension is perfect for me.
|
||||
|
||||
The most convenient way to try LanguageTool is by using its browser extension. Install the browser add-on and next time you type anything in the browser, LanguageTool will start checking your text for grammatical and spelling errors. It will also check for styling errors.
|
||||
|
||||
### Experience with LanguageTool: How good is it?
|
||||
|
||||
LanguageTool leaves a good first impression. It starts checking for errors as you start typing.
|
||||
|
||||
Different types of errors have different color codes. Spelling mistakes are highlighted in red color, grammatical mistakes are in yellow colors and styling errors have a blueish shade.
|
||||
|
||||
Clicking on the error suggestion replaces your text with the suggested one. You may also ignore the suggestion. You’ll also see number of issues identified by LanguageTool in the current text check.
|
||||
|
||||
![Spelling mistake identified by LanguageTool][9]
|
||||
|
||||
#### Personal dictionary
|
||||
|
||||
You can also create your personal directory and add words in it. This is helpful because no proofreading tool can give a green light to technical terms like systemd, iptables and brand names like [WireGuard][10]. To avoid these words labeled as spelling mistakes, add them to your personal dictionary.
|
||||
|
||||
You may edit your personal dictionary from your LanguageTool account.
|
||||
|
||||
![LanguageTool Personal Dictionary][11]
|
||||
|
||||
#### Details on the error suggestion
|
||||
|
||||
If it finds grammatical errors, it also gives a quick explanation of the error. You can get more details by clicking the tool tip which takes you to a reputable external source.
|
||||
|
||||
![You can get additional details on the errors][12]
|
||||
|
||||
#### Synonym suggestion (in beta)
|
||||
|
||||
If you double-click on a word, it will also suggest synonyms.
|
||||
|
||||
![][13]
|
||||
|
||||
#### Are there any privacy issues?
|
||||
|
||||
If you use the online services of LanguageTool, your text is sent to their servers over an **encrypted** connection. All their servers are hosted at Hetzner Online GmbH in Germany.
|
||||
|
||||
LanguageTool states that it doesn’t store any text that you check using its services. You can read their privacy policy [here][14].
|
||||
|
||||
The free to use languagetool.org website shows ads (there are no third-party ads in the browser add-on). To test their claim of “sending text over an encrypted server”, I typed sample text containing words like vacuum cleaner, laptop etc.
|
||||
|
||||
Thankfully, the displayed ad on their website was nothing related to the text I typed. I haven’t noticed any vacuum cleaner ads on the websites I visit or on Facebook. That’s a good thing.
|
||||
|
||||
#### It doesn’t work flawlessly all the time
|
||||
|
||||
No software is perfect and LanguageTool is not an exception. While it is helpful in finding obvious spelling and grammatical mistakes, it struggles in some simple scenario.
|
||||
|
||||
For example, if a sentence contains several blank spaces together, LanguageTool failed to find an issue with that.
|
||||
|
||||
![Too many whitespaces and yet it went undetected][15]
|
||||
|
||||
This is weird because if I look at their ‘error rules’, I can see a [whitespace repetition rule][16]. I think this rule is applicable only for the Java-based LanguageTool apps, not the browser add-on I am using.
|
||||
|
||||
I also found some other cases where LanguageTool should have identified errors but it didn’t. For example, it didn’t alert for the missing ‘to’ in the text below:
|
||||
|
||||
![LanguageTool fails to find the missing “to”][17]
|
||||
|
||||
When I checked it against the [Grammarly free version][2], it was able to point it out.
|
||||
|
||||
![Grammarly was quick to identify it][18]
|
||||
|
||||
I also found an infinite loop of suggestion. It first suggests using syntaxes as plural of syntax.
|
||||
|
||||
![Suggestion for using ‘syntaxes’][19]
|
||||
|
||||
And then it doesn’t accept ‘syntaxes’ as a valid word.
|
||||
|
||||
![And then it doesn’t accept ‘syntaxes’][20]
|
||||
|
||||
I have seen such “infinite error loop” with Grammarly as well in the past, so I won’t be too hard on LanguageTool for such issues.
|
||||
|
||||
### Conclusion
|
||||
|
||||
Despite some hiccups, I am satisfied with LanguageTool proofreading tool. Both free and premium version are good enough for finding obvious spelling mistakes and grammatical errors.
|
||||
|
||||
The premium version offers over 2500 additional error checks and it costs around $15-$70 per year depending on your geographical region. This is a lot cheaper than [Grammarly][2] which costs $140 per year.
|
||||
|
||||
I opted for the premium version because it will help this open-source project. Premium users also get email support.
|
||||
|
||||
You are not forced to go premium, of course. You can use the free version and if you have some questions or need support, there is a [community forum][21] that you can join for free.
|
||||
|
||||
LanguageTool can certainly be considered one of the [essential open-source tools for writers][22]. I am going to continue using LanguageTool. If you find grammatical or spelling mistakes in It’s FOSS articles in the future, blame LanguageTool, not me. Just kidding :)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/languagetool-review/
|
||||
|
||||
作者:[Abhishek Prakash][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/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://languagetool.org/
|
||||
[2]: https://itsfoss.com/recommends/grammarly/
|
||||
[3]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/05/languagetool.png?fit=800%2C593&ssl=1
|
||||
[4]: https://languagetool.org/compare
|
||||
[5]: http://wiki.languagetool.org/software-that-supports-languagetool-as-a-plug-in-or-add-on
|
||||
[6]: https://play.google.com/store/apps/details?id=org.softcatala.corrector
|
||||
[7]: https://github.com/languagetool-org/
|
||||
[8]: https://languagetoolplus.com/
|
||||
[9]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/05/langaugetool-error-detection.png?ssl=1
|
||||
[10]: https://itsfoss.com/wireguard/
|
||||
[11]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/05/languagetool-personal-dictionary.png?ssl=1
|
||||
[12]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/languagetool-error-explanation.png?ssl=1
|
||||
[13]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/05/languagetool-synonym-suggestion.png?ssl=1
|
||||
[14]: https://languagetoolplus.com/legal/privacy
|
||||
[15]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/languagetool-whitespaces.png?ssl=1
|
||||
[16]: https://community.languagetool.org/rule/show/WHITESPACE_RULE?lang=en
|
||||
[17]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/05/languagetool-suggestion-3.jpg?fit=800%2C219&ssl=1
|
||||
[18]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/05/languagetool-suggestion-grammarly.jpg?fit=800%2C272&ssl=1
|
||||
[19]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/languagetool-suggestion.png?ssl=1
|
||||
[20]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/05/languagetool-suggestion-1.png?ssl=1
|
||||
[21]: https://forum.languagetool.org/
|
||||
[22]: https://itsfoss.com/open-source-tools-writers/
|
@ -1,103 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (lnrCoder)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Now You Can Run Linux Apps in Windows (Thanks to WSL))
|
||||
[#]: via: (https://itsfoss.com/run-linux-apps-windows-wsl/)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
|
||||
Now You Can Run Linux Apps in Windows (Thanks to WSL)
|
||||
======
|
||||
|
||||
Microsoft’s recent “[Build 2020][1]” developer conference involved some interesting announcements. I’m not sure if it’s something to be excited about or skeptical about — but Microsoft you have our attention now more than ever.
|
||||
|
||||
And, among all the announcements, the ability to run GUI apps on WSL (Windows Subsystem for Linux) gained the spotlight.
|
||||
|
||||
Not to forget the [fiasco with Xamrin.Forms rebranding as MAUI][2] which conflicts with an existing open-source project ([Maui Project][3]) by Uri Herrera of [Nitrux Linux.][4]
|
||||
|
||||
In case you didn’t know, WSL is an environment that lets you have a console-only Linux experience from within Windows 10. It is also one of the [best ways to run Linux commands in Windows.][5]
|
||||
|
||||
While the announcement through a blog post ([DirectX ❤ Linux][6]) may have been a PR bait as [Liam Dawe thinks][7]. But, it’s still something worth talking about.
|
||||
|
||||
### Support for Linux GUI Apps On WSL
|
||||
|
||||
![][8]
|
||||
|
||||
Recently, Microsoft announced a bunch of new features coming to WSL (a.k.a. WSL 2) during the online developer conference.
|
||||
|
||||
The introduction of [Windows Package Manager][9], [Windows Terminal 1.0][10], and a couple others were some its highlights.
|
||||
|
||||
But, the support for GPU hardware acceleration to **Windows Subsystem for Linux 2** was something significant.
|
||||
|
||||
So, does this mean that you can run Linux apps on Windows using WSL? Looks like it…
|
||||
|
||||
Microsoft plans to make it happen using a brand-new Linux kernel driver **dxgkrnl**. To give you a technical brief, I’d quote the description from their announcement here:
|
||||
|
||||
![Linux Kernel Driver Wsl][11]
|
||||
|
||||
> Dxgkrnl is a brand-new kernel driver for Linux that exposes the **/dev/dxg** device to user mode Linux. **/dev/dxg** exposes a set of IOCTL that closely mimic the native WDDM D3DKMT kernel service layer on Windows. Dxgkrnl inside the Linux kernel connects over the VM Bus to its big brother on the Windows host and uses this VM bus connection to communicate with the physical GPU.
|
||||
|
||||
I’m no expert here but it means that the **Linux applications on WSL will have the same access to the GPU as native Windows applications do**.
|
||||
|
||||
The support for GUI apps will be coming later this fall (not with May 2020 update) — so we’ll have to see when that happens.
|
||||
|
||||
Microsoft is specifically targeting the developers who want the comfort of using their Linux IDE on Windows. Google is also targeting the same user base by [bringing GUI Linux apps to Chromebook][12].
|
||||
|
||||
Well, that’s good news for users who want to stick with Windows. But, is it really?
|
||||
|
||||
### Microsoft Loves Linux — Do They Really?
|
||||
|
||||
![Microsoft Loves Linux][13]
|
||||
|
||||
It is definitely a good thing that they are embracing Linux and its benefits through their efforts of incorporating a Linux environment on Windows.
|
||||
|
||||
But, how is it really going to help the **desktop Linux users**? I don’t see any real-word benefits from it as of now.
|
||||
|
||||
You’re free to have a different opinion here. But, I think there’s no real value to the desktop users of Linux through the development of WSL. At least, none so far.
|
||||
|
||||
It was interesting to notice that someone on [Linux Unplugged podcast][14] highlighted Microsoft’s move as something in the line of EEE (Embrace, extend, and extinguish) for which they’re known for.
|
||||
|
||||
Maybe, who knows? Of course, the effort they’ve put to pull this off is worth appreciating — but it’s exciting and mystifying at the same time.
|
||||
|
||||
### Does this mean Windows users will no longer switch to Linux?
|
||||
|
||||
The reason why Microsoft is embracing Linux on its platform is that they know what it’s capable of and why developers (or users) prefer using.
|
||||
|
||||
But, with the updates to WSL 2, I tend to agree to what Abhishek thinks if this continues:
|
||||
|
||||
> Eventually, desktop Linux will be confined to become a desktop application under Windows…
|
||||
|
||||
Well, of course, the native experience is still superior for the time being. And, it’ll be rare to see that the existing Linux desktop users will use Windows over it. But, that’s still something to worry about.
|
||||
|
||||
What do you think about all this? I’m not ruling the advantages of WSL for users forced to use Windows — but do you think Microsoft’s progress with WSL is going to be something hostile in nature or something that will help Linux in the long run?
|
||||
|
||||
Let me know your thoughts in the comments!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/run-linux-apps-windows-wsl/
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[lnrCoder](https://github.com/lnrCoder)
|
||||
校对:[校对者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://news.microsoft.com/build2020/
|
||||
[2]: https://itsfoss.com/microsoft-maui-kde-row/
|
||||
[3]: https://mauikit.org/
|
||||
[4]: https://itsfoss.com/nitrux-linux/
|
||||
[5]: https://itsfoss.com/run-linux-commands-in-windows/
|
||||
[6]: https://devblogs.microsoft.com/directx/directx-heart-linux/
|
||||
[7]: https://www.gamingonlinux.com/2020/05/microsoft-build-directx-and-linux-plus-more
|
||||
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/Linux-GUI-app-Windows-WSL.png?ssl=1
|
||||
[9]: https://devblogs.microsoft.com/commandline/windows-package-manager-preview/
|
||||
[10]: https://devblogs.microsoft.com/commandline/windows-terminal-1-0/
|
||||
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/linux-kernel-driver-wsl.png?ssl=1
|
||||
[12]: https://itsfoss.com/linux-apps-chromebook/
|
||||
[13]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/microsoft-loves-linux.jpg?ssl=1
|
||||
[14]: https://linuxunplugged.com/354
|
@ -1,179 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (3 Python templating languages you should (probably) never use)
|
||||
[#]: via: (https://opensource.com/article/20/4/python-templating-languages)
|
||||
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
|
||||
|
||||
你应该(或许)没使用过的 3 种 Python 模板语言
|
||||
======
|
||||
Python 积累了许多模板语言,包括这 3 个适合在愚人节介绍的模板语言
|
||||
![Hands on a keyboard with a Python book ][1]
|
||||
|
||||
当使用一种模板语言来编写 [Python][2] Web 应用时,它有很多健壮的解决方案。
|
||||
|
||||
有 [Jinja2][3]、[Genshi 和 Mako][4]。甚至还有 [Chameleon][5] 之类的解决方案,虽然有些陈旧,但仍被 [Pyramid][6] 框架推荐。
|
||||
|
||||
Python 已经存在了很长时间。此时,在系统的深处,它积累了一些几乎被遗忘的模板语言,它们都是值得一试的。
|
||||
|
||||
就像桉树顶上的可爱考拉一样,在它们的生态位中不错,有时用它们工作会危险,这些都是很少有人听说过的模板语言,使用过的应该更少。
|
||||
|
||||
### 3\. string.Template
|
||||
|
||||
你是否曾经想过:“如何获得一种没有任何特性但同时也不需要 **pip install** 的模板语言?” Python 标准库已经涵盖。虽然没有循环和条件,但 **string.Template** 类是一种最小的模板语言。
|
||||
|
||||
使用它很简单。
|
||||
|
||||
|
||||
```
|
||||
>>> import string
|
||||
>>> greeting = string.Template("Hello, $name, good $time!")
|
||||
>>> greeting.substitute(name="OpenSource.com", time="afternoon")
|
||||
'Hello, OpenSource.com, good afternoon!'
|
||||
```
|
||||
|
||||
### 2\. twisted.web.template
|
||||
|
||||
你会给一个有所有东西的库什么礼物?
|
||||
|
||||
当然,它不是一种模板语言,因为已经有一种。 嵌套在 twisted.web.template 中的是两种模板语言。 一种是基于 XML 的,并有一个[很棒的文档][7]。
|
||||
|
||||
但是还有另一种,一种基于使用 Python 作为领域特定语言来生成 HTML 文档。
|
||||
|
||||
它基于两个原语:包含标签对象的 **twisted.web.template.tags** 和渲染它们的 **twisted.web.template.flattenString**。由于它是 Twisted 的一部分,因此它内置支持高效异步渲染。
|
||||
|
||||
此例将渲染一个小页面:
|
||||
|
||||
|
||||
```
|
||||
async def render(reactor):
|
||||
my_title = "A Fun page"
|
||||
things = ["one", "two", "red", "blue"]
|
||||
template = tags.html(
|
||||
tags.head(
|
||||
tags.title(my_title),
|
||||
),
|
||||
tags.body(
|
||||
tags.h1(my_title),
|
||||
tags.ul(
|
||||
[tags.li(thing) for thing in things],
|
||||
),
|
||||
tags.p(
|
||||
task.deferLater(reactor, 3, lambda: "Hello "),
|
||||
task.deferLater(reactor, 3, lambda: "world!"),
|
||||
)
|
||||
)
|
||||
)
|
||||
res = await flattenString(None, template)
|
||||
res = res.decode('utf-8')
|
||||
with open("hello.html", 'w') as fpout:
|
||||
fpout.write(res)
|
||||
```
|
||||
|
||||
该模板是使用 **tags.<TAGNAME>** 来指示层次结构的常规 Python 代码。原生支持渲染字符串,因此任何字符串都正常。
|
||||
|
||||
要渲染它,你需要做的是添加调用:
|
||||
|
||||
|
||||
```
|
||||
from twisted.internet import task, defer
|
||||
from twisted.web.template import tags, flattenString
|
||||
|
||||
def main(reactor):
|
||||
return defer.ensureDeferred(render(reactor))
|
||||
```
|
||||
|
||||
最后写上:
|
||||
|
||||
|
||||
```
|
||||
`task.react(main)`
|
||||
```
|
||||
|
||||
只需 _3_ 秒(而不是 _6_ 秒),它将渲染一个不错的 HTML 页面。在实际中,这些 **deferLater** 可以是对 HTTP API 的调用:它们将并行发送和处理,而无需花费精力。我建议你阅读关于[更好地使用 Twisted][8]。但是,这仍可以工作。
|
||||
|
||||
### 1\. Quixote
|
||||
|
||||
你会说:“但是 Python 并不是针对 HTML 输入而优化的领域特定语言。” 如果有一种语言可以[转化][9]到 Python,但是更适合定义模板,而不是像 Python 那样按原样解决呢? 如果可以的话,请使用“Python 模板语言”(PTL)。
|
||||
|
||||
对于攻击假想敌的人来说,写自己的语言有时被认为是梦想家的项目。当 Quixote (可用于 [PyPI][10])的创造者决定这样做时,并没有受此影响。
|
||||
|
||||
以下将渲染与上面 Twisted 相同的模板。 _警告:以下是无效的 Python_:
|
||||
|
||||
|
||||
```
|
||||
import time
|
||||
|
||||
def render [html] ():
|
||||
my_title = "A Fun page"
|
||||
things = ["one", "two", "red", "blue"]
|
||||
"<html><head><title>"
|
||||
my_title
|
||||
"</head></title><body><h1>"
|
||||
my_title
|
||||
"</h1>"
|
||||
"<ul>"
|
||||
for thing in things:
|
||||
"<li>"
|
||||
thing
|
||||
"</li>"
|
||||
"<p>"
|
||||
time.sleep(3)
|
||||
(lambda: "Hello ")()
|
||||
time.sleep(3)
|
||||
(lambda: "world!")()
|
||||
"</p>"
|
||||
"</body></html>"
|
||||
|
||||
def write():
|
||||
result = render()
|
||||
with open("hello.html", 'w') as fpout:
|
||||
fpout.write(str(result))
|
||||
```
|
||||
|
||||
但是,如果将它放到 **template.ptl** 文件中,那么可以将其导入到 Quixote 并写出可以渲染模板的版本:
|
||||
|
||||
|
||||
```
|
||||
>>> from quixote import enable_ptl
|
||||
>>> enable_ptl()
|
||||
>>> import template
|
||||
>>> template.write()
|
||||
```
|
||||
|
||||
Quixote 安装一个导入钩子,它会将 PTL 文件转换为 Python。请注意,此渲染需要 _6_ 秒,而不是 _3_ 秒。你不再能自由异步。
|
||||
|
||||
### Python 中的模板太多
|
||||
|
||||
Python 的库历史悠久且曲折,其中一些库可以或多或少以类似的方式实现相同的结果(例如,Python [包管理][11])。
|
||||
|
||||
在这个愚人节,我希望你喜欢探索这三种_可以_用 Python 创建模板的方式。另外,我建议从[这三个库之一][4]开始了解。
|
||||
|
||||
你是否有另一种深奥的模板方法?请在下面的评论中分享!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/4/python-templating-languages
|
||||
|
||||
作者:[Moshe Zadka][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/python-programming-code-keyboard.png?itok=fxiSpmnd (Hands on a keyboard with a Python book )
|
||||
[2]: https://opensource.com/resources/python
|
||||
[3]: https://opensource.com/article/20/2/jinja2-cheat-sheet
|
||||
[4]: https://opensource.com/resources/python/template-libraries
|
||||
[5]: https://chameleon.readthedocs.io/en/latest/
|
||||
[6]: https://opensource.com/article/18/5/pyramid-framework
|
||||
[7]: https://twistedmatrix.com/documents/13.1.0/web/howto/twisted-templates.html
|
||||
[8]: https://opensource.com/article/20/3/treq-python
|
||||
[9]: https://en.wikipedia.org/wiki/Source-to-source_compiler
|
||||
[10]: https://pypi.org/project/Quixote/
|
||||
[11]: https://opensource.com/article/19/4/managing-python-packages
|
@ -0,0 +1,104 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (lnrCoder)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Now You Can Run Linux Apps in Windows (Thanks to WSL))
|
||||
[#]: via: (https://itsfoss.com/run-linux-apps-windows-wsl/)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
|
||||
现在您可以在 Windows 中运行 Linux 应用(多亏了 WSL)
|
||||
======
|
||||
|
||||
微软最近的 “[Build 2020][1]” 开发者大会公布了一些有趣的公告。 我不确定这该令人兴奋还是该令人怀疑 — 但是微软,你现在比以往任何时候都受到我们的关注。
|
||||
|
||||
同时,在所有公告中,能够在 WSL(Windows Subsystem for Linux)上运行 GUI 应用程序的功能备受关注。
|
||||
|
||||
别忘了 [Xamrin.Forms 更名为 MAUI 的尴尬结局][2],它与 [Nitrux Linux.][4] 的 Uri Herrera 的现有开源项目([Maui Project][3])相冲突。
|
||||
|
||||
以为防止你不不清楚,WSL 是一种环境,可让你在 Windows 10 中获得纯控制台 Linux 的体验。它也是在 [Windows 中运行 Linux 命令的最佳方法][5]之一。
|
||||
|
||||
正如 [Liam Dawe][7] 认为的那样,通过博客文章([DirectX ❤ Linux][6])发布的公告可能是只是个诱饵。但是,仍然值得一提。
|
||||
|
||||
### WSL 上对 Linux GUI 应用程序的支持
|
||||
|
||||
![][8]
|
||||
|
||||
最近,Microsoft 在在线开发者大会上宣布了 WSL(又名 WSL 2)的一系列新功能。
|
||||
|
||||
[Windows Package Manager][9],[Windows Terminal 1.0][10],以及其他一些功能的引入是其亮点。
|
||||
|
||||
但是,支持 GPU 硬件加速的 Windows 的 Linux 2 子系统非常重要。
|
||||
|
||||
那么,是否意味着你可以使用 WSL 在 Windows 上运行 Linux 应用程序呢?看起来像是。
|
||||
|
||||
微软计划通过使用全新的 Linux 内核驱动程序 **dxgkrnl** 来实现。
|
||||
Microsoft plans to make it happen using a brand-new Linux kernel driver **dxgkrnl**。 为了给你一个技术简报, 我在这里引用他们的公告中的描述:
|
||||
|
||||
![Linux Kernel Driver Wsl][11]
|
||||
|
||||
> Dxgkrnl 是 Linux 的全新内核驱动程序,它将 **/dev/dxg** 设备暴露给用户模式的 Linux。 **/dev/dxg** 暴露了一组 IOCTL,他们与 Winodws 上的原生 WDDM D3DKMT 内核服务层非常相似。Linux 内核中的 Dxgkrnl 通过 VM 总线连接到 Windows 主机上,并使用此 VM 总线连接与物理 GPU 进行通讯。
|
||||
|
||||
我不是这方面的专家,但这以为蛇 WSL 上的 Linux 应用程序将具有与本机 Windows 应用程序相同的 GPU 访问权限。
|
||||
|
||||
针对 GUI 应用程序的支持将在今年秋季的晚些时候提供 (而不是 2020 年 5 月的更新) — 所以我们跌看看什么时候提供。
|
||||
|
||||
微软专门针对的是那些系统在 Windows 上轻松使用 Linux IDE 的开发人员。Google 还通过 [将 GUI Linux 应用程序引入 Chromebook ][12] 来针对相同的用户群。
|
||||
|
||||
好吧,对于想要使用 Windows 的用户来说,这是个好消息。但是,这是真的吗?
|
||||
|
||||
### 微软爱上了 Linux — 真的吗?
|
||||
|
||||
![Microsoft Loves Linux][13]
|
||||
|
||||
他们通过努力在 Windows 上整合 Linux 环境来拥抱 Linux 及其优势,绝对是一件好事。
|
||||
|
||||
但是,如何真正帮助 **Linux 桌面用户**呢?到目前为止,我还没有看到任何实际的好处。
|
||||
|
||||
你可以在这里随意发表不同意见。但是,我认为 WSL 的开发对于 Linux 桌面用户来说没有实际的价值。至少目前为止没有。
|
||||
|
||||
有趣的是,[Linux Unplugged podcast][14] 上有人强调了微软的举动,以其闻名的 EEE (Embrace, extend, and extinguish) 为代表。
|
||||
|
||||
可能,谁知道呢?当然,他们为实现这一目标而付出的努力值得赞赏 — 同时又令人感到兴奋和神秘。
|
||||
|
||||
### 这是否以为着 Windows 用户将不必再切换到 Linux?
|
||||
|
||||
微软之所以在其平台上集成 Linux,是因为他们知道 Liunx 的功能以及开发人员(或用户)喜欢使用的原因。
|
||||
|
||||
但是,随着 WSL 2 的更新,如果这种情况持续下去,我倾向于同意 Abhishek 的看法:
|
||||
|
||||
> 最终,桌面 Linux 将被限制为 Windows 下的桌面应用程序。
|
||||
|
||||
好吧,当然,原生的体验暂时还是比较好的。而且,很难看到现有的 Linux 桌面用户会使用 Windows 来将其替代。但是,这仍然是值得担心的。
|
||||
|
||||
你如何看待这一切? 我不认为 WSL 对于被迫使用 Windows 的用户有什么好处 — 但是,从长远来看,你认为微软在 WSL 方面的进展本质上是敌意还是对 Linux 有帮助?
|
||||
|
||||
在评论中让我知道你的想法!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/run-linux-apps-windows-wsl/
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[lnrCoder](https://github.com/lnrCoder)
|
||||
校对:[校对者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://news.microsoft.com/build2020/
|
||||
[2]: https://itsfoss.com/microsoft-maui-kde-row/
|
||||
[3]: https://mauikit.org/
|
||||
[4]: https://itsfoss.com/nitrux-linux/
|
||||
[5]: https://itsfoss.com/run-linux-commands-in-windows/
|
||||
[6]: https://devblogs.microsoft.com/directx/directx-heart-linux/
|
||||
[7]: https://www.gamingonlinux.com/2020/05/microsoft-build-directx-and-linux-plus-more
|
||||
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/Linux-GUI-app-Windows-WSL.png?ssl=1
|
||||
[9]: https://devblogs.microsoft.com/commandline/windows-package-manager-preview/
|
||||
[10]: https://devblogs.microsoft.com/commandline/windows-terminal-1-0/
|
||||
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/linux-kernel-driver-wsl.png?ssl=1
|
||||
[12]: https://itsfoss.com/linux-apps-chromebook/
|
||||
[13]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/05/microsoft-loves-linux.jpg?ssl=1
|
||||
[14]: https://linuxunplugged.com/354
|
Loading…
Reference in New Issue
Block a user