WSL Ubuntu 透過 APT 安裝軟體時出現 IPC connect call failed 與 NO_PUBKEY

安裝 MariaDB 時,官方貼心的提供了一個 Repository Configuration Tool,可以選好自己的作業系統與想要安裝的發行版後產生相對應的指令碼,直接複製貼上就可以透過套件管理員進行安裝。

這兩天在摸索 WSL (Windows Subsystem Linux),使用的發行版是 Ubuntu,而今天在 WLS 內安裝 MariaDB 10.4 時卻出現一些錯誤:

sudo apt-get install software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
software-properties-common is already the newest version (0.96.24.32.9).
The following packages were automatically installed and are no longer required:
  gyp javascript-common libhttp-parser2.7.1 libjs-async libjs-inherits libjs-jquery libjs-node-uuid libjs-underscore libuv1-dev nodejs-doc
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 21 not upgraded.

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
Executing: /tmp/apt-key-gpghome.jVRLtzEDLC/gpg.1.sh --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
gpg: connecting dirmngr at '/tmp/apt-key-gpghome.jVRLtzEDLC/S.dirmngr' failed: IPC connect call failed
gpg: keyserver receive failed: No dirmngr

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.4/ubuntu bionic main'
Hit:1 http://free.nchc.org.tw/ubuntu bionic InRelease
Hit:2 http://free.nchc.org.tw/ubuntu bionic-updates InRelease
Get:3 http://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.4/ubuntu bionic InRelease [3901 B]
Hit:4 https://deb.nodesource.com/node_10.x bionic InRelease
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
Err:3 http://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.4/ubuntu bionic InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F1656F24C74CD1D8
Reading package lists... Done
W: GPG error: http://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.4/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F1656F24C74CD1D8
E: The repository 'http://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.4/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

有兩個關鍵字:

  1. IPC connect call failed (Line 12)
  2. NO_PUBKEY (Line 25)

找了一下,發現是 WSL 自己的問題,跟 Ubuntu 沒有太大的關係;開發者 Ghost 表示是 WSL 下的 Ubuntu Bionic 第一版的問題,改用 curl 去把 key 抓下來後透過 sudo apt-key add 就可以解決:

It’s Bugging Since The First Bionics in wsl. But the temporary to pass this problems is using apt-key add instead adv options through wget or curl :
curl -sL “http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xA6A19B38D3D831EF” | sudo apt-key add

但是在 issue closed 後隔沒幾天有其他人表示說問題依然存在,並沒有被解決,最後發現只是各個軟體的 key 不一樣而已,開發者 foxliu 提醒依照安裝軟體的不同,要自己更換 key,以 MariaDB 來說,官方提供的 key 為 0xF1656F24C74CD1D8, 所以把指令改成這樣就好:

curl -sL "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xF1656F24C74CD1D8" | sudo apt-key add
OK

最後重新執行一次 sudo apt update,就可以把套件資訊抓回來了。

