diff --git a/README.md b/README.md index fd4a197..1235b8d 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,8 @@ ``` $ curl -sL https://github.com/dev-satoshi/dotfiles/install.sh | sh ``` + +## Update +``` +$ curl -sL https://github.com/dev-satoshi/dotfiles/update.sh | sh +``` diff --git a/asdf/.tool-versions b/asdf/.tool-versions index 92efda0..5dd0340 100644 --- a/asdf/.tool-versions +++ b/asdf/.tool-versions @@ -1,10 +1,10 @@ -ruby 3.3.4 awscli 2.16.5 flutter 3.29.2-stable gradle 8.4 java openjdk-17.0.2 +kotlin 2.1.10 nodejs 20.12.2 pre-commit 3.7.1 -yarn 1.22.22 -kotlin 2.1.10 +ruby 3.3.4 rust 1.85.1 +yarn 1.22.22 diff --git a/scripts/asdf_setup.sh b/scripts/asdf_setup.sh old mode 100644 new mode 100755 index 0d19ed7..ca1afb3 --- a/scripts/asdf_setup.sh +++ b/scripts/asdf_setup.sh @@ -3,15 +3,24 @@ set -euo pipefail echo "「ASDF」のセットアップを開始しました" -# プラグインを出力 -asdf plugin list --urls > ~/dotfiles/asdf/plugins.txt - # プラグインをインストール -while read -r name url; do - asdf plugin add "$name" "$url" || true +while IFS=$' \t' read -r name url; do + asdf plugin add "$name" "$url" >/dev/null 2>&1 || true done < ~/dotfiles/asdf/plugins.txt -# 一括インストール -asdf install +# .tool-versionsに書いてある全てのバージョンをインストール +while IFS= read -r line; do + # 空行スキップ + [[ -z "$line" ]] && continue + + # 先頭の単語がプラグイン名、残りがバージョン一覧 + set -- "$line" + plugin=$1 + shift + for version in "$@"; do + echo "→ Installing $plugin $version" + asdf install "$plugin" "$version" + done +done < ~/dotfiles/asdf/.tool-versions echo "「ASDF」のセットアップが完了しました" diff --git a/scripts/update/asdf_update.sh b/scripts/update/asdf_update.sh new file mode 100644 index 0000000..0bd8f83 --- /dev/null +++ b/scripts/update/asdf_update.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env zsh +set -euo pipefail + +echo "「ASDF」のアップデートを開始しました" + +# プラグインを出力 +asdf plugin list --urls > "$HOME/dotfiles/asdf/plugins.txt" + +# 出力先ディレクトリがなければ作成 +mkdir -p "$HOME/dotfiles/asdf" + +# .tool-versionsを初期化 +: > "$HOME/dotfiles/asdf/.tool-versions" + +# 各プラグインの全バージョンを取得して出力 +for plugin in $(asdf plugin list); do + # 空行はスキップ + [[ -z "$plugin" ]] && continue + + # バージョンリスト取得&整形(行頭の空白、*、空行を削除) + versions=$(asdf list "$plugin" 2>/dev/null \ + | sed -e 's/^[[:space:]]*\*\?[[:space:]]*//' -e '/^$/d') + + # それぞれのバージョンを.tool-versionsに出力 + for version in $versions; do + echo "$plugin $version" >> "$HOME/dotfiles/asdf/.tool-versions" + done +done + +echo "「ASDF」のアップデートが完了しました" diff --git a/scripts/update/update.sh b/scripts/update/update.sh new file mode 100644 index 0000000..a222f0b --- /dev/null +++ b/scripts/update/update.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env zsh +set -euo pipefail + +echo "「dotfiles」のアップデートを開始しました" + +INSTALL_DIR="$HOME/dotfiles" + +sh "$INSTALL_DIR/scripts/update/asdf_update.sh" + +echo "「dotfiles」のアップデートが完了しました" diff --git a/update.sh b/update.sh new file mode 100644 index 0000000..0c1aad4 --- /dev/null +++ b/update.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env zsh +set -euo pipefail + +INSTALL_DIR="$HOME/dotfiles" + +if [ ! -d "$INSTALL_DIR" ]; then + echo "dotfiles not found in $INSTALL_DIR" + echo "Please run 'install.sh' first." + exit 1 +fi + +echo "Updating dotfiles..." +git -C "$INSTALL_DIR" pull + +sh "$INSTALL_DIR/scripts/update/update.sh"