Advertisement
kohpriwniranam

install_gopy

Jan 31st, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. import os
  2. import subprocess
  3.  
  4. def change_hostname():
  5. new_hostname = input("กรุณาใส่ชื่อโฮสต์ใหม่ (หรือกด Enter เพื่อข้าม): ")
  6. if new_hostname.strip():
  7. subprocess.run(["sudo", "hostnamectl", "set-hostname", new_hostname], check=True)
  8. print(f"โฮสต์เนมถูกเปลี่ยนเป็น {new_hostname} แล้ว")
  9. else:
  10. print("ข้ามการเปลี่ยนชื่อโฮสต์")
  11.  
  12. def change_password():
  13. new_password = input("กรุณาใส่รหัสผ่านใหม่ (หรือกด Enter เพื่อข้าม): ")
  14. if new_password.strip():
  15. subprocess.run(f"echo -e '{new_password}\\n{new_password}' | sudo passwd", shell=True, check=True)
  16. print("รหัสผ่านถูกเปลี่ยนเรียบร้อยแล้ว")
  17. else:
  18. print("ข้ามการเปลี่ยนรหัสผ่าน")
  19.  
  20. def check_speed():
  21. print("กำลังตรวจสอบความเร็วอินเทอร์เน็ต...")
  22. try:
  23. subprocess.run(["speedtest-cli"], check=True)
  24. except FileNotFoundError:
  25. print("ไม่พบ speedtest-cli ในระบบ กำลังติดตั้ง...")
  26. subprocess.run(["sudo", "apt-get", "install", "-y", "python3-pip"], check=True)
  27. subprocess.run(["pip3", "install", "speedtest-cli"], check=True)
  28. subprocess.run(["speedtest-cli"], check=True)
  29.  
  30. def install_go_and_dependencies():
  31. print("กำลังติดตั้ง Go และไลบรารีที่จำเป็น...")
  32. subprocess.run(["wget", "https://go.dev/dl/go1.21.0.linux-amd64.tar.gz"], check=True)
  33. subprocess.run(["sudo", "rm", "-rf", "/usr/local/go"], check=True)
  34. subprocess.run(["sudo", "tar", "-C", "/usr/local", "-xzf", "go1.21.0.linux-amd64.tar.gz"], check=True)
  35. subprocess.run(["sudo", "apt-get", "update"], check=True)
  36. subprocess.run(["sudo", "apt-get", "install", "-y", "unzip", "zip", "git"], check=True)
  37. subprocess.run(["sudo", "ln", "-fs", "/usr/share/zoneinfo/Asia/Bangkok", "/etc/localtime"], check=True)
  38. subprocess.run(["sudo", "dpkg-reconfigure", "-f", "noninteractive", "tzdata"], check=True)
  39.  
  40. with open(os.path.expanduser("~/.profile"), "a") as profile:
  41. profile.write('\nexport PATH=$PATH:/usr/local/go/bin')
  42. profile.write('\nexport GOROOT=/usr/local/go')
  43. profile.write('\nexport GOPATH=$HOME')
  44. profile.write('\nexport PATH=$GOPATH/bin:$GOROOT/bin:$PATH')
  45.  
  46. subprocess.run(["source", os.path.expanduser("~/.profile")], shell=True, check=True)
  47.  
  48. go_get_dependencies = [
  49. "github.com/opalmer/check-go-version/api",
  50. "github.com/shirou/gopsutil/disk",
  51. "github.com/shirou/gopsutil/host",
  52. "github.com/shirou/gopsutil/mem",
  53. "github.com/tidwall/gjson",
  54. "github.com/valyala/fasthttp",
  55. "github.com/kardianos/osext",
  56. "github.com/panjf2000/ants",
  57. "github.com/asaskevich/govalidator",
  58. "github.com/dchest/siphash",
  59. "golang.org/x/net/http2",
  60. "github.com/fatih/color",
  61. "github.com/ddosify/go-faker/faker",
  62. "golang.org/x/crypto/hkdf",
  63. "golang.org/x/crypto/curve25519",
  64. "github.com/lynn9388/supsub",
  65. "github.com/danielgtaylor/unistyle",
  66. "github.com/leekchan/timeutil",
  67. #"github.com/8ff/gpt/pkg/gpt_3_5_turbo",
  68. #"github.com/sashabaranov/go-openai",
  69. "github.com/boombuler/barcode",
  70. "github.com/dgrr/http2",
  71. "github.com/fckveza/VHtearCryptoutil",
  72. "github.com/pmezard/go-difflib/difflib",
  73. "github.com/skip2/go-qrcode",
  74. "github.com/slayer/autorestart",
  75. "github.com/tidwall/sjson"
  76. ]
  77.  
  78. for dep in go_get_dependencies:
  79. subprocess.run(["go", "get", "-u", dep], check=True)
  80.  
  81. if __name__ == "__main__":
  82. change_hostname()
  83. change_password()
  84. check_speed()
  85. install_go_and_dependencies()
  86. print("ติดตั้งเสร็จเรียบร้อย กรุณารีสตาร์ทเซิร์ฟเวอร์")
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement