Ubuntu 21.10にKindleをインストール

# TL;DR
```bash
sudo apt purge -y 'wine*' \
  && sudo dpkg --add-architecture i386 \
  && wget -qO - https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add - \
  && sudo add-apt-repository -y "deb https://dl.winehq.org/wine-builds/ubuntu/ $(lsb_release -cs) main" \
  && sudo apt update \
  && wine_version=staging \
  && sudo apt install --install-recommends -y winehq-$wine_version winetricks \
  && mono_version=$(iconv -cfutf16 /opt/wine-$wine_version/lib64/wine/x86_64-windows/appwiz.cpl 2>/dev/null | grep -Pao '(?<=wine-mono-).+(?=-x86\.msi)') \
  && gecko_version=$(iconv -cfutf16 /opt/wine-$wine_version/lib64/wine/x86_64-windows/appwiz.cpl 2>/dev/null | grep -Pao '(?<=wine-gecko-).+(?=-x86_64\.msi)') \
  && mkdir -p ~/.cache/wine \
  && wget -nc https://dl.winehq.org/wine/wine-mono/$mono_version/wine-mono-$mono_version-x86.msi https://dl.winehq.org/wine/wine-gecko/$gecko_version/wine-gecko-$gecko_version-x86{,_64}.msi -P ~/.cache/wine/ \
  && winetricks -q cjkfonts vcrun2013 \
  && mkdir -p "$HOME/.wine/drive_c/users/$USER/AppData/Local/Amazon/Kindle" \
  && wget -nc --trust-server-names http://www.amazon.co.jp/kindlepcdownload \
  && wine KindleForPC-installer-*.exe
```

## 既存のWineを削除
```bash
sudo apt purge -y 'wine*'
```

## Wineをインストール
```bash
sudo dpkg --add-architecture i386 \
  && wget -qO - https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add - \
  && sudo add-apt-repository -y "deb https://dl.winehq.org/wine-builds/ubuntu/ $(lsb_release -cs) main" \
  && sudo apt update \
  && wine_version=staging \
  && sudo apt install --install-recommends -y winehq-$wine_version winetricks
```

[wine-stable 6.0.2 build fails in Ubuntu 21.10](https://bugs.winehq.org/show_bug.cgi?id=51932) が解決されたらwine-stableが使えると思います。

## MonoとGeckoのインストーラをダウンロード
```bash
mono_version=$(iconv -cfutf16 /opt/wine-$wine_version/lib64/wine/x86_64-windows/appwiz.cpl 2>/dev/null | grep -Pao '(?<=wine-mono-).+(?=-x86\.msi)') \
  && gecko_version=$(iconv -cfutf16 /opt/wine-$wine_version/lib64/wine/x86_64-windows/appwiz.cpl 2>/dev/null | grep -Pao '(?<=wine-gecko-).+(?=-x86_64\.msi)') \
  && mkdir -p ~/.cache/wine \
  && wget -nc https://dl.winehq.org/wine/wine-mono/$mono_version/wine-mono-$mono_version-x86.msi https://dl.winehq.org/wine/wine-gecko/$gecko_version/wine-gecko-$gecko_version-x86{,_64}.msi -P ~/.cache/wine/
```
インストーラをダウンロードすることで以下のダイアログを省略できます。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208363/37478de6-8c15-481c-e7b2-4a7c118d2654.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208363/c6441f5a-68de-d0e0-ffba-b591a32cfd88.png)

## 日本語フォントをインストール
文字化けが起きなくなります。vcrun2013でmfc120のエラーがなくなると思います。

```bash
winetricks -q cjkfonts vcrun2013
```

## Kindleディレクトリを作成
[Multiple applications and games need support for Windows Vista+ User Shell Folder layout, specifically 'Local AppData' (Amazon Kindle for PC)](https://bugs.winehq.org/show_bug.cgi?id=46320)

```bash
mkdir -p "$HOME/.wine/drive_c/users/$USER/AppData/Local/Amazon/Kindle"
```

## Kindleをダウンロード
```bash
wget -nc --trust-server-names http://www.amazon.co.jp/kindlepcdownload
```

## Kindleをインストール
```bash
wine KindleForPC-installer-*.exe
```

## エビデンス
<iframe width="560" height="315" src="https://www.youtube.com/embed/FH7Th4fLAoQ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>