#!/usr/bin/env bash
cd
ROOTFS=`for i in bullseye buster bionic kali jammy focal; do if grep -q $i /etc/os-release ; then echo $i; fi done`
                                 
case $ROOTFS in
bullseye|kali)
ROOTFS=bullseye
LXC=debian
;;
buster)
ROOTFS=buster
LXC=debian
;;
bionic)
ROOTFS=bionic
LXC=ubuntu
;;
focal)
ROOTFS=focal
LXC=ubuntu
;;
jammy)
ROOTFS=jammy
LXC=ubuntu
;;
*)
echo -e "这个脚本不支持你的系统"
sleep 2
exit 0
esac
main(){
while [ ! $(command -v box86) ] || [ ! $(command -v box64) ] || [ ! $(command -v /usr/games/sl) ] || [ ! $(command -v wine64) ] && [[ $ii -ne 3 ]]
do
DEPENDS0="zenity:armhf libegl-mesa0:armhf libgl1-mesa-dri:armhf libglapi-mesa:armhf libglx-mesa0:armhf libasound*:armhf libstdc++6:armhf libtcmalloc-minimal4:armhf gcc-arm-linux-gnueabihf sl:armhf -y"
if [[ $(id -u) != 0 ]];then
SUDO=sudo
fi
mkdir -p /usr/share/doc/wine 2>/dev/null
$SUDO apt install fonts-wqy-microhei -y
$SUDO dpkg --add-architecture armhf
$SUDO apt update
$SUDO apt install $DEPENDS0 -y
if [ ! $(command -v box86) ]; then
#curl https://raw.githubusercontent.com$(curl https://kgithub.com/Itai-Nelken/weekly-box86-debs/tree/main/debian/pool|grep 'armhf.deb'|awk -F 'href="' '{print $2}'|cut -d '"' -f 1|tail -n 1|sed 's@/blob@@') -o box86.deb&&dpkg -X box86.deb /
curl -O https://shell.xb6868.com/wine/box86.tar.gz
tar zxvf box86.tar.gz -C /
fi
if [ ! $(command -v box64) ]; then
#curl https://raw.githubusercontent.com$(curl https://kgithub.com/ryanfortner/box64-debs/tree/master/debian|grep 'arm64.deb'|awk -F 'href="' '{print $2}'|cut -d '"' -f 1|tail -n 1|sed 's@/blob@@') -o box64.deb&&dpkg -X box64.deb /
curl -O https://shell.xb6868.com/wine/box64.tar.gz
tar zxvf box64.tar.gz -C /
fi
if [ ! $(command -v wine64) ]; then
#curl -O https://www.playonlinux.com/wine/binaries/phoenicis/upstream-linux-amd64/PlayOnLinux-wine-6.17-upstream-linux-amd64.tar.gz
curl -O https://shell.xb6868.com/wine/PlayOnLinux-wine-6.17-upstream-linux-amd64.tar.gz
tar zxvf PlayOnLinux-wine-6.17-upstream-linux-amd64.tar.gz -C /usr/ ./lib
WINE_URL="https://mirrors.tuna.tsinghua.edu.cn"; curl -o wine-devel-i386.deb ${WINE_URL}/wine-builds/${LXC}/dists/${ROOTFS}/main/binary-i386/$(curl ${WINE_URL}/wine-builds/${LXC}/dists/${ROOTFS}/main/binary-i386/|grep wine-devel-i386_8|awk -F 'href="' '{print $2}'|cut -d '"' -f 1|tail -n 1); curl -o wine-devel-amd64.deb ${WINE_URL}/wine-builds/${LXC}/dists/${ROOTFS}/main/binary-amd64/$(curl ${WINE_URL}/wine-builds/${LXC}/dists/${ROOTFS}/main/binary-amd64/|grep wine-devel-amd64_8|awk -F 'href="' '{print $2}'|cut -d '"' -f 1|tail -n 1); curl -o wine-devel.deb  ${WINE_URL}/wine-builds/${LXC}/dists/${ROOTFS}/main/binary-amd64/$(curl ${WINE_URL}/wine-builds/${LXC}/dists/${ROOTFS}/main/binary-amd64/|grep wine-devel_8|awk -F 'href="' '{print $2}'|cut -d '"' -f 1|tail -n 1); curl -o winehq-devel.deb ${WINE_URL}/wine-builds/${LXC}/dists/${ROOTFS}/main/binary-amd64/$(curl ${WINE_URL}/wine-builds/${LXC}/dists/${ROOTFS}/main/binary-amd64/|grep winehq-devel_8|awk -F 'href="' '{print $2}'|cut -d '"' -f 1|tail -n 1); for i in wine-devel-amd64.deb  winehq-devel.deb wine-devel.deb wine-devel-i386.deb; do dpkg -X $i / >>/usr/share/doc/wine/postrm 2>/dev/null; done
fi
ii=$(( $ii+1 ))
done
WINEDEBUG=fixme-all box64 wine64 wineboot &
pstree | grep -q "services"
while [ $? == 0 ]
do
sleep 1
pstree | grep -q "services"
done

while [ ! -f .wine/user.reg ]
do
sleep 1
done
echo -e "\e[33m配置中，请稍候..\e[0m"
sleep 1
pstree | grep -q "wineboot"
while [ $? == 0 ]
do
sleep 3
du -sh ${HOME}/.wine
pstree | grep -q "wineboot"
done
sed -i '/\[Environment/i \[Software\\\\Wine\\\\Explorer\]\n"Desktop"="Default"\n\n\[Software\\\\Wine\\\\Explorer\\\\Desktops\]\n"Default"="800x600"\n\n\[Software\\\\Wine\\\\X11 Driver\]\n"Decorated"="N"\n"Managed"="Y"' .wine/user.reg
sed -i '/FontMapper/i \[Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\FontLink\\\\SystemLink\]\n"Arial"="wqy-microhei.ttc"\n"Arial Black"="wqy-microhei.ttc"\n"Lucida Sans Unicode"="wqy-microhei.ttc"\n"MS Sans Serif"="wqy-microhei.ttc"\n"SimSun"="wqy-microhei.ttc"\n"Tahoma"="wqy-microhei.ttc"\n"Tahoma Bold"="wqy-microhei.ttc"\n\n' .wine/system.reg
}
main "$@"
