Advertisement
kohpriwniranam

installgo

Sep 9th, 2024 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.58 KB | None | 0 0
  1. import subprocess
  2. import os
  3.  
  4. def run_command(command):
  5.     try:
  6.         subprocess.run(command, shell=True, check=True)
  7.     except subprocess.CalledProcessError as e:
  8.         print(f"Error executing command: {command}\n{e}")
  9.  
  10. def download_go():
  11.     run_command("wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz")
  12.  
  13. def install_go():
  14.     run_command("sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz")
  15.  
  16. def update_system():
  17.     run_command("sudo apt-get update")
  18.     run_command("sudo apt-get install -y unzip zip git")
  19.  
  20. def set_timezone():
  21.     run_command("sudo ln -fs /usr/share/zoneinfo/Asia/Bangkok /etc/localtime && sudo dpkg-reconfigure -f noninteractive tzdata")
  22.  
  23. def configure_profile():
  24.     profile_path = os.path.expanduser("~/.profile")
  25.     with open(profile_path, "a") as profile_file:
  26.         profile_file.write("\nexport PATH=$PATH:/usr/local/go/bin\n")
  27.         profile_file.write("export GOROOT=/usr/local/go\n")
  28.         profile_file.write("export GOPATH=$HOME\n")
  29.         profile_file.write("export PATH=$GOPATH/bin:$GOROOT/bin:$PATH\n")
  30.     run_command("source ~/.profile")
  31.  
  32. def install_go_modules():
  33.     go_modules = [
  34.         "github.com/opalmer/check-go-version/api",
  35.         "github.com/shirou/gopsutil/disk",
  36.         "github.com/shirou/gopsutil/host",
  37.         "github.com/shirou/gopsutil/mem",
  38.         "github.com/tidwall/gjson",
  39.         "github.com/valyala/fasthttp",
  40.         "github.com/kardianos/osext",
  41.         "github.com/panjf2000/ants",
  42.         "github.com/asaskevich/govalidator",
  43.         "github.com/dchest/siphash",
  44.         "golang.org/x/net/http2",
  45.         "github.com/fatih/color",
  46.         "github.com/ddosify/go-faker/faker",
  47.         "golang.org/x/crypto/hkdf",
  48.         "golang.org/x/crypto/curve25519",
  49.         "github.com/lynn9388/supsub",
  50.         "github.com/danielgtaylor/unistyle",
  51.         "github.com/leekchan/timeutil",
  52.         "github.com/8ff/gpt/pkg/gpt_3_5_turbo",
  53.         "github.com/sashabaranov/go-openai",
  54.         "github.com/fckveza/VHtearCryptoutil",
  55.         "github.com/pmezard/go-difflib/difflib",
  56.         "github.com/skip2/go-qrcode",
  57.         "github.com/slayer/autorestart",
  58.         "github.com/tidwall/sjson"
  59.     ]
  60.    
  61.     run_command("go env -w GO111MODULE=off")
  62.     for module in go_modules:
  63.         run_command(f"go get -u {module}")
  64.  
  65. def main():
  66.     download_go()
  67.     install_go()
  68.     update_system()
  69.     set_timezone()
  70.     configure_profile()
  71.     install_go_modules()
  72.     print("Installation completed. Please restart your server.")
  73.  
  74. if __name__ == "__main__":
  75.     main()
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement