{"id":38089259,"url":"https://github.com/zhiminwen/magetool","last_synced_at":"2026-01-16T20:56:16.992Z","repository":{"id":57512088,"uuid":"154270752","full_name":"zhiminwen/magetool","owner":"zhiminwen","description":"sshkit/rake in Golang","archived":false,"fork":false,"pushed_at":"2025-05-11T13:00:19.000Z","size":580,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-11T13:19:29.402Z","etag":null,"topics":["mage","rake","sshkit"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhiminwen.png","metadata":{"files":{"readme":"readme.md","changelog":"changes.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-23T06:00:10.000Z","updated_at":"2025-05-11T13:00:22.000Z","dependencies_parsed_at":"2024-06-20T00:06:42.466Z","dependency_job_id":"d0d58281-38fc-4e6a-bf7a-c148cc644361","html_url":"https://github.com/zhiminwen/magetool","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zhiminwen/magetool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhiminwen%2Fmagetool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhiminwen%2Fmagetool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhiminwen%2Fmagetool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhiminwen%2Fmagetool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhiminwen","download_url":"https://codeload.github.com/zhiminwen/magetool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhiminwen%2Fmagetool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28482425,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mage","rake","sshkit"],"created_at":"2026-01-16T20:56:16.865Z","updated_at":"2026-01-16T20:56:16.953Z","avatar_url":"https://github.com/zhiminwen.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Capistrano/SSHKit Implementation with Golang\n\n## Download and Import\n```\ngo get github.com/zhiminwen/magetool\n```\n\n```\nimport (\n\t\"github.com/zhiminwen/magetool/shellkit\"\n\t\"github.com/zhiminwen/magetool/sshkit\"\n)\n```\n\n## [Medium Story](https://medium.com/@zhimin.wen/implement-capistrano-sshkit-in-golang-32d8d094e65d)\n\n\n## Synopsis\n\n### Mage\nUse [Mage](https://github.com/magefile/mage) to organize the tasks together\n\n```golang\n// +build mage\npackage main\nimport (\n \"os\"\n \"github.com/zhiminwen/magetool/shellkit\"\n)\nfunc init() {\n os.Setenv(\"MAGEFILE_VERBOSE\", \"true\")\n}\n//Run Cmd\nfunc RunCmd() {\n shellkit.Execute(\"cmd\", \"/c\", \"type test.log \u0026 sleep 10\")\n}\n//dir\nfunc Dir() {\n shellkit.Execute(\"cmd\", \"/c\", \"time /t 1\u003e\u00262 \u0026 exit 1\")\n}\n```\n\n### Shellkit\n\n- Use Shellkit.Execute() to run local command.\n- Use Shellkit.Capture to capture command output.\n\n### SSHkit\n\nInit the client\n\n```golang\n//Use password\nclient1 := sshkit.NewSSHClient(\"192.168.5.10\", \"22\", \"ubuntu\", \"password\", \"\")\n//Use private key\ns2 := sshkit.NewSSHClient(\"192.168.5.10\", \"22\", \"ubuntu\", \"\", \"mykeyfile\"\n// Use a slice of the client\n\nvar servers []*sshkit.SSHClient\nservers = append(servers, sshkit.NewSSHClient(\"192.168.5.10\", \"22\", \"ubuntu\", \"password\", \"\"))\nservers = append(servers, sshkit.NewSSHClient(\"192.168.5.10\", \"22\", \"ubuntu2\", \"password\", \"\"))\n```\n\nExecute a command\n\n```golang\n// Run against a single client\nclient1.Execute(\"id; hostname\")\n//Run against slice of servers\nsshkit.Execute(servers, \"id; hostname\")\n```\n\nCapture a result\n\n``` golang\nresult, err := client.Capture(\"hostname\")\n```\n\n```golang\nsshkit.ExecuteFunc(servers, func(t *sshkit.SSHClient) {\n  id, err := t.Capture(\"id -u\")\n  if err != nil {\n   log.Printf(\"Failed to get id:%v\", err)\n   return\n  }\n  if id == \"1000\" {\n   return\n  }\n  cmd := fmt.Sprintf(\"echo %s; hostname\", id)\n  t.Execute(cmd)\n })\n```\n\n\nUpload and Download\n\n```golang\nclient1.Upload(\"example.txt\", \"/tmp/example.txt\")\nclient1.Download(\"/etc/hosts\", \"hosts.txt\")\n```\n\n```\nclient1.Put(`This is a test content`, \"mytest.txt\")\nlist, err := servers[0].Get(\"/etc/passwd\")\n```\n\nInteract with command\n\n```golang\nclient1.Execute(`rm -rf .ssh/known_hosts`)\nclient1.ExecuteInteractively(\"scp ubuntu@ubuntu:/tmp/test.txt /tmp/test.txt.dupped\", map[string]string{\n  `\\(yes/no\\)`: \"yes\",\n  \"password\":   \"password\",\n })\n```\n\n## Full example to build a docker image and push to dockerhub\n[Source Code](sample/dockerBuild/dockerBuilder.go)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhiminwen%2Fmagetool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhiminwen%2Fmagetool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhiminwen%2Fmagetool/lists"}