astroport/.install/sys_checkOS.sh

31 lines
1.1 KiB
Bash

#!/bin/bash
astroVars="OS ARM YOU ipfsnodeid ASTROZEN ASTRONODE myProfile"
export YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1)
export ipfsnodeid=$(ipfs id -f='<id>\n')
export ASTROZEN="/home/$YOU/.zen"
export ASTRONODE="$ASTROZEN/ipfs/.$ipfsnodeid"
export myProfile="$ASTRONODE/profile"
[[ ! -d $ASTRONODE ]] && mkdir -p $ASTRONODE
## Check system kind
[[ $(uname -a | grep arm) ]] && export ARM=yes || unset ARM
if [[ $(grep -E 'stretch|18.|19.' /etc/os-release) ]]; then export OS=stretch;
elif [[ $(grep buster /etc/os-release) ]]; then export OS=buster;
else echo "${c_red}OS not supported$c_"; exit 1; fi
[[ -e $myProfile ]] && rm $myProfile
touch $myProfile
for i in $astroVars; do
[[ ! $(grep "$i=" $myProfile) && -n ${!i} ]] && echo "export $i=${!i}" >> $myProfile
done
[[ -n $(grep "/.zen/ipfs/" ~/.bashrc) ]] && sed -i -n '/\/.zen\/ipfs/!p' ~/.bashrc
[[ -n $(grep "# ASTROPORT " ~/.bashrc) ]] && sed -i -n '/# ASTROPORT /!p' ~/.bashrc
echo -e "# ASTROPORT ENVIRONMENT VARIABLE\n. /home/$YOU/.zen/ipfs/.$ipfsnodeid/profile" >> ~/.bashrc
[[ $1 != "noexec" ]] && exec bash