# 日記
[TOC]
## 2020/07/09
### 前回までのあらすじ
Docker Desktopはいいものだったが、結局の所パフォーマンス的にWSLの中からファイルを操作しないと実用できなさそうだった。`\\wsl$ `のネットワークドライブごしにアクセスするとクソ遅い。
WSL内からGitKrakenを使うために(Snapを使うために)[DamionGans/ubuntu-wsl2-systemd-script](https://github.com/DamionGans/ubuntu-wsl2-systemd-script)を入れようとしたらUbuntuが壊れたので再インストール
<details>
### WSL2 再インストール
[Windows 10のWSL環境を初期化してクリーンな状態に戻す:Tech TIPS - @IT](https://www.atmarkit.co.jp/ait/articles/1807/06/news028.html)
[u-ch: WSL のデフォルト Linux ディストリビューションを変更する](https://u.hoso.net/2020/06/wsl-linux.html)
![](https://i.imgur.com/xDF4rGj.png)
Okay
私の環境ではWindowsのpathを引き継ぐのを切っていて、cmd.exeにパスが通っていないので通す。DamionGans/ubuntu-wsl2-systemd-scriptがcmd.exeのコマンドを実行するため。
![](https://i.imgur.com/Y2oYAsr.png)
ついでにDocker Desktopを使うためのパスも通した
[WSL2上のdocker-composeで認証エラー - roy-n-roy メモ](https://roy-n-roy.github.io/Windows/WSL%EF%BC%86%E3%82%B3%E3%83%B3%E3%83%86%E3%83%8A/DockerDesktopError/)
`ghq`でclone……goを入れなきゃだめか
Ubuntu 20.04なので`sudo apt install golang-go`で新しめのが入るのは本当に助かる
```bash
eai@MADAI:~$ go version
go version go1.13.8 linux/amd64
```
GOPATHは(.bash_profileを使ってない限り).profileにかけばいいらしい
[bash の初期化ファイル .profile, .bashrc, .bash_profile の使い分けと管理方針 - A Memorandum](https://blog1.mammb.com/entry/2019/12/01/090000)
Ubuntu 20.04は`.profile`と`.bashrc`があるけど`.bash_profile`がなくてのみになっている?みたいなので環境変数は`.profile`に書く感じにします
記事内でいうと**標準的管理(環境変数は~/.profile)**
[go - Why is $GOPATH often set in ~/.bashrc and ~/.bash_profile instead of ~/.profile? - Stack Overflow](https://stackoverflow.com/questions/47235993/why-is-gopath-often-set-in-bashrc-and-bash-profile-instead-of-profile)
```bash
eai@MADAI:~$ nano ~/.profile
```
```bash:~/.profile
export GOPATH=$HOME/.go
export PATH="$PATH:$GOPATH/bin"
```
```bash
eai@MADAI:~$ source ~/.profile
eai@MADAI:~$ echo $GOPATH
/home/eai/.go
eai@MADAI:~$
```
いざghqを入れる
[x-motemen/ghq: Remote repository management made easy](https://github.com/x-motemen/ghq)
```bash
eai@MADAI:~$ go get github.com/x-motemen/ghq
eai@MADAI:~$ ghq
NAME:
ghq - Manage remote repository clones
USAGE:
ghq [global options] command [command options] [arguments...]
VERSION:
1.1.4 (rev:HEAD)
AUTHORS:
motemen <motemen@gmail.com>
Songmu <y.songmu@gmail.com>
COMMANDS:
get Clone/sync with a remote repository
list List local repositories
root Show repositories' root
create Create a new repository
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help (default: false)
--version, -v print the version (default: false)
```
よき
```bash
eai@MADAI:~$ ghq get https://github.com/DamionGans/ubuntu-wsl2-systemd-script
clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script -> /home/eai/ghq/github.com/DamionGans/ubuntu-wsl2-systemd-script
git clone --recursive https://github.com/DamionGans/ubuntu-wsl2-systemd-script /home/eai/ghq/github.com/DamionGans/ubuntu-wsl2-systemd-script
Cloning into '/home/eai/ghq/github.com/DamionGans/ubuntu-wsl2-systemd-script'...
remote: Enumerating objects: 82, done.
remote: Total 82 (delta 0), reused 0 (delta 0), pack-reused 82
Unpacking objects: 100% (82/82), 22.02 KiB | 159.00 KiB/s, done.
eai@MADAI:~$ cd ~/ghq/github.com/DamionGans/ubuntu-wsl2-systemd-script/
eai@MADAI:~/ghq/github.com/DamionGans/ubuntu-wsl2-systemd-script$
```
`bash ubuntu-wsl2-systemd-script.sh`をしてしばらく待って、再ログイン(`exit`,`wsl`)
ログイン後`ps aux`すると、PID 1がsystemdになっていることが確認できる
![](https://i.imgur.com/OTtIzEd.png)
Ubuntuに普通に入れるにはめんどくさいGitKrakenもsnapなら
```bash
eai@MADAI:/mnt/c/Users/Eai$ sudo snap install gitkraken --classic
[sudo] password for eai:
gitkraken 7.0.1 from gitkraken✓ installed
eai@MADAI:/mnt/c/Users/Eai$ gitkraken
(gitkraken:1712): Gtk-WARNING **: 13:59:55.197: cannot open display:
eai@MADAI:/mnt/c/Users/Eai$
```
はい。適当なX Window Serverが必要なので、ここではX410を入れる。入れた。多分VcXsrvでもいい。
[X410 を購入 - Microsoft Store ja-JP](https://www.microsoft.com/ja-jp/p/x410/9nlp712zmn9q)
こいついっつも4700円割引になってんな
それで、WSLからWindows 10に接続したい(IPアドレスを知りたい)わけで。
[【Windows10/WSL2 Ubuntu 20.04 LTS】X Serverアプリを実行する(Emacs GUI版を試す) | The modern stone age.](https://www.yokoweb.net/2020/06/12/windows10-wsl2-xserver-x410-emacs/)
> 母艦となっているWindowsに割り当てられたIPアドレスを直接使用してもよいのだが、WSL2の「/etc/resolv.conf」ファイルに自動的に追加される内部IPアドレスを使用する。このアドレスは、Windowsを再起動するか、WSL2を再起動すると変更される場合がある。したがって、そのファイルからアドレスを動的に抽出し、それをDISPLAY環境変数に割り当てておく。下記コマンドを、~/.bashrc に追加する。
賢い。先程環境変数は`.profile`に書くと決めたので、そうする。
```bash:.profile
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
```
`exit`,`wsl`
```bash
eai@MADAI:/mnt/c/Users/Eai$ echo $DISPLAY
192.168.112.1:0.0
```
よさそう
:::spoiler Snapを使わないことにしたので読まなくていい部分
```bash
eai@MADAI:/mnt/c/Users/Eai$ gitkraken
```
![](https://i.imgur.com/RzOpoLp.png)
ファイルマネージャー開こうとしたら落ちた
![](https://i.imgur.com/hs5t51S.png)
[Crash when accessing Check for Updates... or About from Help menu · Issue #100940 · microsoft/vscode](https://github.com/microsoft/vscode/issues/100940)
と同じくsnapの問題らしい
Openのままってことは、そういうことなんだろうなあ
とりあえずフォーラムに質問するか、このままにしておく。今後もできないようならsnapをやめて頑張って依存関係を解決しつつパッケージを入れるかもしれない。
ファイルマネージャーを開く際に問題が起きていてるみたい。Firefoxのほうが情報がありそうなので、出せるか試してみる。
```bash
eai@MADAI:/usr/lib$ firefox
(firefox:3025): Gtk-WARNING **: 15:01:14.611: Can't open portal file chooser: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.portal.Desktop was not provided by any .service files
```
やはりエラーが出た
[Firefox file chooser error on Neon 5.16 • KDE Community Forums](https://forum.kde.org/viewtopic.php?f=309&t=161249)
```bash
sudo apt install xdg-desktop-portal
```
```bash
eai@MADAI:/usr/lib$ firefox
(firefox:3952): Gtk-WARNING **: 15:03:06.224: Can't open portal file chooser: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.FileChooser” on object at path /org/freedesktop/portal/desktop
```
ちょっと変わった
:::
---
さて、結局Snapで入れてもファイルマネージャーが出せないことを愚痴ったらなんか普通にdebを入れればみたいに言われて、えーでも依存がめんどいって言ったらaptで依存解決できるとのこと
ほんまでござるか
(debはdpkgで入れるものだと思っていたがaptはdpkgのラッパーなのでより便利らしい)
```bash
eai@MADAI:~$ sudo apt install ./gitkraken-amd64.deb
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
gitkraken : Depends: gconf2 but it is not installed
Depends: gconf-service but it is not installed
Depends: libgtk2.0-0 but it is not installed
Depends: libnotify4 but it is not installed
Depends: libnss3 but it is not installed
Depends: gvfs-bin but it is not installed
Depends: xdg-utils but it is not installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
```
はい
```bash
eai@MADAI:~$ sudo apt install ./gitkraken-amd64.deb --fix-broken
# いろいろ
```
で入った。便利だ。
![](https://i.imgur.com/epGWXjd.png)
動いた。
snapの消す
```bash
eai@MADAI:~$ sudo snap remove firefox gitkraken
firefox removed
gitkraken removed
```
これで開発環境が整ったかもしれない
日本語フォント入れるの忘れてた
```bash
sudo apt install fonts-migmix
```
これだけで表示できるようになるのは便利。
dockerのグループに入れるのを忘れてた
```bash
sudo gpasswd -a $(whoami) docker
```
これをしないとdockerが使えない
### VSCode の Remote - WSLで接続した際、ワークスペースを開いたあとターミナルを起動すると/mnt/c/Users/Eai/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.4$で開かれる
DamionGans/ubuntu-wsl2-systemd-scriptのせいらしい
</details>
さて、ここまで書いた時点で最初に入れたDamionGans/ubuntu-wsl2-systemd-scriptが原因で問題が起きたので再セットアップですあーあ
結局snap使わないようにしたからいらないしね
まず更新
```bash
sudo apt update && sudo apt upgrade -y
```
### PATH切るやつ
さっき忘れてたやつ
[WSLでWindowsのPATHを引き継がないようにする方法 - Qiita](https://qiita.com/raccy/items/456a7158f588670c0850)
```bash
sudo nano /etc/wsl.conf
```
```
[interop]
appendWindowsPath = false
```
`exit`, `wsl`
```bash
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
```
よし
### ~/.profile
cmd.exeとdocker系のパスとGOPATHとDISPLAY
```bash:~/.profile
export PATH="$PATH:/mnt/c/Windows/System32"
export PATH="$PATH:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin"
export GOPATH="$HOME/.go"
export PATH="$PATH:$GOPATH/bin"
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
```
この時点で`docker version`とかが機能するはず
```bash
sudo gpasswd -a $(whoami) docker
```
### Go
```bash
sudo apt install golang-go
echo $GOPATH
# 確認
go get github.com/x-motemen/ghq
ghq
```
OK
### GitKraken
```bash
cd ~
wget https://release.gitkraken.com/linux/gitkraken-amd64.deb
sudo apt install gitkraken-amd64.deb
rm gitkraken-amd64.deb
```
```bash
gitkraken 1>/dev/null 2>/dev/null &
```
起動したのでOK
```bash
sudo apt install fonts-migmix
```