sudo apt update
Hit:1 http://free.nchc.org.tw/ubuntu bionic InRelease
Hit:2 http://free.nchc.org.tw/ubuntu bionic-updates InRelease
Hit:3 https://deb.nodesource.com/node_10.x bionic InRelease
Get:4 http://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.4/ubuntu bionic InRelease [3901 B]
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
Get:6 http://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.4/ubuntu bionic/main arm64 Packages [7787 B]
Get:7 http://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.4/ubuntu bionic/main amd64 Packages [8008 B]
Get:8 http://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.4/ubuntu bionic/main ppc64el Packages [7793 B]
Fetched 27.5 kB in 4s (6549 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
24 packages can be upgraded. Run 'apt list --upgradable' to see them.

檢查一下套件資訊:

apt show mariadb-server
Package: mariadb-server
Version: 1:10.4.6+maria~bionic
Priority: optional
Section: database
Source: mariadb-10.4
Maintainer: MariaDB Developers <[email protected]>
Installed-Size: 10.2 kB
Depends: mariadb-server-10.4 (>= 1:10.4.6+maria~bionic)
Homepage: http://mariadb.org/
Download-Size: 3180 B
APT-Sources: http://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.4/ubuntu bionic/main amd64 Packages
Description: MariaDB database server (metapackage depending on the latest version)
 This is an empty package that depends on the current "best" version of
 mariadb-server (currently mariadb-server-10.4), as determined by the MariaDB
 maintainers. Install this package if in doubt about which MariaDB
 version you need. That will install the version recommended by the
 package maintainers.
 .
 MariaDB is a fast, stable and true multi-user, multi-threaded SQL database
 server. SQL (Structured Query Language) is the most popular database query
 language in the world. The main goals of MariaDB are speed, robustness and
 ease of use.

N: There are 2 additional records. Please use the '-a' switch to see them.

如果安裝其他套件時出現類似的錯誤,把 key 替換應該都能解決。

Reference: Ubuntu 18.04 gpg dirmngr IPC connect call failed #3286

發表留言

讓 Visual Studio Code 在關閉工作區時保留未儲存的檔案

Visual Studio Code 在預設情況下,關閉工作區時如果有未儲存的檔案,就會詢問要不要儲存,而沒辦法暫存起來於下次開啟時載入(Sublime Text 預設是可以的)。

 

其實 Visual Studio Code 也支援,只是預設值為在關閉整個 Visual Studio Code 才會有用,如果要支援關閉工作區的話,將 files.hotExit 這個設定值修改為 onExitAndWindowClose 即可。

 

Reference: vscode settings – How to keep unsaved file into vs code workspace? – Stack Overflow

發表留言

[Chrome] 清除快取的三種方法

一、全域清除

  1. 滑鼠點選右上角展開選單,選擇「設定」。
  2. 找到隱私權區塊,點選「清除瀏覽資料」。
  3. 自行指定要清除的類型與時間。
    161220_01

 

二、單一網站

  1. 開啟 Chrome Developer Tool 介面。(快速鍵:F12Ctrl+Shift+I,MAC 使用者按 Command+Shift+I 
  2. 切換到介面上的「Application」分頁。
  3. 點選介面左側選單「Clear storage」,勾選要清除的類型後,按下「Clear site data」。
    161220_02

 

三、單一頁面 (最快最方便,推薦)

  1. 開啟 Chrome Developer Tool 介面。(快速鍵:F12Ctrl+Shift+I,MAC 使用者按 Command+Shift+I )
  2. 滑鼠右鍵點選左上角 Reload 按鈕,在 Developer Tool 介面下會出現三種不同的 Reload 方式。
  3. 點選第三種「清除快取並強制重新載入」。
    161220_03
2 則迴響

[SublimeText] 正規表示式搜尋與取代

在搜尋/取代模式下

點選下圖紅框處,即可使用regex模式

161201_1

 

如果想要保留match pattern內容

在Replace With這欄如上圖使用錢號+數字即可

如果有一段內容如下:

$a = 1;
$b = 2;

 

照圖中使用的Replace pattern

就會變成如下:

$a = '1';
$b = '2';

 

PS:

  1. 錢號是特殊符號,所以要當作純文字的話要加反斜線。
  2. 使用 $1 或是 \1 在 Sublime Text 中兩者皆具有保留 match pattern 的效果。
發表留言

Cloc – 快速計算程式碼行數

最近剛好一個閒來無事

想看看專案規模成長到多大

雖然以程式碼行數來去看是不太準

但起碼依然是指標的一種

 

Cloc不但計算快速

且除了程式碼行數,還會列出檔案總數、空行數和註解行數

 

GitHub: https://github.com/AlDanial/cloc


安裝

Cloc可以透過多種Package manager安裝:

npm install -g cloc                    # https://www.npmjs.com/package/cloc
sudo apt-get install cloc              # Debian, Ubuntu
sudo yum install cloc                  # Red Hat, Fedora
sudo dnf install cloc                  # Fedora 22 or later
sudo pacman -S cloc                    # Arch
sudo pkg install cloc                  # FreeBSD
sudo port install cloc                 # Mac OS X with MacPorts
brew install cloc                      # Mac OS X with Homebrew
choco install cloc                     # Windows with Chocolatey

也可以直接下載Released package進行安裝 (下載頁面 )

 


操作

指令:cloc [options] <file(s)/dir(s)> | <set 1> <set 2> | <report files>

[email protected]:~/project/my-project$ cloc .
     538 text files.
     520 unique files.
     154 files ignored.

https://github.com/AlDanial/cloc v 1.66  T=2.61 s (182.4 files/s, 38389.0 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
PHP                            299           3141           1457          35339
JavaScript                      97           5996           5308          30628
CSS                             44            386            207          11262
SQL                              2             25             54           2732
HTML                            14            423             98           2699
JSON                            10              1              0            282
Bourne Shell                     8             21              2             77
make                             1             12             13             28
YAML                             1              0              0             10
-------------------------------------------------------------------------------
SUM:                           476          10005           7139          83057
-------------------------------------------------------------------------------

個人常用的參數有三種:

  • –exclude-dir: 排除特定目錄,以逗號隔開
  • –exclude-lang: 排除特定語言,以逗號隔開
  • –exclude-ext: 排除特定副檔名,以逗號隔開

完整參數說明請參考官方文件 

 

以下範例為:

  1. 排除plugins、makefiles、storage三個特定目錄下所有檔案
  2. 排除make語言的所有檔案
  3. 排除副檔名為html的所有檔案
[email protected]:~/project/my-project$ cloc . --exclude-dir=plugins,makefiles,storage --exclude-lang=make --exclude-ext=html
     372 text files.
     364 unique files.
      63 files ignored.

https://github.com/AlDanial/cloc v 1.66  T=0.44 s (808.6 files/s, 102809.6 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
PHP                            286           2986           1390          34250
JavaScript                      39            604            286           4056
CSS                             28            230             23           1055
-------------------------------------------------------------------------------
SUM:                           353           3820           1699          39361
-------------------------------------------------------------------------------

 

發表留言