· 6 months ago · Apr 12, 2025, 05:30 AM
1#!/bin/bash
2set -e # Exit immediately if a command exits with a non-zero status
3
4# Define color variables
5RED='\e[31m'
6GREEN='\e[32m'
7YELLOW='\e[33m'
8BLUE='\e[34m'
9NC='\e[0m' # No Color
10
11# Check for root privileges
12if [ "$EUID" -ne 0 ]; then
13 echo -e "${RED}This script must be run as root. Use 'sudo' to execute it.${NC}"
14 exit 1
15fi
16
17# Function to prompt for OS selection
18select_os() {
19 while true; do
20 echo -e "${BLUE} KAJOKO BAIK HATI :${NC}"
21 echo -e "${YELLOW}1) Windows 10 GS DigitalOcean${NC}"
22 echo -e "${YELLOW}2) Windows 2016${NC}"
23 echo -e "${YELLOW}3) Windows 2012${NC}"
24 read -p "Enter choice : " os_choice
25 if [[ "$os_choice" =~ ^[1-3]$ ]]; then
26 break
27 else
28 echo -e "${RED}Invalid selection. Please enter 1 or 2.${NC}"
29 fi
30 done
31
32 if [ "$os_choice" == "1" ]; then
33 img_url='joko/win10.gz'
34 elif [ "$os_choice" == "2" ]; then
35 img_url='joko/win2016.gz'
36 elif [ "$os_choice" == "3" ]; then
37 img_url='https://www.dropbox.com/scl/fi/kc0v8uv9cca90kwxgftec/w2012r2.gz?rlkey=nf5cxoel30b4ax1yi33h0zhfv&st=uqfvhlw4&dl=1'
38 fi
39}
40
41# Function to prompt for password
42prompt_password() {
43 default_password="Warning1@"
44 while true; do
45 echo -e "${GREEN}Enter RDP password (press enter for default: ${default_password}):${NC}"
46 read -p "" user_password
47 password=${user_password:-$default_password}
48 break
49
50 # Password strength check
51# if [[ "$password" =~ ^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{8,}$ ]]; then
52# break
53# else
54# echo -e "${RED}Password must be at least 8 characters long and include uppercase, lowercase, and numbers.${NC}"
55# fi
56 done
57}
58
59# Download reinstall.sh
60download_reinstall_script() {
61 echo -e "${BLUE}Downloading reinstall.sh...${NC}"
62 if ! curl -# -O https://raw.githubusercontent.com/kripul/reinstall/main/reinstall.sh && ! wget --progress=bar:force -O reinstall.sh https://raw.githubusercontent.com/kripul/reinstall/main/reinstall.sh; then
63 echo -e "${RED}Failed to download reinstall.sh. Exiting.${NC}"
64 exit 1
65 fi
66}
67
68# Execute the reinstall script
69execute_reinstall_script() {
70 echo -e "${GREEN}Executing reinstall script...${NC}"
71 bash reinstall.sh dd \
72 --rdp-port 6969 \
73 --password "$password" \
74 --img "$img_url"
75}
76
77# Confirm reboot
78confirm_reboot() {
79 read -p "Are you sure you want to reboot now? (y/n): " confirm_reboot
80 if [[ "$confirm_reboot" == "y" || "$confirm_reboot" == "Y" ]]; then
81 echo -e "${YELLOW}Rebooting in 5 seconds...${NC}"
82 sleep 5
83 reboot
84 else
85 echo -e "${GREEN}Reboot canceled. Exiting.${NC}"
86 exit 0
87 fi
88}
89
90# Main script logic
91select_os
92prompt_password
93download_reinstall_script
94execute_reinstall_script
95confirm_reboot