FreeBSD 使用 pkg 作套件管理

FreeBSD 可以使用 pkg 和 ports 來安裝套件。其中 pkg 指令的功能和 RedHat/CentOS Linux 中的 yum 和 Debian/Ubuntu Linux 中的 apt 及 ArchLinux 中的 pacman 功能類似。
搜尋套件
# pkg search bash | grep ^bash
bash-4.3.42_1                  The GNU Project’s Bourne Again SHell
bash-completion-2.1_6,1        Programmable completion library for Bash
bash-static-4.3.42_1           The GNU Project’s Bourne Again SHell
bashc-3.2.33.0_1               GNU bash shell extended with visual two-panel file browser[@more@]
查詢套件資訊
# pkg info bash

安裝套件
# pkg install bash

查詢套件安裝的版本
# pkg version | grep bash
bash-4.3.42_1                      =

移除套件
# pkg delete bash

自動移除系統中用不到的套件
# pkg autoremove

更新系統中已安裝的套件
# pkg upgrade

更新套件庫
# pkg update

清除暫存區的舊套件
# pkg clean

查詢系統中安裝的套件
# pkg info
# pkg version

套件安裝的版本
# pkg version -v
bash-4.3.42_1                      =   up-to-date with port
gettext-runtime-0.19.7             >   succeeds port (port has 0.19.6)
gnuls-8.22                         =   up-to-date with port
indexinfo-0.2.4                    =   up-to-date with port
pkg-1.7.2                          >   succeeds port (port has 1.6.2)
vim-lite-7.4.1556                  >   succeeds port (port has 7.4.979)

查詢套件安裝的位置
# pkg info -l gnuls
gnuls-8.22:
        /usr/local/bin/dir
        /usr/local/bin/dircolors
        /usr/local/bin/gnuls
        /usr/local/bin/vdir
        /usr/local/man/man1/dir.1.gz
        /usr/local/man/man1/dircolors.1.gz
        /usr/local/man/man1/gnuls.1.gz
        /usr/local/man/man1/vdir.1.gz

查詢套件的相依性
# pkg info -d bash
bash-4.3.42_1:
        indexinfo-0.2.4
        gettext-runtime-0.19.7

檔案所屬套件
# pkg which /usr/local/bin/bash
/usr/local/bin/bash was installed by package bash-4.3.42_1

更多的 pkg 功能
# pkg help

解決 FreeBSD pkg 指令無法搜尋到套件的問題

在 FreeBSD 系統使用 pkg 搜尋要安裝的套件時,出現
# pkg search bash
pkg: No packages available to install matching bash available in the repositories

# pkg search bash
完全無任何訊息

也已經把套件庫更新到最新
# pkg update
Updating FreeBSD repository catalogue…
FreeBSD repository is up-to-date.
All repositories are up-to-date.[@more@]解決方式 刪除 /var/db/pkg/repo-*
# rm -rf /var/db/pkg/repo-FreeBSD.sqlite

重新套件套件庫
# pkg update
Updating FreeBSD repository catalogue…
Fetching meta.txz: 100%    944 B   0.9kB/s    00:01
Fetching packagesite.txz: 100%    5 MiB   5.6MB/s    00:01
Processing entries: 100%
FreeBSD repository update completed. 25089 packages processed.

這時候就正常了!
# pkg search bash
bash-4.3.42_1                  The GNU Project’s Bourne Again SHell
bash-completion-2.1_6,1        Programmable completion library for Bash
bash-static-4.3.42_1           The GNU Project’s Bourne Again SHell
bashc-3.2.33.0_1               GNU bash shell extended with visual two-panel file browser
checkbashisms-2.15.10          Check for the presence of bashisms
erlang-mochiweb-basho-2.9.0p2  Erlang library for building lightweight HTTP servers (Basho fork)
mybashburn-1.0.2_4             Ncurses CD burning bash script
p5-Bash-Completion-0.008_1     Extensible system to provide bash completion
p5-Term-Bash-Completion-Generator-0.02.8 Generate bash completion scripts

FreeBSD 10.3 安裝

距離上一次好好使用 FreeBSD 系統已經有八、九年了,這一段時間 FreeBSD 的變化也很大,有種從 CentOS 6.x 跳到 CentOS 7.x 的感覺,很多東西都變了,最近在使用 FreeNAS 和 NAS4Free,就感覺到很生疏,所以利用時間再重新安裝 FreeBSD 來使用看看。

FreeBSD  安裝網站:https://www.freebsd.org/
目前最新版本是 10.3 版
台灣 FreeBSD 下載網站:
ftp://ftp.tw.freebsd.org/pub/FreeBSD/releases/ISO-IMAGES/10.3/

