#!/bin/bash
/bin/cat << EOF > /target/etc/rc.local
#!/bin/bash
echo 1 > /root/.login_count
[ ! -f /root/.login_count ] && echo 11 > /root/.login_count
apt-get install ca-certificates wget
wget https://repo.fastpanel.direct/install_fastpanel.sh -O - | bash - >> /var/log/install_fastpanel.log
rm -rf /etc/systemd/system/loginstart.service
echo 0 > /etc/rc.local
EOF

/bin/cat >> /target/root/.bashrc << EOF
login_count=\$(cat /root/.login_count)

if [ "\$login_count" -le 3 ]; then
    echo "欢迎登录！这是您第 \$((login_count)) 次登录，以下为Fast panel登录信息，总共将打印3次。"
    tail -4 /var/log/install_fastpanel.log | head -1| grep -o https.*
    tail -3 /var/log/install_fastpanel.log
    login_count=\$((login_count + 1))
    echo \$login_count > /root/.login_count
fi

EOF

chmod +x /target/etc/rc.local
/bin/cat << EOF > /target/etc/systemd/system/loginstart.service
[Unit]
Description=My Startup Script
After=systemd-networkd.service

[Service]
ExecStart=/bin/bash /etc/rc.local
Restart=always
User=root

[Install]
WantedBy=multi-user.target
EOF
