astrXbian/ISOconfig.sh

209 lines
9.2 KiB
Bash
Raw Normal View History

2020-12-12 01:26:39 +01:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 2020.12.05
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
# AUTOMATIC version of interactive 1stRUNconfig.sh
# This script can run from ~/.config/autostart/Astroport_X_config.desktop
#
########################################################################
# Create secret key files
# ~/.zen/secret.june
# ~/.zen/secret.dunikey
# ~/.zen/secret.ipfs & /tmp/config.ipfs
# ~/.zen/ipfs.sync
########################################################################
# CHECK IF CONFIG ALREADY DONE !! Remove ~/.zen/ipfs ~/.zen/secret ~/.zen/ipfs.sync
if [[ -f ~/.zen/ipfs.sync ]]; then
echo "CONFIG ALREADY DONE"
source ~/.zen/ipfs.sync
2020-12-14 04:40:06 +01:00
2020-12-12 01:26:39 +01:00
# NEW BOOT! SEND ipfstryme message to my friends...
2020-12-12 01:43:01 +01:00
cd ~/.zen/astrXbian/zen/jaklis
2020-12-12 01:26:39 +01:00
# GET LIST of issuer(s) who likes me
for liking_me in $(./jaklis.py like | jq -r '.likes[].issuer');
do
# CHECk if I am liking him either
friend_of_mine=$(./jaklis.py like -p $liking_me | jq -r '.yours');
echo "Sending IPFSTRYME message to $liking_me"
[[ $friend_of_mine != null ]] && ./jaklis.py send -d $liking_me -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
done
cd -
exit 0
fi
# CHECK INTERNET CONNECTIVITY !!
ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || (echo "NO INTERNET CONNEXION" && exit 1)
########################################################################
########################################################################
echo "CREATING Gchange credentials"
########################################################################
2020-12-12 01:43:01 +01:00
salt="$(~/.zen/astrXbian/zen/tools/diceware.sh 3 | xargs)"
2020-12-12 01:26:39 +01:00
[[ $salt == "" ]] && echo "ERROR" && exit 1
2020-12-12 01:43:01 +01:00
pepper="$(~/.zen/astrXbian/zen/tools/diceware.sh 3 | xargs)"
2020-12-12 01:26:39 +01:00
g1_salt="$salt"
g1_pepper="$pepper"
echo "CREATING /tmp/secret.june"
echo "$g1_salt" > /tmp/secret.june
echo "$g1_pepper" >> /tmp/secret.june
########################################################################
########################################################################
echo "CREATING /tmp/secret.dunikey"
########################################################################
2020-12-12 01:43:01 +01:00
python3 ~/.zen/astrXbian/zen/tools/key_create_dunikey.py "$g1_salt" "$g1_pepper"
2020-12-12 01:26:39 +01:00
g1pub=$(cat /tmp/secret.dunikey | grep "pub" | cut -d ' ' -f 2)
g1sec=$(cat /tmp/secret.dunikey | grep "sec" | cut -d ' ' -f 2)
########################################################################
########################################################################
echo "CREATING /tmp/config.ipfs"
########################################################################
2020-12-12 01:43:01 +01:00
ipfs_ID=$(python3 ~/.zen/astrXbian/zen/tools/create_ipfsnodeid_from_tmp_secret.dunikey.py)
2020-12-12 01:26:39 +01:00
echo $ipfs_ID > /tmp/secret.ipfs && source /tmp/secret.ipfs
[[ $PrivKEY == "" ]] && echo "ERROR" && exit 1
jq -r --arg PeerID "$PeerID" '.Identity.PeerID=$PeerID' ~/.ipfs/config > /tmp/config.tmp
jq -r --arg PrivKEY "$PrivKEY" '.Identity.PrivKey=$PrivKEY' /tmp/config.tmp > /tmp/config.ipfs
rm /tmp/config.tmp
#
IPFSNODEID=$PeerID
echo $IPFSNODEID
## Declare directory transfered in IPFS
IPFS_sync_directory="$HOME/astroport"
########################################################################
# INSTALL KEYS
########################################################################
2020-12-12 21:41:05 +01:00
[[ -f ~/.zen/secret.june ]] && mv ~/.zen/secret.june ~/.zen/secret.june.old
2020-12-12 01:26:39 +01:00
mv /tmp/secret.june ~/.zen/secret.june
2020-12-12 21:41:05 +01:00
[[ -f ~/.zen/secret.dunikey ]] && mv ~/.zen/secret.dunikey ~/.zen/secret.dunikey.old
2020-12-12 01:26:39 +01:00
mv /tmp/secret.dunikey ~/.zen/secret.dunikey
2020-12-12 21:41:05 +01:00
[[ -f ~/.zen/secret.ipfs ]] && mv ~/.zen/secret.ipfs ~/.zen/secret.ipfs.old
2020-12-12 01:26:39 +01:00
mv /tmp/secret.ipfs ~/.zen/secret.ipfs
2020-12-12 21:41:05 +01:00
[[ -f ~/.ipfs/config ]] && mv ~/.ipfs/config ~/.ipfs/config.old
2020-12-12 01:26:39 +01:00
mv /tmp/config.ipfs ~/.ipfs/config
########################################################################
echo "INIT ~/.zen/ipfs/.${IPFSNODEID}"
########################################################################
rm -Rf ~/.zen/ipfs
mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/G1SSB
########################################################################
# Give $XZUID to your (gchange friends) to add in Vstream Astroport and access your sharings
# IPNS link to "pastebin list" http://localhost:8181/ipns/$IPNSKEY/xbian/$XZUID
2020-12-12 01:26:39 +01:00
########################################################################
2020-12-14 01:11:38 +01:00
XZUID=$(~/.zen/astrXbian/zen/tools/diceware.sh 1 | xargs)$(hostname -I | cut -d ' ' -f 1 | cut -d "." -f 4)$(~/.zen/astrXbian/zen/tools/diceware.sh 1 | xargs)
2020-12-12 01:26:39 +01:00
echo "CREATE ~/.zen/ipfs/xbian/$XZUID"
2020-12-12 16:18:46 +01:00
mkdir -p ~/.zen/ipfs/xbian
2020-12-12 01:26:39 +01:00
touch ~/.zen/ipfs/xbian/$XZUID
# https://github.com/Kodi-vStream/venom-xbmc-addons/wiki/Voir-et-partager-sa-biblioth%C3%A8que-priv%C3%A9e#d%C3%A9clarer-des-films
echo "$XZUID" > ~/.zen/ipfs/.${IPFSNODEID}/_xbian.zuid
########################################################################
########################################################################
2020-12-12 02:11:42 +01:00
echo "CREATE + profile"
2020-12-12 01:26:39 +01:00
########################################################################
2020-12-12 01:43:01 +01:00
cd ~/.zen/astrXbian/zen/jaklis
2020-12-14 01:11:38 +01:00
./jaklis.py -n "https://g1.data.e-is.pro" set --name "$XZUID" --avatar "/home/xbian/.zen/astrXbian/logo.png" #CESIUM+
./jaklis.py -n "https://data.gchange.fr" set --name "$XZUID" --avatar "/home/xbian/.zen/astrXbian/logo.png" #GCHANGE+
2020-12-12 01:26:39 +01:00
########################################################################
########################################################################
echo "BECOME FRIEND with oasis (1st bootstrap)"
########################################################################
2020-12-12 19:05:05 +01:00
./jaklis.py -n "https://g1.data.e-is.pro" like -p 2jQUH4HfHxdTesjCjvMCx1VJgA5AnpuvrWRq1swfRdsS -s 5
2020-12-12 16:53:39 +01:00
./jaklis.py -n "https://data.gchange.fr" like -p 2jQUH4HfHxdTesjCjvMCx1VJgA5AnpuvrWRq1swfRdsS -s 5
2020-12-12 01:26:39 +01:00
########################################################################
echo "RESTART ipfs"
########################################################################
sudo service ipfs restart
echo ".... WAIT for SWARM to connect ..."
sleep 10
ipfs swarm peers
########################################################################
echo 'EXTEND ~/.bashrc'
########################################################################
2020-12-12 01:43:01 +01:00
~/.zen/astrXbian/.install/update_bashrc.sh
2020-12-12 01:26:39 +01:00
echo "Configure .kodi/addons/plugin.video.vstream/resources/sites/astroport.py"
2020-12-12 01:43:01 +01:00
cp -f ~/.zen/astrXbian/.install/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py \
2020-12-12 01:26:39 +01:00
~/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py
# CREATE xbian IPNSKEY used to publish ~/.zen/ipfs_swarm/xbian (contains all XZUID pastebin files)
ipfs key rm xbian
IPNSKEY=$(ipfs key gen xbian)
2020-12-12 16:22:49 +01:00
sed -i "s/_IPNSKEY_/$IPNSKEY/g" ~/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py
sed -i "s/_PROFIL_/$XZUID/g" ~/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py
sed -i "s/_LOGIN_/$salt/g" ~/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py
sed -i "s/_MDP_/$pepper/g" ~/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py
2020-12-12 01:26:39 +01:00
2020-12-12 03:51:08 +01:00
~/.zen/astrXbian/zen/cesium_IPFS_swarm.sh
2020-12-12 01:43:01 +01:00
~/.zen/astrXbian/zen/ipfs_SWARM_refresh.sh
2020-12-12 01:26:39 +01:00
########################################################################
echo 'SEND "ipfstryme" message'
########################################################################
echo "" > ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr # ERASE
for tryme in $(ipfs id | jq -r .Addresses[]);
do
isLAN=$(echo $tryme | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/")
[[ ! $isLAN && $tryme != "" ]] && echo "$tryme" >> ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr && echo "$tryme"
done
echo 'SEND ipfstryme to oasis' # Add your bootstrap Pub here
2020-12-12 16:53:39 +01:00
./jaklis.py -n "https://g1.data.le-sou.org" send -d 2jQUH4HfHxdTesjCjvMCx1VJgA5AnpuvrWRq1swfRdsS -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
2020-12-12 20:59:40 +01:00
./jaklis.py -n "https://data.gchange.fr" send -d 2jQUH4HfHxdTesjCjvMCx1VJgA5AnpuvrWRq1swfRdsS -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
2020-12-12 01:26:39 +01:00
########################################################################
echo 'INSTALL Astroport cron_MINUTE'
########################################################################
2020-12-12 16:18:46 +01:00
~/.zen/astrXbian/zen/cron_VRFY.sh
2020-12-12 01:26:39 +01:00
2020-12-12 01:43:01 +01:00
# Run only once: comment /etc/rc.local (su - xbian -c "~/.zen/astrXbian/ISOconfig.sh")
2020-12-12 01:26:39 +01:00
# sudo sed -i s/su/\#su/g /etc/rc.local
# BETTER NOT: Send new 'ipfstryme' message on each boot is done instead
echo "CHANGE hostname"
2020-12-12 16:18:46 +01:00
astrxbian=$(hostname)
2020-12-12 16:53:39 +01:00
sudo sed -i "s/$astrxbian/$XZUID/g" /etc/hostname
sudo sed -i "s/$astrxbian/$XZUID/g" /etc/hosts
2020-12-12 01:26:39 +01:00
2020-12-14 01:11:38 +01:00
echo "CHANGE DNS" # Avoid provider restrictions
sudo chattr -i /etc/resolv.conf
sudo cat > /tmp/resolv.conf <<EOF
2020-12-12 01:26:39 +01:00
domain home
search home
nameserver 80.67.169.12 80.67.169.40 94.247.43.254 2001:67c:13e4:1::37
# FFDN.org opennic.org = ns8.he.de + ns5.ru
EOF
2020-12-14 01:11:38 +01:00
sudo mv /tmp/resolv.conf /etc/resolv.conf
2020-12-12 01:26:39 +01:00
sudo chattr +i /etc/resolv.conf
2020-12-12 16:51:17 +01:00
# WRITE ~/.zen/ipfs.sync CONFIG (meaning DONE)
echo "IPFS_SYNC_DIR=$IPFS_sync_directory" > ~/.zen/ipfs.sync
2020-12-12 01:26:39 +01:00
2020-12-13 20:16:30 +01:00
# RESIZING / partition
# sudo btrfs filesystem resize max /
2020-12-12 01:26:39 +01:00
########################################################################
echo 'REBOOT NOW...'
########################################################################
sudo reboot
exit 0