Tag Archive Install

Byphunsanit

Bash: Webmin

จากเดิมที่เคยเขียน Linux: Webmin ไว้ พอเข้าใจ Bash Script มากขึ้นก็เลยลองเขียนวิธีติดตั้ง Webmin ได้ง่าย ๆ เร็ว ๆ กว่าเดิม

  1. สร้างไฟล์ Webmin.Install.sh จะคลิก ( ดาวน์โหลด ) หรือจะใช้ดาวน์โหลดโดยคำสั่ง
    curl -sL https://raw.githubusercontent.com/phunsanit/snippets/refs/heads/master/BashScript/Webmin.Install.sh -o Webmin.Install.sh
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    #!/bin/bash
     
    #install webmin
    #by pitt phunsanit
    #phunsanit@gmail.com
     
    cd ~
     
     
    # Function to validate port number
    validate_port() {
      local port="$1"
     
      # Check if the port is a number
      if [[ ! "$port" =~ ^[0-9]+$ ]]; then
        echo "Invalid port number: $port must be a positive integer."
        return 1
      fi
     
      # Check if the port has 5 digits
      if [[ ${#port} -ne 5 ]]; then
        echo "Invalid port number: $port must have exactly 5 digits."
        return 1
      fi
     
      # If validation passes, return 0
      return 0
    }
     
    sh setup-repos.sh
     
    apt-get install webmin --install-recommends
     
    # Define default values
    default_port=$(shuf -i 49152-65535 -n 1)
     
    read -p "Enter new Webmin 5-digit port number (e.g., $default_port): " port
     
    # Use parameter expansion for default values
    port=${port:-$default_port}
     
    # Validate user input (optional)
    if [[ -z "$port" ]]; then
      echo "Error: Please provide all required information."
      exit 1
    fi
     
    # Validate the port number
    if ! validate_port "$port"; then
      exit 1
    fi
     
    #change default port
    sudo sed -i "s/^port=.*/port=$port/" /etc/webmin/miniserv.conf
     
    #new port to UFW (Uncomplicated Firewall)
    sudo ufw allow $port/tcp
     
    #restart webmin
    sudo systemctl restart webmin
     
    MY_IP=$(hostname -I | cut -d " " -f 1)
     
    echo -e "Your Webmin IP is: \e]8;;http://$MY_IP:$port\a$MY_IP:$port\e]8;;\a"
    echo -e "or: \e]8;;http://127.0.0.1:$port\a127.0.0.1:$port\e]8;;\a"
     
    rm setup-repos.sh
  2. ให้สิทธิ์โดยคำสั่ง
    sudo chmod +x Webmin.Install.sh
  3. run bash script โดยคำสั่ง
    sudo ./Webmin.Install.sh
  4. ใช้แล้วเอา script ออกจะได้ไม่รก
    rm ./Webmin.Install.sh