TOC
RPi4の初期設定の続きの設定です。
Raspberry Pi 4(RPi4)にUbuntu Server 20.10を導入。headless運用のための初期設定。
Argon Oneケースのファン・電源制御スクリプトのインストール
今回、Raspberry Pi 4のケースとしてArgon40のArgon Oneを購入して使用しているので、このケース用の制御スクリプトをインストールします。
Raspberry Pi 4(RPi4)とArgon Oneを購入。購入ルートと届くまでの顛末、組み立てまで。
Argon One Pi 4の電源ボタン仕様
状態 | 行動 | 動作 |
---|---|---|
OFF | 短押し | 電源ON |
ON | 長押し(3秒以上) | ソフトシャットダウンと電源断 |
ON | 短押し(3秒未満) | 何もしない |
ON | 2回押し | 再起動 |
ON | 長押し(5秒以上) | 強制電源断 |
Argon One Pi 4のファン速度
CPU温度 | ファン速度 |
---|---|
55℃ | 10% |
60℃ | 55% |
65℃ | 100% |
ファン速度についてはインストール後にargonone-config
で変更可能です。
スクリプトのインストール
$ curl https://download.argon40.com/argon1.sh | bash
一般ユーザーで実行しますが、sudoersに書かれているユーザーで実行する必要があります。
スクリプトの内容
2020/12時点のスクリプトは以下の通りです。
#!/bin/bash
argon_create_file() {
if [ -f $1 ]; then
sudo rm $1
fi
sudo touch $1
sudo chmod 666 $1
}
argon_check_pkg() {
RESULT=$(dpkg-query -W -f='${Status}\n' "$1" 2> /dev/null | grep "installed")
if [ "" == "$RESULT" ]; then
echo "NG"
else
echo "OK"
fi
}
CHECKPLATFORM="Others"
# Check if Raspbian, otherwise Ubuntu
grep -q -F 'Raspbian' /etc/os-release &> /dev/null
if [ $? -eq 0 ]
then
CHECKPLATFORM="Raspbian"
pkglist=(raspi-gpio python3-rpi.gpio python3-smbus i2c-tools)
else
# Ubuntu has serial and i2c enabled
pkglist=(python3-rpi.gpio python3-smbus i2c-tools)
fi
for curpkg in ${pkglist[@]}; do
sudo apt-get install -y $curpkg
RESULT=$(argon_check_pkg "$curpkg")
if [ "NG" == "$RESULT" ]
then
echo "********************************************************************"
echo "Please also connect device to the internet and restart installation."
echo "********************************************************************"
exit
fi
done
# Ubuntu Mate for RPi has raspi-config too
command -v raspi-config &> /dev/null
if [ $? -eq 0 ]
then
sudo raspi-config nonint do_i2c 0
sudo raspi-config nonint do_serial 0
fi
daemonname="argononed"
powerbuttonscript=/usr/bin/$daemonname.py
shutdownscript="/lib/systemd/system-shutdown/"$daemonname"-poweroff.py"
daemonconfigfile=/etc/$daemonname.conf
configscript=/usr/bin/argonone-config
removescript=/usr/bin/argonone-uninstall
daemonfanservice=/lib/systemd/system/$daemonname.service
if [ ! -f $daemonconfigfile ]; then
# Generate config file for fan speed
sudo touch $daemonconfigfile
sudo chmod 666 $daemonconfigfile
echo '#' >> $daemonconfigfile
echo '# Argon One Fan Configuration' >> $daemonconfigfile
echo '#' >> $daemonconfigfile
echo '# List below the temperature (Celsius) and fan speed (in percent) pairs' >> $daemonconfigfile
echo '# Use the following form:' >> $daemonconfigfile
echo '# min.temperature=speed' >> $daemonconfigfile
echo '#' >> $daemonconfigfile
echo '# Example:' >> $daemonconfigfile
echo '# 55=10' >> $daemonconfigfile
echo '# 60=55' >> $daemonconfigfile
echo '# 65=100' >> $daemonconfigfile
echo '#' >> $daemonconfigfile
echo '# Above example sets the fan speed to' >> $daemonconfigfile
echo '#' >> $daemonconfigfile
echo '# NOTE: Lines begining with # are ignored' >> $daemonconfigfile
echo '#' >> $daemonconfigfile
echo '# Type the following at the command line for changes to take effect:' >> $daemonconfigfile
echo '# sudo systemctl restart '$daemonname'.service' >> $daemonconfigfile
echo '#' >> $daemonconfigfile
echo '# Start below:' >> $daemonconfigfile
echo '55=10' >> $daemonconfigfile
echo '60=55' >> $daemonconfigfile
echo '65=100' >> $daemonconfigfile
fi
# Generate script that runs every shutdown event
argon_create_file $shutdownscript
echo "#!/usr/bin/python3" >> $shutdownscript
echo 'import sys' >> $shutdownscript
echo 'import smbus' >> $shutdownscript
echo 'import RPi.GPIO as GPIO' >> $shutdownscript
echo 'rev = GPIO.RPI_REVISION' >> $shutdownscript
echo 'if rev == 2 or rev == 3:' >> $shutdownscript
echo ' bus = smbus.SMBus(1)' >> $shutdownscript
echo 'else:' >> $shutdownscript
echo ' bus = smbus.SMBus(0)' >> $shutdownscript
echo 'if len(sys.argv)>1:' >> $shutdownscript
echo " bus.write_byte(0x1a,0)" >> $shutdownscript
# power cut signal
echo ' if sys.argv[1] == "poweroff" or sys.argv[1] == "halt":' >> $shutdownscript
echo " try:" >> $shutdownscript
echo " bus.write_byte(0x1a,0xFF)" >> $shutdownscript
echo " except:" >> $shutdownscript
echo " rev=0" >> $shutdownscript
sudo chmod 755 $shutdownscript
# Generate script to monitor shutdown button
argon_create_file $powerbuttonscript
echo "#!/usr/bin/python3" >> $powerbuttonscript
echo 'import smbus' >> $powerbuttonscript
echo 'import RPi.GPIO as GPIO' >> $powerbuttonscript
echo 'import os' >> $powerbuttonscript
echo 'import time' >> $powerbuttonscript
echo 'from threading import Thread' >> $powerbuttonscript
echo 'rev = GPIO.RPI_REVISION' >> $powerbuttonscript
echo 'if rev == 2 or rev == 3:' >> $powerbuttonscript
echo ' bus = smbus.SMBus(1)' >> $powerbuttonscript
echo 'else:' >> $powerbuttonscript
echo ' bus = smbus.SMBus(0)' >> $powerbuttonscript
echo 'GPIO.setwarnings(False)' >> $powerbuttonscript
echo 'GPIO.setmode(GPIO.BCM)' >> $powerbuttonscript
echo 'shutdown_pin=4' >> $powerbuttonscript
echo 'GPIO.setup(shutdown_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)' >> $powerbuttonscript
echo 'def shutdown_check():' >> $powerbuttonscript
echo ' while True:' >> $powerbuttonscript
echo ' pulsetime = 1' >> $powerbuttonscript
echo ' GPIO.wait_for_edge(shutdown_pin, GPIO.RISING)' >> $powerbuttonscript
echo ' time.sleep(0.01)' >> $powerbuttonscript
echo ' while GPIO.input(shutdown_pin) == GPIO.HIGH:' >> $powerbuttonscript
echo ' time.sleep(0.01)' >> $powerbuttonscript
echo ' pulsetime += 1' >> $powerbuttonscript
echo ' if pulsetime >=2 and pulsetime <=3:' >> $powerbuttonscript
echo ' os.system("reboot")' >> $powerbuttonscript
echo ' elif pulsetime >=4 and pulsetime <=5:' >> $powerbuttonscript
echo ' os.system("shutdown now -h")' >> $powerbuttonscript
echo 'def get_fanspeed(tempval, configlist):' >> $powerbuttonscript
echo ' for curconfig in configlist:' >> $powerbuttonscript
echo ' curpair = curconfig.split("=")' >> $powerbuttonscript
echo ' tempcfg = float(curpair[0])' >> $powerbuttonscript
echo ' fancfg = int(float(curpair[1]))' >> $powerbuttonscript
echo ' if tempval >= tempcfg:' >> $powerbuttonscript
echo ' return fancfg' >> $powerbuttonscript
echo ' return 0' >> $powerbuttonscript
echo 'def load_config(fname):' >> $powerbuttonscript
echo ' newconfig = []' >> $powerbuttonscript
echo ' try:' >> $powerbuttonscript
echo ' with open(fname, "r") as fp:' >> $powerbuttonscript
echo ' for curline in fp:' >> $powerbuttonscript
echo ' if not curline:' >> $powerbuttonscript
echo ' continue' >> $powerbuttonscript
echo ' tmpline = curline.strip()' >> $powerbuttonscript
echo ' if not tmpline:' >> $powerbuttonscript
echo ' continue' >> $powerbuttonscript
echo ' if tmpline[0] == "#":' >> $powerbuttonscript
echo ' continue' >> $powerbuttonscript
echo ' tmppair = tmpline.split("=")' >> $powerbuttonscript
echo ' if len(tmppair) != 2:' >> $powerbuttonscript
echo ' continue' >> $powerbuttonscript
echo ' tempval = 0' >> $powerbuttonscript
echo ' fanval = 0' >> $powerbuttonscript
echo ' try:' >> $powerbuttonscript
echo ' tempval = float(tmppair[0])' >> $powerbuttonscript
echo ' if tempval < 0 or tempval > 100:' >> $powerbuttonscript
echo ' continue' >> $powerbuttonscript
echo ' except:' >> $powerbuttonscript
echo ' continue' >> $powerbuttonscript
echo ' try:' >> $powerbuttonscript
echo ' fanval = int(float(tmppair[1]))' >> $powerbuttonscript
echo ' if fanval < 0 or fanval > 100:' >> $powerbuttonscript
echo ' continue' >> $powerbuttonscript
echo ' except:' >> $powerbuttonscript
echo ' continue' >> $powerbuttonscript
echo ' newconfig.append( "{:5.1f}={}".format(tempval,fanval))' >> $powerbuttonscript
echo ' if len(newconfig) > 0:' >> $powerbuttonscript
echo ' newconfig.sort(reverse=True)' >> $powerbuttonscript
echo ' except:' >> $powerbuttonscript
echo ' return []' >> $powerbuttonscript
echo ' return newconfig' >> $powerbuttonscript
echo 'def temp_check():' >> $powerbuttonscript
echo ' fanconfig = ["65=100", "60=55", "55=10"]' >> $powerbuttonscript
echo ' tmpconfig = load_config("'$daemonconfigfile'")' >> $powerbuttonscript
echo ' if len(tmpconfig) > 0:' >> $powerbuttonscript
echo ' fanconfig = tmpconfig' >> $powerbuttonscript
echo ' address=0x1a' >> $powerbuttonscript
echo ' prevblock=0' >> $powerbuttonscript
echo ' while True:' >> $powerbuttonscript
echo ' try:' >> $powerbuttonscript
echo ' tempfp = open("/sys/class/thermal/thermal_zone0/temp", "r")' >> $powerbuttonscript
echo ' temp = tempfp.readline()' >> $powerbuttonscript
echo ' tempfp.close()' >> $powerbuttonscript
echo ' val = float(int(temp)/1000)' >> $powerbuttonscript
echo ' except IOError:' >> $powerbuttonscript
echo ' val = 0' >> $powerbuttonscript
echo ' block = get_fanspeed(val, fanconfig)' >> $powerbuttonscript
echo ' if block < prevblock:' >> $powerbuttonscript
echo ' time.sleep(30)' >> $powerbuttonscript
echo ' prevblock = block' >> $powerbuttonscript
echo ' try:' >> $powerbuttonscript
echo ' bus.write_byte(address,block)' >> $powerbuttonscript
echo ' except IOError:' >> $powerbuttonscript
echo ' temp=""' >> $powerbuttonscript
echo ' time.sleep(30)' >> $powerbuttonscript
echo 'try:' >> $powerbuttonscript
echo ' t1 = Thread(target = shutdown_check)' >> $powerbuttonscript
echo ' t2 = Thread(target = temp_check)' >> $powerbuttonscript
echo ' t1.start()' >> $powerbuttonscript
echo ' t2.start()' >> $powerbuttonscript
echo 'except:' >> $powerbuttonscript
echo ' t1.stop()' >> $powerbuttonscript
echo ' t2.stop()' >> $powerbuttonscript
echo ' GPIO.cleanup()' >> $powerbuttonscript
sudo chmod 755 $powerbuttonscript
argon_create_file $daemonfanservice
# Fan Daemon
echo "[Unit]" >> $daemonfanservice
echo "Description=Argon One Fan and Button Service" >> $daemonfanservice
echo "After=multi-user.target" >> $daemonfanservice
echo '[Service]' >> $daemonfanservice
echo 'Type=simple' >> $daemonfanservice
echo "Restart=always" >> $daemonfanservice
echo "RemainAfterExit=true" >> $daemonfanservice
echo "ExecStart=/usr/bin/python3 $powerbuttonscript" >> $daemonfanservice
echo '[Install]' >> $daemonfanservice
echo "WantedBy=multi-user.target" >> $daemonfanservice
sudo chmod 644 $daemonfanservice
argon_create_file $removescript
# Uninstall Script
echo '#!/bin/bash' >> $removescript
echo 'echo "-------------------------"' >> $removescript
echo 'echo "Argon One Uninstall Tool"' >> $removescript
echo 'echo "-------------------------"' >> $removescript
echo 'echo -n "Press Y to continue:"' >> $removescript
echo 'read -n 1 confirm' >> $removescript
echo 'echo' >> $removescript
echo 'if [ "$confirm" = "y" ]' >> $removescript
echo 'then' >> $removescript
echo ' confirm="Y"' >> $removescript
echo 'fi' >> $removescript
echo '' >> $removescript
echo 'if [ "$confirm" != "Y" ]' >> $removescript
echo 'then' >> $removescript
echo ' echo "Cancelled"' >> $removescript
echo ' exit' >> $removescript
echo 'fi' >> $removescript
echo 'if [ -d "/home/pi/Desktop" ]; then' >> $removescript
echo ' sudo rm "/home/pi/Desktop/argonone-config.desktop"' >> $removescript
echo ' sudo rm "/home/pi/Desktop/argonone-uninstall.desktop"' >> $removescript
echo 'fi' >> $removescript
echo 'if [ -f '$powerbuttonscript' ]; then' >> $removescript
echo ' sudo systemctl stop '$daemonname'.service' >> $removescript
echo ' sudo systemctl disable '$daemonname'.service' >> $removescript
echo ' sudo /usr/bin/python3 '$shutdownscript' uninstall' >> $removescript
echo ' sudo rm '$powerbuttonscript >> $removescript
echo ' sudo rm '$shutdownscript >> $removescript
echo ' sudo rm '$removescript >> $removescript
echo ' echo "Removed Argon One Services."' >> $removescript
echo ' echo "Cleanup will complete after restarting the device."' >> $removescript
echo 'fi' >> $removescript
sudo chmod 755 $removescript
argon_create_file $configscript
# Config Script
echo '#!/bin/bash' >> $configscript
echo 'daemonconfigfile='$daemonconfigfile >> $configscript
echo 'echo "--------------------------------------"' >> $configscript
echo 'echo "Argon One Fan Speed Configuration Tool"' >> $configscript
echo 'echo "--------------------------------------"' >> $configscript
echo 'echo "WARNING: This will remove existing configuration."' >> $configscript
echo 'echo -n "Press Y to continue:"' >> $configscript
echo 'read -n 1 confirm' >> $configscript
echo 'echo' >> $configscript
echo 'if [ "$confirm" = "y" ]' >> $configscript
echo 'then' >> $configscript
echo ' confirm="Y"' >> $configscript
echo 'fi' >> $configscript
echo '' >> $configscript
echo 'if [ "$confirm" != "Y" ]' >> $configscript
echo 'then' >> $configscript
echo ' echo "Cancelled"' >> $configscript
echo ' exit' >> $configscript
echo 'fi' >> $configscript
echo 'echo "Thank you."' >> $configscript
echo 'get_number () {' >> $configscript
echo ' read curnumber' >> $configscript
echo ' re="^[0-9]+$"' >> $configscript
echo ' if [ -z "$curnumber" ]' >> $configscript
echo ' then' >> $configscript
echo ' echo "-2"' >> $configscript
echo ' return' >> $configscript
echo ' elif [[ $curnumber =~ ^[+-]?[0-9]+$ ]]' >> $configscript
echo ' then' >> $configscript
echo ' if [ $curnumber -lt 0 ]' >> $configscript
echo ' then' >> $configscript
echo ' echo "-1"' >> $configscript
echo ' return' >> $configscript
echo ' elif [ $curnumber -gt 100 ]' >> $configscript
echo ' then' >> $configscript
echo ' echo "-1"' >> $configscript
echo ' return' >> $configscript
echo ' fi ' >> $configscript
echo ' echo $curnumber' >> $configscript
echo ' return' >> $configscript
echo ' fi' >> $configscript
echo ' echo "-1"' >> $configscript
echo ' return' >> $configscript
echo '}' >> $configscript
echo '' >> $configscript
echo 'loopflag=1' >> $configscript
echo 'while [ $loopflag -eq 1 ]' >> $configscript
echo 'do' >> $configscript
echo ' echo' >> $configscript
echo ' echo "Select fan mode:"' >> $configscript
echo ' echo " 1. Always on"' >> $configscript
echo ' echo " 2. Adjust to temperatures (55C, 60C, and 65C)"' >> $configscript
echo ' echo " 3. Customize behavior"' >> $configscript
echo ' echo " 4. Cancel"' >> $configscript
echo ' echo "NOTE: You can also edit $daemonconfigfile directly"' >> $configscript
echo ' echo -n "Enter Number (1-4):"' >> $configscript
echo ' newmode=$( get_number )' >> $configscript
echo ' if [[ $newmode -ge 1 && $newmode -le 4 ]]' >> $configscript
echo ' then' >> $configscript
echo ' loopflag=0' >> $configscript
echo ' fi' >> $configscript
echo 'done' >> $configscript
echo 'echo' >> $configscript
echo 'if [ $newmode -eq 4 ]' >> $configscript
echo 'then' >> $configscript
echo ' echo "Cancelled"' >> $configscript
echo ' exit' >> $configscript
echo 'elif [ $newmode -eq 1 ]' >> $configscript
echo 'then' >> $configscript
echo ' echo "#" > $daemonconfigfile' >> $configscript
echo ' echo "# Argon One Fan Speed Configuration" >> $daemonconfigfile' >> $configscript
echo ' echo "#" >> $daemonconfigfile' >> $configscript
echo ' echo "# Min Temp=Fan Speed" >> $daemonconfigfile' >> $configscript
echo ' echo 1"="100 >> $daemonconfigfile' >> $configscript
echo ' sudo systemctl restart '$daemonname'.service' >> $configscript
echo ' echo "Fan always on."' >> $configscript
echo ' exit' >> $configscript
echo 'elif [ $newmode -eq 2 ]' >> $configscript
echo 'then' >> $configscript
echo ' echo "Please provide fan speeds for the following temperatures:"' >> $configscript
echo ' echo "#" > $daemonconfigfile' >> $configscript
echo ' echo "# Argon One Fan Speed Configuration" >> $daemonconfigfile' >> $configscript
echo ' echo "#" >> $daemonconfigfile' >> $configscript
echo ' echo "# Min Temp=Fan Speed" >> $daemonconfigfile' >> $configscript
echo ' curtemp=55' >> $configscript
echo ' while [ $curtemp -lt 70 ]' >> $configscript
echo ' do' >> $configscript
echo ' errorfanflag=1' >> $configscript
echo ' while [ $errorfanflag -eq 1 ]' >> $configscript
echo ' do' >> $configscript
echo ' echo -n ""$curtemp"C (0-100 only):"' >> $configscript
echo ' curfan=$( get_number )' >> $configscript
echo ' if [ $curfan -ge 0 ]' >> $configscript
echo ' then' >> $configscript
echo ' errorfanflag=0' >> $configscript
echo ' fi' >> $configscript
echo ' done' >> $configscript
echo ' echo $curtemp"="$curfan >> $daemonconfigfile' >> $configscript
echo ' curtemp=$((curtemp+5))' >> $configscript
echo ' done' >> $configscript
echo ' sudo systemctl restart '$daemonname'.service' >> $configscript
echo ' echo "Configuration updated."' >> $configscript
echo ' exit' >> $configscript
echo 'fi' >> $configscript
echo 'echo "Please provide fan speeds and temperature pairs"' >> $configscript
echo 'echo' >> $configscript
echo 'loopflag=1' >> $configscript
echo 'paircounter=0' >> $configscript
echo 'while [ $loopflag -eq 1 ]' >> $configscript
echo 'do' >> $configscript
echo ' errortempflag=1' >> $configscript
echo ' errorfanflag=1' >> $configscript
echo ' while [ $errortempflag -eq 1 ]' >> $configscript
echo ' do' >> $configscript
echo ' echo -n "Provide minimum temperature (in Celsius) then [ENTER]:"' >> $configscript
echo ' curtemp=$( get_number )' >> $configscript
echo ' if [ $curtemp -ge 0 ]' >> $configscript
echo ' then' >> $configscript
echo ' errortempflag=0' >> $configscript
echo ' elif [ $curtemp -eq -2 ]' >> $configscript
echo ' then' >> $configscript
echo ' errortempflag=0' >> $configscript
echo ' errorfanflag=0' >> $configscript
echo ' loopflag=0' >> $configscript
echo ' fi' >> $configscript
echo ' done' >> $configscript
echo ' while [ $errorfanflag -eq 1 ]' >> $configscript
echo ' do' >> $configscript
echo ' echo -n "Provide fan speed for "$curtemp"C (0-100) then [ENTER]:"' >> $configscript
echo ' curfan=$( get_number )' >> $configscript
echo ' if [ $curfan -ge 0 ]' >> $configscript
echo ' then' >> $configscript
echo ' errorfanflag=0' >> $configscript
echo ' elif [ $curfan -eq -2 ]' >> $configscript
echo ' then' >> $configscript
echo ' errortempflag=0' >> $configscript
echo ' errorfanflag=0' >> $configscript
echo ' loopflag=0' >> $configscript
echo ' fi' >> $configscript
echo ' done' >> $configscript
echo ' if [ $loopflag -eq 1 ]' >> $configscript
echo ' then' >> $configscript
echo ' if [ $paircounter -eq 0 ]' >> $configscript
echo ' then' >> $configscript
echo ' echo "#" > $daemonconfigfile' >> $configscript
echo ' echo "# Argon One Fan Speed Configuration" >> $daemonconfigfile' >> $configscript
echo ' echo "#" >> $daemonconfigfile' >> $configscript
echo ' echo "# Min Temp=Fan Speed" >> $daemonconfigfile' >> $configscript
echo ' fi' >> $configscript
echo ' echo $curtemp"="$curfan >> $daemonconfigfile' >> $configscript
echo ' ' >> $configscript
echo ' paircounter=$((paircounter+1))' >> $configscript
echo ' ' >> $configscript
echo ' echo "* Fan speed will be set to "$curfan" once temperature reaches "$curtemp" C"' >> $configscript
echo ' echo' >> $configscript
echo ' fi' >> $configscript
echo 'done' >> $configscript
echo '' >> $configscript
echo 'echo' >> $configscript
echo 'if [ $paircounter -gt 0 ]' >> $configscript
echo 'then' >> $configscript
echo ' echo "Thank you! We saved "$paircounter" pairs."' >> $configscript
echo ' sudo systemctl restart '$daemonname'.service' >> $configscript
echo ' echo "Changes should take effect now."' >> $configscript
echo 'else' >> $configscript
echo ' echo "Cancelled, no data saved."' >> $configscript
echo 'fi' >> $configscript
sudo chmod 755 $configscript
sudo systemctl daemon-reload
sudo systemctl enable $daemonname.service
sudo systemctl start $daemonname.service
shortcutfile="/home/pi/Desktop/argonone-config.desktop"
if [ "$CHECKPLATFORM" = "Raspbian" ] && [ -d "/home/pi/Desktop" ]
then
sudo wget http://download.argon40.com/ar1config.png -O /usr/share/pixmaps/ar1config.png --quiet
sudo wget http://download.argon40.com/ar1uninstall.png -O /usr/share/pixmaps/ar1uninstall.png --quiet
# Create Shortcuts
echo "[Desktop Entry]" > $shortcutfile
echo "Name=Argon One Configuration" >> $shortcutfile
echo "Comment=Argon One Configuration" >> $shortcutfile
echo "Icon=/usr/share/pixmaps/ar1config.png" >> $shortcutfile
echo 'Exec=lxterminal -t "Argon One Configuration" --working-directory=/home/pi/ -e '$configscript >> $shortcutfile
echo "Type=Application" >> $shortcutfile
echo "Encoding=UTF-8" >> $shortcutfile
echo "Terminal=false" >> $shortcutfile
echo "Categories=None;" >> $shortcutfile
chmod 755 $shortcutfile
shortcutfile="/home/pi/Desktop/argonone-uninstall.desktop"
echo "[Desktop Entry]" > $shortcutfile
echo "Name=Argon One Uninstall" >> $shortcutfile
echo "Comment=Argon One Uninstall" >> $shortcutfile
echo "Icon=/usr/share/pixmaps/ar1uninstall.png" >> $shortcutfile
echo 'Exec=lxterminal -t "Argon One Uninstall" --working-directory=/home/pi/ -e '$removescript >> $shortcutfile
echo "Type=Application" >> $shortcutfile
echo "Encoding=UTF-8" >> $shortcutfile
echo "Terminal=false" >> $shortcutfile
echo "Categories=None;" >> $shortcutfile
chmod 755 $shortcutfile
fi
# IR config script
sudo wget https://download.argon40.com/argonone-irconfig.sh -O /usr/bin/argonone-ir --quiet
sudo chmod 755 /usr/bin/argonone-ir
echo "***************************"
echo "Argon One Setup Completed."
echo "***************************"
echo
if [ ! "$CHECKPLATFORM" = "Raspbian" ]
then
echo "You may need to reboot for changes to take effect"
echo
fi
if [ -f $shortcutfile ]; then
echo Shortcuts created in your desktop.
else
echo Use 'argonone-config' to configure fan
echo Use 'argonone-uninstall' to uninstall
fi
echo
処理の概要はこんな感じです。
- OSがRaspbianかどうかを判別
- Raspbianの場合は raspi-gpio python3-rpi.gpio python3-smbus i2c-tools がインストールできるかチェック、それ以外の場合はUbuntuとして扱って python3-rpi.gpio python3-smbus i2c-tools がインストールできるか確認
- RaspbianとUbuntu Mate for RPi用にraspi-configコマンドでI2Cとシリアルを有効化する
/etc/argononed.conf
がない場合は作成/lib/systemd/system-shutdown/argononed-poweroff.py
ファイルを作成、実行権付与/usr/bin/argononed.py
ファイルを作成/lib/systemd/system/argononed.service
ファイルを作成/usr/bin/argonone-uninstall
ファイルを作成/usr/bin/argonone-config
ファイルを作成/lib/systemd/system/argononed.service
をsystemdで有効化、実行/usr/bin/argonone-ir
をダウンロード、実行権付与- Raspbianの場合、再起動を促す
ファンスピードのカスタマイズ
argonone-configコマンドを実行してみました。対話式で回転数を変更可能です。
$ argonone-config
--------------------------------------
Argon One Fan Speed Configuration Tool
--------------------------------------
WARNING: This will remove existing configuration.
Press Y to continue:Y
Thank you.
Select fan mode:
1. Always on
2. Adjust to temperatures (55C, 60C, and 65C)
3. Customize behavior
4. Cancel
NOTE: You can also edit /etc/argononed.conf directly
Enter Number (1-4):2
Please provide fan speeds for the following temperatures:
55C (0-100 only):20
60C (0-100 only):60
65C (0-100 only):100
Configuration updated.
$ argonone-config
--------------------------------------
Argon One Fan Speed Configuration Tool
--------------------------------------
WARNING: This will remove existing configuration.
Press Y to continue:Y
Thank you.
Select fan mode:
1. Always on
2. Adjust to temperatures (55C, 60C, and 65C)
3. Customize behavior
4. Cancel
NOTE: You can also edit /etc/argononed.conf directly
Enter Number (1-4):3
Please provide fan speeds and temperature pairs
Provide minimum temperature (in Celsius) then [ENTER]:30
Provide fan speed for 30C (0-100) then [ENTER]:10
* Fan speed will be set to 10 once temperature reaches 30 C
Provide minimum temperature (in Celsius) then [ENTER]:50
Provide fan speed for 50C (0-100) then [ENTER]:20
* Fan speed will be set to 20 once temperature reaches 50 C
Provide minimum temperature (in Celsius) then [ENTER]:60
Provide fan speed for 60C (0-100) then [ENTER]:60
* Fan speed will be set to 60 once temperature reaches 60 C
Provide minimum temperature (in Celsius) then [ENTER]:65
Provide fan speed for 65C (0-100) then [ENTER]:100
* Fan speed will be set to 100 once temperature reaches 65 C
Provide minimum temperature (in Celsius) then [ENTER]:
Thank you! We saved 4 pairs.
Changes should take effect now.
外付けHDDをsystemdで自動マウント
ストレージの自動マウントをSystemdで行う(AutoFSではなく)
dmesg
コマンドで接続したHDDを確認します。
[ 8729.111849] usb 1-1.3: new high-speed USB device number 5 using xhci_hcd
[ 8729.215859] usb 1-1.3: New USB device found, idVendor=1bcf, idProduct=0c31, bcdDevice= 1.0f
[ 8729.215875] usb 1-1.3: New USB device strings: Mfr=2, Product=3, SerialNumber=1
[ 8729.215886] usb 1-1.3: Product: USB to Serial-ATA bridge
[ 8729.215897] usb 1-1.3: Manufacturer: Sunplus Innovation Technology.
[ 8729.215908] usb 1-1.3: SerialNumber: FDC0FD20EA00000FD0FFAFA2104415
[ 8729.223947] usb-storage 1-1.3:1.0: USB Mass Storage device detected
[ 8729.224420] scsi host0: usb-storage 1-1.3:1.0
[ 8730.263363] scsi 0:0:0:0: Direct-Access WDC WD20 EARS-00MVWB0 PQ: 0 ANSI: 4
[ 8730.264881] sd 0:0:0:0: Attached scsi generic sg0 type 0
[ 8730.266616] sd 0:0:0:0: [sda] 3907029168 512-byte logical blocks: (2.00 TB/1.82 TiB)
[ 8730.272977] sd 0:0:0:0: [sda] Write Protect is off
[ 8730.272990] sd 0:0:0:0: [sda] Mode Sense: 38 00 00 00
[ 8730.279305] sd 0:0:0:0: [sda] No Caching mode page found
[ 8730.284797] sd 0:0:0:0: [sda] Assuming drive cache: write through
[ 8730.344744] sda: sda1
[ 8730.359064] sd 0:0:0:0: [sda] Attached SCSI disk
[ 8730.727034] BTRFS: device fsid f8d82e32-10ac-4c08-8969-457cf1ba04ac devid 1 transid 208450 /dev/sda1 scanned by systemd-udevd (3475)
UUIDを確認します。blkidコマンドは/dev/sda1を指定しても結果が得られませんでした。
$ ls -l /dev/disk/by-uuid/f8d82e32-10ac-4c08-8969-457cf1ba04ac
lrwxrwxrwx 1 root root 10 12月 22 06:41 /dev/disk/by-uuid/f8d82e32-10ac-4c08-8969-457cf1ba04ac -> ../../sda1
設定は以下の通りにします。
項目 | 設定値 |
---|---|
Description | USB HDD1 |
What | f8d82e32-10ac-4c08-8969-457cf1ba04ac |
Where | /mnt/usbhdd1 |
Type | btrfs |
名前 | usbhdd1 |
作成ファイル1 | /lib/systemd/system/mnt-usbhdd1.mount /lib/systemd/system/mnt-usbhdd1.automount |
マウントポイントを作成します。
# mkdir -p /mnt/usbhdd1
/lib/systemd/system/mnt-usbhdd1.mount
を作成します。
[Unit]
Description=USB HDD1
[Mount]
What=/dev/disk/by-uuid/f8d82e32-10ac-4c08-8969-457cf1ba04ac
Where=/mnt/usbhdd1
Type=btrfs
Options=defaults
[Install]
WantedBy=multi-user.target
/lib/systemd/system/mnt-usbhdd1.automount
を作成します。
[Unit]
Description=Automount USB HDD1
[Automount]
Where=/mnt/usbhdd1
[Install]
WantedBy=multi-user.target
systemdをリロードします。
# systemctl daemon-reload
automountを開始します。
# systemctl disable mnt-usbhdd1.mount
# systemctl enable mnt-usbhdd1.automount
Created symlink /etc/systemd/system/multi-user.target.wants/mnt-usbhdd1.automount → /lib/systemd/system/mnt-usbhdd1.automount.
# systemctl is-enabled mnt-usbhdd1.mount
disabled
# systemctl is-enabled mnt-usbhdd1.automount
enabled
# systemctl start mnt-usbhdd1.automount
マウントさせます。
$ ls /mnt/usbhdd1 > /dev/null
状態を確認します。
$ systemctl status mnt-usbhdd1.automount
● mnt-usbhdd1.automount - Automount USB HDD1
Loaded: loaded (/lib/systemd/system/mnt-usbhdd1.automount; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-12-22 06:40:50 JST; 37s ago
Triggers: ● mnt-usbhdd1.mount
Where: /mnt/usbhdd1
$ systemctl status mnt-usbhdd1.mount
● mnt-usbhdd1.mount - USB HDD1
Loaded: loaded (/lib/systemd/system/mnt-usbhdd1.mount; disabled; vendor preset: enabled)
Active: active (mounted) since Tue 2020-12-22 06:41:26 JST; 1min 29s ago
TriggeredBy: ● mnt-usbhdd1.automount
Where: /mnt/usbhdd1
What: /dev/sda1
Tasks: 0 (limit: 9255)
CGroup: /system.slice/mnt-usbhdd1.mount
apt-cacher-ngを設定
LAN内に設置するAPTのPull through proxyでAPTパッケージの重複ダウンロードを回避
# apt-get install apt-cacher-ng
/etc/apt-cacher-ng/acng.conf
を変更します。
--- /etc/apt-cacher-ng/acng.conf.org 2020-12-22 07:00:38.304826502 +0900
+++ /etc/apt-cacher-ng/acng.conf 2020-12-22 06:59:56.085933224 +0900
@@ -25,7 +25,8 @@
# Note: When the value for CacheDir is changed, change the file
# /lib/systemd/system/apt-cacher-ng.service too
#
-CacheDir: /var/cache/apt-cacher-ng
+#CacheDir: /var/cache/apt-cacher-ng
+CacheDir: /mnt/usbhdd1/var/apt-cacher
# Log file directory, can be set empty to disable logging
#
キャッシュディレクトリのオーナーをapt-cacher-ngユーザーに変更します。
# chown -R apt-cacher-ng:apt-cacher-ng /mnt/usbhdd1/var/apt-cacher/
apt-cacher-ngを再起動します。
# systemctl restart apt-cacher-ng
systemdの設定ファイルを変更用にコピーします。
# cp /lib/systemd/system/apt-cacher-ng.service /etc/systemd/system/
外付けHDDのマウントを待ち合わせます。
--- /etc/systemd/system/apt-cacher-ng.service.org 2020-12-22 06:54:04.253483236 +0900
+++ /etc/systemd/system/apt-cacher-ng.service 2020-12-22 06:55:40.823770241 +0900
@@ -1,6 +1,6 @@
[Unit]
Description=Apt-Cacher NG software download proxy
-After=network.target
+After=network.target mnt-usbhdd1.mount
# This can be used to ensure that the service starts only after delayed mount of
# the storage location.
# Note: when the CacheDir folder in configuration file(s) like in
systemdをリロードしてapt-cacher-ngを再起動します。
# systemctl daemon-reload
# systemctl restart apt-cacher-ng
/etc/apt/apt.conf.d/02cacher-ngを作成します。
Acquire::http::Proxy "http://127.0.0.1:3142/";
基準を20.10、必要に応じて21.04のパッケージを利用できるようにする
【非推奨】Ubuntuで一部のパッケージだけ将来のリリースから持ってくる
/etc/apt/apt.conf.d/01ubuntu-base
というファイルを作成します。
APT::Default-Release "groovy";
/etc/apt/sources.list.d/hirsute.list
という名前でapt-lineを記載します。
deb http://ports.ubuntu.com/ubuntu-ports hirsute main restricted universe multiverse
Podman/Cockpitをインストール
今、改めてUbuntuでPodmanを使う(2020年11月)
# apt-get install podman cockpit cockpit-podman
Ubuntu 20.10の現在のバージョンであるPodman2.0.6の場合、runcがインストールされないので別にインストールします。
# apt-get install runc
コンテナレジストリのポリシー設定をします。
$ mkdir ~/.config/containers
$ curl -L -o ~/.config/containers/policy.json https://raw.githubusercontent.com/containers/skopeo/master/default-policy.json
LAN内のコンテナレジストリ設定(平文)を~/.config/containers/registries.conf
に記載します。
[registries.search]
registries = ['docker.io', 'quay.io', '192.168.1.210:18080']
[registries.insecure]
registries = ["192.168.1.210:18080", "192.168.1.210:28080"]
コンテナ・イメージの格納場所を変更
$ podman system info | grep config
configFile: /home/hogehoge/.config/containers/storage.conf
格納場所を作成します。
# mkdir /mnt/usbhdd1/var/podman-image/
# chmod 777 /mnt/usbhdd1/var/podman-image/
~/.config/containers/storage.conf
を作成します。
[storage]
driver = "overlay"
graphroot = "/mnt/usbhdd1/var/podman-image/storage"
rootless_storage_path = "/mnt/usbhdd1/var/podman-image/storage-$UID"
[storage.options]
mount_program = "/usr/bin/fuse-overlayfs"
fuse-overlayfs
の設定はこれをしないとひたすら以下のエラーが出る為です。
Storing signatures
Error processing tar file(exit status 1): operation not permitted
反映を確認します。
$ podman system info | egrep '(graphRoot|volumePath)'
graphRoot: /mnt/usbhdd1/var/podman-image/storage-1001
volumePath: /mnt/usbhdd1/var/podman-image/storage-1001/volumes
Syncthingをインストール
マルチプラットフォームファイル同期ソフトSyncthingのご紹介
# curl -s https://syncthing.net/release-key.txt | apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
apt-keyは時代遅れだそうです…初めて知りました。
# echo "deb https://apt.syncthing.net/ syncthing stable" | tee /etc/apt/sources.list.d/syncthing.list
deb https://apt.syncthing.net/ syncthing stable
# apt-get update
# apt-get install syncthing
共有ディレクトリをUSB接続のHDDに作成し、Syncthingを実行するユーザーにオーナーを変更します。
# mkdir /mnt/usbhdd1/var/syncthing/
# chown hogehoge:hogehoge /mnt/usbhdd1/var/syncthing/
実行する一般ユーザーで作業します。
# su - hogehoge
$ mkdir -p ~/.config/systemd/user
$ cp -p /usr/lib/systemd/user/syncthing.service ~/.config/systemd/user/
systemdの設定ファイルをUSB接続のHDDが接続された後に起動するように変更します。
--- /home/hogehoge/.config/systemd/user/syncthing.service.org 2020-06-20 15:09:08.838546360 +0900
+++ /home/hogehoge/.config/systemd/user/syncthing.service 2020-06-20 15:09:27.499009171 +0900
@@ -1,6 +1,7 @@
[Unit]
Description=Syncthing - Open Source Continuous File Synchronization
Documentation=man:syncthing(1)
+After=mnt-usbhdd1.mount
[Service]
ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0
起動します。
$ systemctl --user enable syncthing.service
Created symlink /home/hogehoge/.config/systemd/user/default.target.wants/syncthing.service → /home/hogehoge/.config/systemd/user/syncthing.service.
$ systemctl --user start syncthing.service
$ systemctl --user status syncthing.service
● syncthing.service - Syncthing - Open Source Continuous File Synchronization
Loaded: loaded (/home/hogehoge/.config/systemd/user/syncthing.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-12-22 18:23:24 JST; 5s ago
Docs: man:syncthing(1)
Main PID: 2397 (syncthing)
CGroup: /user.slice/user-1001.slice/user@1001.service/syncthing.service
├─2397 /usr/bin/syncthing -no-browser -no-restart -logflags=0
└─2405 /usr/bin/syncthing -no-browser -no-restart -logflags=0
12月 22 18:23:27 ubuntu syncthing[2397]: [4YZIU] INFO: Loading HTTPS certificate: open /home/hogehoge/.config/syncthing>
12月 22 18:23:27 ubuntu syncthing[2397]: [4YZIU] INFO: Creating new HTTPS certificate
12月 22 18:23:27 ubuntu syncthing[2397]: [4YZIU] INFO: Relay listener (dynamic+https://relays.syncthing.net/endpoint) s>
12月 22 18:23:27 ubuntu syncthing[2397]: [4YZIU] INFO: Ready to synchronize "Default Folder" (default) (sendreceive)
12月 22 18:23:27 ubuntu syncthing[2397]: [4YZIU] INFO: QUIC listener ([::]:22000) starting
12月 22 18:23:27 ubuntu syncthing[2397]: [4YZIU] INFO: Completed initial scan of sendreceive folder "Default Folder" (d>
12月 22 18:23:27 ubuntu syncthing[2397]: [4YZIU] INFO: TCP listener ([::]:22000) starting
12月 22 18:23:27 ubuntu syncthing[2397]: [4YZIU] INFO: GUI and API listening on 127.0.0.1:8384
12月 22 18:23:27 ubuntu syncthing[2397]: [4YZIU] INFO: Access the GUI via the following URL: http://127.0.0.1:8384/
12月 22 18:23:27 ubuntu syncthing[2397]: [4YZIU] INFO: My name is "ubuntu"
ポートを引っ張ってSSH接続をします。
$ ssh -L 9999:localhost:8384 hogehoge@192.168.1.210
localhostの9999にRPi4の8384がバインドされているので、ブラウザからアクセスして設定します。
- デフォルトのフォルダーパスを外付けHDDに変更 (/mnt/usbhdd1/var/syncthing/)
スポンサーリンク
- すっかり忘れていましたが、Whereで指定したフルパスのディレクトリをハイフンに置換した文字列がファイル名になります(これ以外にするとWhereが間違っているというエラーが出ます) [return]
comments powered by Disqus