#!/bin/sh
# -----------------------------------------
# install rfriends for ubuntu
# -----------------------------------------
# 1.00 2020/05/20 18.04, 19.10, 20.04
# 1.10 2020/05/21 architecture check
# 1.20 2020/05/22 ask update rfriends
# 1.30 2020/06/21 fix armhf error
# 1.40 2021/02/13 fix
# 1.50 2021/05/09 fix
# 1.60 2021/10/26 add pulseaudio
# 1.70 2021/11/04 add xrfriends2.sh
# 1.80 2022/05/09 add dnsutils
# 1.90 2022/06/23 ffmpeg force copy
# 2.0 2022/06/23 ffmpeg default only
# 
# toolinstall
# rfriends install
# -----------------------------------------
echo
echo rfriends for ubuntu 2.00
echo
# -----------------------------------------
sudo apt update
sudo apt upgrade
# -----------------------------------------
ar=`dpkg --print-architecture`
bit=`getconf LONG_BIT`
echo
echo アーキテクチュアは、$ar $bit bits です。
# -----------------------------------------
echo
echo ツールをインストール
echo
sudo apt -y install unzip
sudo apt -y install at
sudo apt -y install nano
sudo apt -y install vim

sudo apt -y install php-cli
sudo apt -y install php-xml
sudo apt -y install php-zip
sudo apt -y install php-mbstring

sudo apt -y install mp4v2-utils
sudo apt -y install atomicparsley
sudo apt -y install pulseaudio
sudo apt -y install pulseaudio-module-bluetooth
sudo apt -y install dnsutils
sudo apt -y install ffmpeg
# -----------------------------------------
echo
echo rfriendsをインストール

echo

cd ~/

if [ -d ./rfriends2 ]; then
	read -p "すでにrfriendsがインストールされていますが、削除しますか？　(y/N) " ans

	case "$ans" in
  		"y" | "Y" )
			rm -r ./rfriends2
			echo "rfriendsを削除しました。"
			echo 
    			;;
  		* )
			echo 
    			;;
	esac
fi

if [ -d ./rfriends2 ]; then
	read -p "rfriends(安定版)を上書きインストールしますか？　(y/N) " ans

	case "$ans" in
  		"y" | "Y" )
			echo 
    			;;
  		* )
			echo
                        echo finished
                        exit
    			;;
	esac
fi

# -----------------------------------------
rm rfriends2_latest_script.zip
wget http://rfriends.s1009.xrea.com/files/rfriends2_latest_script.zip
unzip -q -o rfriends2_latest_script.zip
# -----------------------------------------
rm ~/xrfriends2.sh
cat <<EOF | sudo tee ~/xrfriends2.sh > /dev/null
#!/bin/sh
# -----------------------------------------
# rfriends 簡単起動
# -----------------------------------------
# 1.00 2021/02/15
#
sh ~/rfriends2/rfriends2.sh
# -----------------------------------------
EOF

sudo chmod +x ~/xrfriends2.sh

# -----------------------------------------
# 終了
# -----------------------------------------
echo
echo finished

echo
echo rfriends2起動
echo ./xrfriends2.sh
# -----------------------------------------
