astrXbian/.install/update_bashrc.sh

45 lines
1.5 KiB
Bash
Raw Permalink Normal View History

2020-12-12 01:26:39 +01:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 2020.12.06
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
# update_bashrc.sh
# Add $YOU $IPFSNODEID $G1PUB to ~/.bashrc
2021-01-28 23:55:04 +01:00
XZUID="$1"
2020-12-12 01:26:39 +01:00
source ~/.bashrc
2020-12-16 21:27:39 +01:00
newYOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) || er+=" ipfs daemon not running"
newIPFSNODEID=$(ipfs id -f='<id>\n') || er+=" ipfs id problem"
[[ -f ~/.zen/secret.dunikey ]] && newG1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) || er+=" ~/.zen/secret.dunikey missing cannot find G1PUB"
2020-12-12 01:26:39 +01:00
[[ $er != "" ]] && echo "$er" && exit 1
2020-12-16 21:27:39 +01:00
if [[ $YOU != "" && $IPFSNODEID != "" && $G1PUB != "" ]]; then
# UPDATE
sed -i "s/YOU=$YOU/YOU=$newYOU/g" ~/.bashrc
sed -i "s/$G1PUB/$newG1PUB/g" ~/.bashrc
sed -i "s/$IPFSNODEID/$newIPFSNODEID/g" ~/.bashrc
2021-01-28 23:55:04 +01:00
2020-12-17 14:13:34 +01:00
if [[ $IPNSKEY == "_IPNSKEY_" ]]; then
ipfs key rm xbian
IPNSKEY=$(ipfs key gen xbian)
sed -i "s/_IPNSKEY_/$IPNSKEY/g" ~/.bashrc.sh
fi
2020-12-16 21:27:39 +01:00
else
# CREATE
2021-02-13 17:59:10 +01:00
echo "export PATH=$PATH:$HOME/.local/bin" >> ~/.bashrc
2020-12-16 21:27:39 +01:00
echo "### ASTROPORT IDENTITY ###" >> ~/.bashrc
2021-02-13 17:59:10 +01:00
echo "export YOU=$newYOU" >> ~/.bashrc
echo "export G1PUB=$newG1PUB" >> ~/.bashrc
echo "export IPFSNODEID=$newIPFSNODEID" >> ~/.bashrc
echo "IPNSKEY=_IPNSKEY_" >> ~/.bashrc
2021-01-29 00:51:31 +01:00
[[ "$XZUID" != "" ]] && echo "XZUID=$XZUID" >> ~/.bashrc
2020-12-16 21:27:39 +01:00
fi
2020-12-12 01:26:39 +01:00
source ~/.bashrc
echo "UPDATE ~/.bashrc OK"
tail -n 4 ~/.bashrc
exit 0