Merge pull request #13 from LCTT/master

update 0827
This commit is contained in:
SamMa 2021-08-27 08:53:49 +08:00 committed by GitHub
commit ead96ed663
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 280 additions and 288 deletions

View File

@ -1,107 +0,0 @@
[#]: subject: "Access your iPhone on Linux with this open source tool"
[#]: via: "https://opensource.com/article/21/8/libimobiledevice-iphone-linux"
[#]: author: "Don Watkins https://opensource.com/users/don-watkins"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Access your iPhone on Linux with this open source tool
======
Communicate with iOS devices from Linux by using Libimobiledevice.
![A person looking at a phone][1]
The iPhone and iPad aren't by any means open source, but they're popular devices. Many people who own an iOS device also happen to use a lot of open source, including Linux. Users of Windows and macOS can communicate with an iOS device by using software provided by Apple, but Apple doesn't support Linux users. Open source programmers came to the rescue back in 2007 (just a year after the iPhone's release) with Libimobiledevice (then called libiphone), a cross-platform solution for communicating with iOS. It runs on Linux, Android, Arm systems such as the Raspberry Pi, Windows, and even macOS.
Libimobiledevice is written in C and uses native protocols to communicate with services running on iOS devices. It doesn't require any libraries from Apple, so it's fully free and open source.
Libimobiledevice is an object-oriented API, and there are a number of terminal utilities that come bundled with it for your convenience. The library supports Apple's earliest iOS devices all the way up to its latest models. This is the result of years of research and development. Applications in the project include **usbmuxd**, **ideviceinstaller**, **idevicerestore**, **ifuse**, **libusbmuxd**, **libplist**, **libirecovery**, and **libideviceactivation**.
### Install Libimobiledevice on Linux
On Linux, you may already have **libimobiledevice** installed by default. You can find out through your package manager or app store, or by running one of the commands included in the project:
```
`$ ifuse --help`
```
You can install **libimobiledevice** using your package manager. For instance, on Fedora or CentOS:
```
`$ sudo dnf install libimobiledevice ifuse usbmuxd`
```
On Debian and Ubuntu:
```
`$ sudo apt install usbmuxd libimobiledevice6 libimobiledevice-utils`
```
Alternatively, you can [download][2] and install **libimobiledevice** from source code.
### Connecting your device
Once you have the required packages installed, connect your iOS device to your computer.
Make a directory as a mount point for your iOS device.
```
`$ mkdir ~/iPhone`
```
Next, mount the device:
```
`$ ifuse ~/iPhone`
```
Your device prompts you to trust the computer you're using to access it.
![iphone prompts to trust the computer][3]
Figure 1: The iPhone prompts you to trust the computer.
Once the trust issue is resolved, you see new icons on your desktop.
![iphone icons appear on desktop][4]
Figure 2: New icons for the iPhone appear on the desktop.
Click on the **iPhone** icon to reveal the folder structure of your iPhone.
![iphone folder structure displayed][5]
Figure 3: The iPhone folder structure is displayed.
The folder I usually access most frequently is **DCIM**, where my iPhone photos are stored. Sometimes I use these photos in articles I write, and sometimes there are photos I want to enhance with open source applications like Gimp. Having direct access to the images instead of emailing them to myself is one of the benefits of using the Libimobiledevice utilities. I can copy any of these folders to my Linux computer. I can create folders on the iPhone and delete them too.
### Find out more
[Martin Szulecki][6] is the lead developer for the project. The project is looking for developers to add to their [community][7]. Libimobiledevice can change the way you use your peripherals, regardless of what platform you're on. It's another win for open source, which means it's a win for everyone.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/libimobiledevice-iphone-linux
作者:[Don Watkins][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/don-watkins
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/idea_innovation_mobile_phone.png?itok=RqVtvxkd (A person looking at a phone)
[2]: https://github.com/libimobiledevice/libimobiledevice/
[3]: https://opensource.com/sites/default/files/1trust_0.png
[4]: https://opensource.com/sites/default/files/2docks.png
[5]: https://opensource.com/sites/default/files/2iphoneicon.png
[6]: https://github.com/FunkyM
[7]: https://libimobiledevice.org/#community

View File

@ -2,7 +2,7 @@
[#]: via: "https://fedoramagazine.org/apps-for-daily-needs-part-4-audio-editors/"
[#]: author: "Arman Arisman https://fedoramagazine.org/author/armanwu/"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "

View File

@ -1,180 +0,0 @@
[#]: subject: "How to include options in your Bash shell scripts"
[#]: via: "https://opensource.com/article/21/8/option-parsing-bash"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "unigeorge"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How to include options in your Bash shell scripts
======
Give your shell scripts options.
![Terminal commands][1]
Terminal commands usually have [options or switches][2], which you can use to modify how the command does what it does. Options are included in the [POSIX specification][3] for command-line interfaces. It's also a time-honored convention established with the earliest UNIX applications, so it's good to know how to include them in your [Bash scripts][4] when you're creating your own commands.
As with most languages, there are several ways to solve the problem of parsing options in Bash. To this day, my favorite method remains the one I learned from Patrick Volkerding's Slackware build scripts, which served as my introduction to shell scripting back when I first discovered Linux and dared to venture into the plain text files that shipped with the OS.
### Option parsing in Bash
The strategy for parsing options in Bash is to cycle through all arguments passed to your shell script, determine whether they are an option or not, and then shift to the next argument. Repeat this process until no options remain.
Start with a simple Boolean option (sometimes called a _switch_ or a _flag_):
```
#!/bin/bash
while [ True ]; do
if [ "$1" = "--alpha" -o "$1" = "-a" ]; then
    ALPHA=1
    shift 1
else
    break
fi
done
echo $ALPHA
```
In this code, I create a `while` loop which serves as an infinite loop until there are no further arguments to process. An `if` statement attempts to match whatever argument is found in the first position (`$1`) to either `--alpha` or `-a`. (These are arbitrary option names with no special significance. In an actual script, you might use `--verbose` and `-v` to trigger verbose output).
The `shift` keyword causes all arguments to shift by 1, such that an argument in position 2 (`$2`) is moved into position 1 (`$1`). The `else` statement is triggered when there are no further arguments to process, which breaks the `while` loop.
At the end of the script, the value of `$ALPHA` is printed to the terminal.
Test the script:
```
$ bash ./test.sh --alpha
1
$ bash ./test.sh
$ bash ./test.sh -a
1
```
The option is correctly detected.
### Detecting arguments in Bash
There is a problem, though: Extra arguments are ignored.
```
$ bash ./test.sh --alpha foo
1
$
```
To catch arguments that aren't intended as options, you can dump remaining arguments into a [Bash array][5].
```
#!/bin/bash
while [ True ]; do
if [ "$1" = "--alpha" -o "$1" = "-a" ]; then
    ALPHA=1
    shift 1
else
    break
fi
done
echo $ALPHA
ARG=( "${@}" )
for i in ${ARG[@]}; do
    echo $i
done
```
Test the new version of the script:
```
$ bash ./test.sh --alpha foo
1
foo
$ bash ./test.sh foo
foo
$ bash ./test.sh --alpha foo bar
1
foo
bar
```
### Options with arguments
Some options require an argument all their own. For instance, you might want to allow the user to set an attribute such as a color or the resolution of a graphic or to point your application to a custom configuration file.
To implement this in Bash, you can use the `shift` keyword as you do with Boolean switches but shift the arguments by 2 instead of 1.
```
#!/bin/bash
while [ True ]; do
if [ "$1" = "--alpha" -o "$1" = "-a" ]; then
    ALPHA=1
    shift 1
elif [ "$1" = "--config" -o "$1" = "-c" ]; then
    CONFIG=$2
    shift 2
else
    break
fi
done
echo $ALPHA
echo $CONFIG
ARG=( "${@}" )
for i in ${ARG[@]}; do
    echo $i
done
```
In this code, I add an `elif` clause to compare each argument to both `--config` and `-c`. In the event of a match, the value of a variable called `CONFIG` is set to the value of whatever the second argument is (this means that the `--config` option requires an argument). All arguments shift place by 2: 1 to shift `--config` or `-c`, and 1 to move its argument. As usual, the loop repeats until no matching arguments remain.
Here's a test of the new version of the script:
```
$ bash ./test.sh --config my.conf foo bar
my.conf
foo
bar
$ bash ./test.sh -a --config my.conf baz
1
my.conf
baz
```
### Option parsing made easy
There are other ways to parse options in Bash. You can alternately use a `case` statement or the `getopt` command. Whatever you choose to use, options for your users are important features for any application, and Bash makes it easy.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/option-parsing-bash
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[unigeorge](https://github.com/unigeorge)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/terminal-commands_1.png?itok=Va3FdaMB (Terminal commands)
[2]: https://opensource.com/article/21/8/linux-terminal#options
[3]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
[4]: https://opensource.com/downloads/bash-scripting-ebook
[5]: https://opensource.com/article/18/5/you-dont-know-bash-intro-bash-arrays

View File

@ -0,0 +1,107 @@
[#]: subject: "Access your iPhone on Linux with this open source tool"
[#]: via: "https://opensource.com/article/21/8/libimobiledevice-iphone-linux"
[#]: author: "Don Watkins https://opensource.com/users/don-watkins"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
用这个开源工具在 Linux 上访问你的 iPhone
======
过使用 Libimobiledevice 从 Linux 与 iOS 设备进行通信。
![A person looking at a phone][1]
iPhone 和 iPad 决不是开源的,但它们是流行的设备。许多拥有 iOS 备的人恰好也在使用大量的开源,包括 Linux。Windows 和 macOS 的用户可以通过使用苹果提供的软件与 iOS 设备通信,但苹果不支持 Linux 用户。开源程序员早在 2007 年(就在 iPhone 发布一年后)就以 Libimobiledevice当时叫 libiphone来拯救了人们这是一个与 iOS 通信的跨平台解决方案。它可以在 Linux、Android、Arm 系统(如 Raspberry Pi、Windows、甚至 macOS 上运行。
Libimobiledevice 是用 C 语言编写的,使用原生协议与 iOS 设备上运行的服务进行通信。它不需要苹果公司的任何库,所以它是完全免费和开源的。
Libimobiledevice 是一个面向对象的 API有许多终端工具与它捆绑在一起以方便你使用。该库支持苹果最早的 iOS 设备,一直到其最新的型号。这是多年来研究和开发的结果。该项目中的应用包括 **usbmuxd**、**ideviceinstaller**、**idevicerestore**、**ifuse**、**libusbmuxd**、**libplist**、**libirecovery**、和 **libideviceactivation**
### 在 Linux 上安装 Libimobiledevice
在 Linux 上,你可能已经默认安装了 **libimobiledevice**。你可以通过你的软件包管理器或应用商店找到,或者通过运行项目中包含的一个命令:
```
`$ ifuse --help`
```
你可以用你的包管理器安装 **libimobiledevice**。例如,在 Fedora 或 CentOS 上:
```
`$ sudo dnf install libimobiledevice ifuse usbmuxd`
```
在 Debian 和 Ubuntu 上:
```
`$ sudo apt install usbmuxd libimobiledevice6 libimobiledevice-utils`
```
或者,你可以从源代码[下载][2]并安装 **libimobiledevice**
### 连接你的设备
当你安装了所需的软件包,将你的 iOS 设备连接到你的电脑。
为你的 iOS 设备建立一个目录作为挂载点。
```
`$ mkdir ~/iPhone`
```
接下来,挂载设备:
```
`$ ifuse ~/iPhone`
```
你的设备提示你信任你用来访问它的电脑。
![iphone prompts to trust the computer][3]
图 1iPhone 提示你要信任电脑。
信任问题解决后,你会在桌面上看到新的图标。
![iphone icons appear on desktop][4]
图 2iPhone 的新图标出现在桌面上。
点击 **iPhone** 图标,显示出你的 iPhone 的文件夹结构。
![iphone folder structure displayed][5]
图 3显示了 iPhone 的文件夹结构。
我通常最常访问的文件夹是 **DCIM**,那里存放着我的 iPhone 照片。有时我在写文章时使用这些照片,有时有一些照片我想用 Gimp 等开源应用来增强。可以直接访问这些图片,而不是通过电子邮件把它们发给我自己,这是使用 Libimobiledevice 工具的好处之一。我可以把这些文件夹中的任何一个复制到我的 Linux 电脑上。我也可以在 iPhone 上创建文件夹并删除它们。
### 发现更多
[Martin Szulecki][6] 是该项目的首席开发者。该项目正在寻找开发者加入他们的[社区][7]。Libimobiledevice 可以改变你使用外设的方式,而无论你在什么平台上。这是开源的又一次胜利,这意味着它是所有人的胜利。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/libimobiledevice-iphone-linux
作者:[Don Watkins][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/don-watkins
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/idea_innovation_mobile_phone.png?itok=RqVtvxkd (A person looking at a phone)
[2]: https://github.com/libimobiledevice/libimobiledevice/
[3]: https://opensource.com/sites/default/files/1trust_0.png
[4]: https://opensource.com/sites/default/files/2docks.png
[5]: https://opensource.com/sites/default/files/2iphoneicon.png
[6]: https://github.com/FunkyM
[7]: https://libimobiledevice.org/#community

View File

@ -0,0 +1,172 @@
[#]: subject: "How to include options in your Bash shell scripts"
[#]: via: "https://opensource.com/article/21/8/option-parsing-bash"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "unigeorge"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
如何在 Bash shell 脚本中解析命令行选项
======
把选项交给你的 shell 脚本吧。
![Terminal commands][1]
终端命令通常具有 [<ruby>选项<rt>options or switches</rt></ruby>][2] 功能,用户可以使用选项来修改命令的执行方式。关于命令行接口的 [POSIX 规范][3] 中就对选项做出了规范,这也是基于最早的 UNIX 应用程序建立的一个由来已久的约定,因此你在创建自己的命令时,最好知道如何将选项包含进 [Bash 脚本][4] 中。
与大多数语言一样,有若干种方法可以解决 Bash 中解析选项的问题。但直到今天,我最喜欢的方法仍然是我从 Patrick Volkerding 的 Slackware 构建脚本中学到的方法,当我第一次得知 Linux 并勇于探索操作系统附带的纯文本文件时,它就是我关于 shell 脚本的引路人。
### Bash 中的选项解析
在 Bash 中解析选项的策略是循环遍历传递给 shell 脚本的所有参数,确定它们是否为选项,然后转移到下一个参数。重复这个过程,直到没有选项为止。
```
#!/bin/bash
while [ True ]; do
if [ "$1" = "--alpha" -o "$1" = "-a" ]; then
    ALPHA=1
    shift 1
else
    break
fi
done
echo $ALPHA
```
在这段代码中,我创建了一个 `while` 循环,它会一直进行循环操作,直到处理完所有参数。`if` 语句会试着将在第一个位置(`$1`)中找到的参数与 `--alpha``-a` 匹配。(此处的待匹配项是任意选项名称,并没有特殊意义。在实际的脚本中,你可以使用 `--verbose``-v` 来触发详细输出)。
`shift` 关键字会使所有参数向后移动一位,这样位置 2`$2`)的参数移动到位置 1`$1`)。处理完所有参数后会触发 else 语句,进而中断 while 循环。
在脚本的末尾,`$ALPHA` 的值会输出到终端。
测试一下这个脚本:
```
$ bash ./test.sh --alpha
1
$ bash ./test.sh
$ bash ./test.sh -a
1
```
可以看到,选项被正确地检测到了。
### 在 Bash 中检测参数
但上面的脚本还有一个问题:多余的参数被忽略了。
```
$ bash ./test.sh --alpha foo
1
$
```
要想捕获非选项名的参数,可以将剩余的参数转储到 [Bash 数组][5] 中。
```
#!/bin/bash
while [ True ]; do
if [ "$1" = "--alpha" -o "$1" = "-a" ]; then
    ALPHA=1
    shift 1
else
    break
fi
done
echo $ALPHA
ARG=( "${@}" )
for i in ${ARG[@]}; do
    echo $i
done
```
测试一下新版的脚本:
```
$ bash ./test.sh --alpha foo
1
foo
$ bash ./test.sh foo
foo
$ bash ./test.sh --alpha foo bar
1
foo
bar
```
### 带参选项
有一些选项需要传入参数。比如,你可能希望允许用户设置诸如颜色或图形分辨率之类的属性,或者将应用程序指向自定义配置文件。
要在 Bash 中实现这一点,你仍然可以像使用布尔选项一样使用 `shift` 关键字,但参数需要向后移动两位而不是一位。
```
#!/bin/bash
while [ True ]; do
if [ "$1" = "--alpha" -o "$1" = "-a" ]; then
    ALPHA=1
    shift 1
elif [ "$1" = "--config" -o "$1" = "-c" ]; then
    CONFIG=$2
    shift 2
else
    break
fi
done
echo $ALPHA
echo $CONFIG
ARG=( "${@}" )
for i in ${ARG[@]}; do
    echo $i
done
```
在这段代码中,我添加了一个 `elif` 子句来将每个参数与 `--config``-c` 进行比较。如果匹配,名为 `CONFIG` 的变量的值就设置为下一个参数的值(这就表示 `--config` 选项需要一个参数)。所有参数都后移两位:其中一位是跳过 `--config``-c`,另一位是跳过其参数。与上节一样,循环重复直到没有匹配的参数。
下面是新版脚本的测试:
```
$ bash ./test.sh --config my.conf foo bar
my.conf
foo
bar
$ bash ./test.sh -a --config my.conf baz
1
my.conf
baz
```
### Bash 让选项解析变得简单
还有一些其他方法也可以解析 Bash 中的选项。你可以交替使用 `case` 语句或 `getopt` 命令。无论使用什么方法,用户选项都是应用程序的重要功能,而 Bash 让解析选项成为了一件简单的事。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/option-parsing-bash
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[unigeorge](https://github.com/unigeorge)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/terminal-commands_1.png?itok=Va3FdaMB (Terminal commands)
[2]: https://opensource.com/article/21/8/linux-terminal#options
[3]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
[4]: https://opensource.com/downloads/bash-scripting-ebook
[5]: https://opensource.com/article/18/5/you-dont-know-bash-intro-bash-arrays