#!/usr/bin/env bash
if [[ $(id -u) != 0 ]];then
sudo=sudo
fi
$sudo apt install libnss3 unzip wget gnupg2 libxtst-dev apt-transport-https -y
if [ ! $(command -v electron) ]; then
mkdir /usr/share/electron
cd /usr/share/electron
wget https://registry.npmmirror.com/-/binary/electron/v8.5.5/chromedriver-v8.5.5-linux-arm64.zip
wget https://registry.npmmirror.com/-/binary/electron/v8.5.5/ffmpeg-v8.5.5-linux-arm64.zip
wget https://registry.npmmirror.com/-/binary/electron/v8.5.5/electron-v8.5.5-linux-arm64.zip
echo -e "\e[33m即将解压包，如遇到提示，请输y回车\e[0m"
read -r -p "确认请回车" input
unset input
unzip -n chromedriver-v8.5.5-linux-arm64.zip
unzip -n ffmpeg-v8.5.5-linux-arm64.zip
unzip -n electron-v8.5.5-linux-arm64.zip
ln -s /usr/share/electron/electron /usr/bin/
curl -1sLf 'https://dl.cloudsmith.io/public/debianopt/debianopt/setup.deb.sh' | sudo -E bash
if ! grep -q 'Package: electron' /var/lib/dpkg/status; then
cat >>/var/lib/dpkg/status<<-EOF
Package: electron
Version: 8.5.5
Architecture: arm64
Status: install ok installed
Priority: extra
Section: devel
Maintainer: coslyk <cos.lyk@gmail.com>
Installed-Size: 200 MB
Homepage: https://github.com/electron/electron
Download-Size: 56.7 MB
APT-Sources: https://dl.cloudsmith.io/public/debianopt/debianopt/deb/debian bullseye/main arm64 Packages
Description: Build cross platform desktop apps with web technologies
EOF
touch /var/lib/dpkg/info/electron.list
fi
fi
#electron --version --no-sandbox
$sudo apt show electron-netease-cloud-music >/dev/null 2>&1
if [ $? != 0 ]; then
	if [ ! -d /etc/apt/sources.list.d ]; then
	mkdir /etc/apt/sources.list.d
	fi
cat >/etc/apt/sources.list.d/debianopt-debianopt.list<<-eof
deb [signed-by=/usr/share/keyrings/debianopt-debianopt-archive-keyring.gpg] https://dl.cloudsmith.io/public/debianopt/debianopt/deb/debian bullseye main
deb-src [signed-by=/usr/share/keyrings/debianopt-debianopt-archive-keyring.gpg] https://dl.cloudsmith.io/public/debianopt/debianopt/deb/debian bullseye main
eof
#apt show electron|sed -E 's/(^Version: ).*$/\18.5.5/;/Depends/d;/Version/a Architecture: arm64\nStatus: install ok installed' >>/var/lib/dpkg/status
$sudo apt update -y
electron --version --no-sandbox
if [ $? == 0 ]; then
	$sudo apt install electron-netease-cloud-music -y
	if [ $(command -v electron-netease-cloud-music) ]; then
	sed -E -i 's/ --no-sandbox//;s/(exec .*$)/\1 --no-sandbox/' $(command -v electron-netease-cloud-music)
	fi
	echo -e "\e[33m安装成功\e[0m"
fi
fi
sleep 1
exit 0
