-
Notifications
You must be signed in to change notification settings - Fork 457
スクリプトによるRaspberry Pi設定の自動化 #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
df3aec5
/boot/firmware/confit.txtにdtoverlayとdtparamを追記するスクリプトを作成
KuraZuzu 4625ff3
カーネルのバージョンに応じてdtoverlayの設定を挿入するかの分岐条件を追加
KuraZuzu b561e60
spiとi2cをonにする処理を追加
KuraZuzu d5aa88a
OSが32bit版であれば"arm_64bit=0"を追記するように変更
KuraZuzu 83c5af9
Raspberry Pi Mouse V3の設定である旨のコメントを追記する処理追加
KuraZuzu af8636b
Merge branch 'master' into feature/setting-configs
KuraZuzu de06624
READMEを整備し、設定スクリプトをshからbashに変更
KuraZuzu 8035705
config.txtに追記する手順の説明方法を以前からあるものに統一した
KuraZuzu 2b08247
arm_64bit=0追記時のメッセージ標準出力で最初に無駄なスペースが入る点を修正
KuraZuzu 6125959
"dtparam=i2c_arm=on"と"dtparam=spi=on"の戦闘に#が付いてコメント担っていた場合は解除するように修正
KuraZuzu cce3fcc
動作しているOSのbit数を判定するコマンドを修正(uname -mだとRaspberry Pi OSの32bitでも64bitと同じ結果…
KuraZuzu 0cbb89e
64bitOSなのにarm_64bit=0が合った場合に削除するよう変更
KuraZuzu 524c6e9
カーネルバージョンの比較が正しく行われていなかったため、整数に変換して比較するように変更
KuraZuzu cd239dc
Merge branch 'master' into feature/setting-configs
KuraZuzu 92e12c2
UbuntuとRaspberry Pi OSでカーネルヘッダーの手順が違うのでREADMEを修正
KuraZuzu bae52c3
CI結果のバッチを修正
KuraZuzu 374da7c
README.mdの文中の無駄な空白を削除
KuraZuzu 90cd60d
リポジトリのcloneとRaspberry Piの設定を行う項目の説明を修正
KuraZuzu f1b74a0
"/dev/null"へのリダイレクトを">"に統一
KuraZuzu 606e958
カーネルバージョンを扱う箇所を変更
KuraZuzu 5d1935f
カーネルバージョン比較のときに整数にしている理由とマイナーバージョンのゼロ埋めについてコメントを追記
KuraZuzu a17dc19
設定に関していくつか変更を加えました。
KuraZuzu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
# settings comment | ||
SETTING_COMMENT='# Raspberry Pi Mouse V3 settings' | ||
|
||
# OS architecture (32-bit or 64-bit) | ||
ARCHITECTURE=$(getconf LONG_BIT) | ||
|
||
# dtoverlay setting | ||
DTOVERLAY='dtoverlay=anyspi:spi0-0,dev="microchip,mcp3204",speed=1000000' | ||
|
||
# i2c_baudrate-setting | ||
DTPARAM='dtparam=i2c_baudrate=62500' | ||
|
||
# config-file PATH | ||
CONFIG_FILE='/boot/firmware/config.txt' | ||
|
||
# compare kernel versions as integers for accurate version comparison (excluding minor versions). | ||
GET_KERNEL_VERSION_INT() { | ||
# 0-padding is used to avoid minor versions being compared by their first digit. | ||
echo "$1" | awk -F. '{ printf "%d%02d", $1, $2 }' | ||
} | ||
|
||
# kernel version | ||
KERNEL_VERSION=$(uname -r | cut -d'-' -f1) | ||
KERNEL_VERSION_INT=$(GET_KERNEL_VERSION_INT "$KERNEL_VERSION") | ||
|
||
# add "Raspberry Pi Mouse v3" settings | ||
if ! grep -qxF "$SETTING_COMMENT" "$CONFIG_FILE"; then | ||
echo "$SETTING_COMMENT" | sudo tee -a "$CONFIG_FILE" > /dev/null | ||
fi | ||
|
||
# check if the OS is running in 32-bit mode | ||
if [[ "$ARCHITECTURE" == "32" ]]; then | ||
if ! grep -qxF "arm_64bit=0" "$CONFIG_FILE"; then | ||
echo "arm_64bit=0" | sudo tee -a "$CONFIG_FILE" | ||
echo "Add \"arm_64bit=0\" > $CONFIG_FILE" | ||
fi | ||
elif [[ "$ARCHITECTURE" == "64" ]]; then | ||
# remove arm_64bit=0 if present in a 64-bit environment | ||
if grep -qxF "arm_64bit=0" "$CONFIG_FILE"; then | ||
sudo sed -i '/arm_64bit=0/d' "$CONFIG_FILE" | ||
echo "Removed \"arm_64bit=0\" from $CONFIG_FILE" | ||
fi | ||
fi | ||
|
||
# add dtparam-setting for "/boot/firmware/config.txt" | ||
if ! grep -qxF "$DTPARAM" "$CONFIG_FILE"; then | ||
echo "$DTPARAM" | sudo tee -a "$CONFIG_FILE" > /dev/null | ||
echo "Add \"$DTPARAM\" > $CONFIG_FILE" | ||
fi | ||
|
||
# use device-tree-overlay when the kernel is 5.16 or higher | ||
if (( KERNEL_VERSION_INT >= $(GET_KERNEL_VERSION_INT 5.16) )); then | ||
# add dtoverlay-setting for "/boot/firmware/config.txt" | ||
if ! grep -qxF "$DTOVERLAY" "$CONFIG_FILE"; then | ||
echo "$DTOVERLAY" | sudo tee -a "$CONFIG_FILE" > /dev/null | ||
echo "Add \"$DTOVERLAY\" > $CONFIG_FILE" | ||
fi | ||
else | ||
# remove dtoverlay-setting if kernel is less than 5.16 | ||
if grep -qxF "$DTOVERLAY" "$CONFIG_FILE"; then | ||
sudo sed -i "/$DTOVERLAY/d" "$CONFIG_FILE" | ||
echo "Removed \"$DTOVERLAY\" from $CONFIG_FILE" | ||
fi | ||
fi | ||
|
||
# replace "dtparam=i2c_arm=off" with "dtparam=i2c_arm=on" | ||
if grep -qxF 'dtparam=i2c_arm=off' "$CONFIG_FILE"; then | ||
sudo sed -i 's/dtparam=i2c_arm=off/dtparam=i2c_arm=on/' "$CONFIG_FILE" | ||
echo "Changed \"dtparam=i2c_arm=off\" to \"dtparam=i2c_arm=on\" in $CONFIG_FILE" | ||
fi | ||
|
||
# replace "dtparam=spi=off" with "dtparam=spi=on" | ||
if grep -qxF 'dtparam=spi=off' "$CONFIG_FILE"; then | ||
sudo sed -i 's/dtparam=spi=off/dtparam=spi=on/' "$CONFIG_FILE" | ||
echo "Changed \"dtparam=spi=off\" to \"dtparam=spi=on\" in $CONFIG_FILE" | ||
fi | ||
|
||
# uncomment "dtparam=i2c_arm=on" if it is commented | ||
if grep -qxF '#dtparam=i2c_arm=on' "$CONFIG_FILE"; then | ||
sudo sed -i 's/#dtparam=i2c_arm=on/dtparam=i2c_arm=on/' "$CONFIG_FILE" | ||
echo "Uncommented \"dtparam=i2c_arm=on\" in $CONFIG_FILE" | ||
fi | ||
|
||
# uncomment "dtparam=spi=on" if it is commented | ||
if grep -qxF '#dtparam=spi=on' "$CONFIG_FILE"; then | ||
sudo sed -i 's/#dtparam=spi=on/dtparam=spi=on/' "$CONFIG_FILE" | ||
echo "Uncommented \"dtparam=spi=on\" in $CONFIG_FILE" | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.