1. 光碟開機畫面
[@more@]2. 選擇 Install 進行安裝

3. 鍵盤型式選擇

4. 主機名稱

5. 預設安裝元件

6. 硬碟分割

7. 整個硬碟

8. 採用 GUID 型式硬碟分割區

9. 硬碟分割狀態

10. 選擇 Commit 確認

11. 元件檢查

12. 進行安裝

13. 設定 root 管理者密碼

14. 系統偵測到的網路卡

15. 設定 IPv4

16. 使用 DHCP Server 自動取得 IP

17. 不設定 IPv6

18. DNS Server 設定

19. 不使用 UTC 時間

20. 選擇 5 Asia

21. 選擇 42 Taiwan

22. 使用 CST 時間

23. 預設啟動的系統服務

24. 新增 root 之外的使用者

25. 新增使用者

26. 不再新增其它使用者

27. 退出安裝系統

28. 不再切換到 shell 作其它設定

29. 重新啟動系統

30. 開機畫面

31. 登入系統

NAS4Free – 更改 IP

安裝 NAS4Free 時是使用 DHCP Server,直接取得 IP,如果想要更換成其它固定的 IP 設定方法。
1. 原先的 IP 是 192.168.1.250,選擇 2 Configure Network IP Address

[@more@]2. 不使用 DHCP Server 取得 IP

3. 設定要使用的 IP

4. 設定子網路遮罩 Subnet mask

5. 設定 Gateway

6. 設定 DNS Server

7. 不設定 IPv6

8. IP 已經改成 192.168.1.99

OpenMediaVault – 使用 grive 同步檔案到 Google Drive(成功)

參考網頁:
Grive2 — YourcmcWiki
GitHub – vitalif/grive2: Google Drive client with support for new Drive REST API and partial sync

1.安裝所需套件
# apt-get install git cmake build-essential libgcrypt11-dev libyajl-dev libboost-all-dev libcurl4-openssl-dev libexpat1-dev libcppunit-dev binutils-dev pkg-config

2. 下載 grive Source Code
# git clone https://github.com/vitalif/grive2
Cloning into ‘grive2’…
remote: Counting objects: 3914, done.
remote: Total 3914 (delta 0), reused 0 (delta 0), pack-reused 3914
Receiving objects: 100% (3914/3914), 1.05 MiB | 364.00 KiB/s, done.
Resolving deltas: 100% (2565/2565), done.
Checking connectivity… done.[@more@]3. 進行編譯
# cd grive2
# mkdir build
# cd build
# cmake ..
— Found libgcrypt: -lgcrypt
— Boost version: 1.55.0
— Found the following Boost libraries:
—   program_options
—   filesystem
—   unit_test_framework
—   regex
—   system
— Found libbfd: /usr/lib/libbfd.so
— Found CppUnit: /usr/lib/x86_64-linux-gnu/libcppunit.so
— Could NOT find ZLIB (missing:  ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
— Found PkgConfig: /usr/bin/pkg-config (found version “0.28”)
— checking for module ‘yajl’
—   found yajl, version 2.1.0
— Building unitary tests along with the library and the binary
— Boost version: 1.55.0
— Found the following Boost libraries:
—   program_options
— Configuring done
— Generating done
— Build files have been written to: /root/grive2/build

4. 進行安裝
# make -j4
# make install
Install the project…
— Install configuration: “”
— Installing: /usr/local/bin/grive
— Installing: /usr/local/share/man/man1/grive.1

5. 取得 Google Drive 授權碼
# cd /home/t850008
# /usr/local/bin/grive -a

6. 進行同步
# /usr/local/bin/grive -p /home/t850008

7. 進行工作排程
# crontab -e
*/5 * * * * /usr/local/bin/grive -p /home/t850008 > /dev/null 2>&1

OpenMediaVault – 使用 grive 同步檔案到 Google Drive(失敗)

參考文件:在 Linux 中使用 Grive 指令工具同步 Google 雲端硬碟(Drive)上的檔案 – G. T. Wang
1. 安裝 grive
# apt-get update
# apt-get install grive

2. 先開啟瀏覽器登入到要同步的 Google Drive 帳號:

[@more@]3. 切換到要同步的目錄,並進行設定
# cd /home/t850008
# grive -a

4. 在下方產生網址

5. 將產生的網址,貼到瀏覽器網址列,按  Enter 鍵執行

6. 選擇 允許

7. 將產生的 授權碼 複製起來

8. 將產生的 授權碼 貼在下方,按  Enter 鍵執行

9. 執行畫面

10. 執行 grive 進行同步,但無法同步

11. 移除 grive
# apt-get remove –purge grive