#!/bin/bash
/bin/cat << EOF > /etc/rc.local
#!/bin/bash
echo 1 > /root/.login_count
[ ! -f /root/.login_count ] && echo 11 > /root/.login_count
yum install wget -y
cd /usr/local/src
wget http://centos-webpanel.com/cwp-el9-latest
sh cwp-el9-latest >> /var/log/install_webpanel.log
rm -rf /etc/systemd/system/loginstart.service
echo 0 > /etc/rc.local
EOF

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

if [ "\$login_count" -le 3 ]; then
    echo "欢迎登录！这是您第 \$((login_count)) 次登录，以下为Web Panel登录信息，总共将打印3次。"
    echo "网页链接: \$(grep "^http:" /var/log/install_webpanel.log)"
    echo "Username: root"
    echo "Password: ssh server root password"
    echo "\$(grep "^MySQL" /var/log/install_webpanel.log)"
    login_count=\$((login_count + 1))
    echo \$login_count > /root/.login_count
fi

EOF

chmod +x /etc/rc.local
/bin/cat << EOF > /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

