私は、ネットワークの一時的なメンバーと呼ぶ Linux コンピューター (以降「ノード」) を持っています。ノードは車両に取り付けられており、頻繁に Wi-Fi カバレッジに出入りします。
もちろん、単一のスクリプト、プログラム、またはファイルの更新をすべてのノードにプッシュすることは、多くの場合有益です。私が思いついたのはこれです:
- すべてのノードで共有されるキー ペアを生成する
- ワークステーションで、インストール パスを含むヘッダーを使用して、新しいファイル バージョンを暗号化します。もちろん、私のワークステーションには公開鍵があります。
- 暗号化された更新を、ノードからアクセス可能なネットワークの「ステージング」フォルダーに配置します
- ノードは、接続が良好であることを検出すると、ステージング フォルダーをチェックします。
- 新しいファイルがある場合、それらは次のとおりです。
- ノードにコピーされました
- 解読した
- 整合性をチェックしました(「ファイルヘッダーは適切に見えますか?」)
- ヘッダーで指定された場所に移動
これが私のコードの簡単なバージョンです。これは悪い考えですか?非常に不安定な接続で無人ノードの更新に対処するよりエレガントな方法はありますか?
#!/bin/bash
#A method for autonomously retrieving distributed updates
#The latest and greatest files are here:
stageDir="/remoteDirectory/stage"
#Files are initially moved to a quarantine area
qDir="/localDirectory/quarantine"
#If all went well, put a copy of the encrypted file here:
aDir="/localDirectory/pulled"
#generic extension for encrypted files "Secure Up Date"
ext="sud"
for file in "$stageDir"/*."$ext"; do #For each "sud" file...
fname=$(basename $file)
if [ ! -f $aDir/$fname ]; then #If this file has not already been worked on...
cp "$file" "$qDir"/"$fname" #Move it to the quarantine directory
else
echo "$fname has already been pulled" #Move along
fi
done
if [ "$(ls $qDir)" ]; then #If there's something to do (i.e. files in the directory)
for file in "$qDir"/*."$ext"; do
fname=$(basename $file)
qPath="$qDir/$fname"
untrusted="$qPath.untrusted"
#Decrypt file
gpg --output "$untrusted" --yes --passphrase "supersecretpassphrase" --decrypt "$qPath" #Say yes to overwriting
headline=$(head -n 1 $untrusted) #Get the header (which is the first line of the file)
#Check to see if this is a valid file
if [[ $headline == "#LOOKSGOOD:"* ]]; then #All headers must start with "#LOOKSGOOD:" or something
#Get install path
installPath=$(echo $headline | cut -d ':' -f 2) #Get the stuff after the colon
tail -n +2 $untrusted > $installPath #Send everything but the header line to the install path
#Clean up our working files
rm $untrusted
mv $qPath "$aDir/$fname"
#Report what we did
echo $headline
else
#trash the file if it's not a legit file
echo "$fname is not a legit update...trashing it"
rm "$qDir/$fname"*
fi
done
fi