├── .gitignore ├── commiter.yml ├── README.md ├── watch.json.example ├── LICENSE └── updatev2.rb /.gitignore: -------------------------------------------------------------------------------- 1 | packages 2 | *.json 3 | -------------------------------------------------------------------------------- /commiter.yml: -------------------------------------------------------------------------------- 1 | convention: symphony 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Update GitHub Programs from Terminal 2 | -------------------------------------------------------------------------------- /watch.json.example: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "program": "ffmpeg", 4 | "repo": "BtbN/FFmpeg-Builds", 5 | "name": "ffmpeg-N-\\d+-\\w+-win64-gpl.zip", 6 | "cmd": "7z e -oC:/tools/bin {PATH}/ffmpeg.zip -r -y > nul" 7 | }, 8 | { 9 | "program": "ripme", 10 | "repo": "ripmeapp/ripme", 11 | "name": "ripme.jar", 12 | "cmd": "cp -f {PATH}/ripme.jar C:/tools/bin/" 13 | }, 14 | { 15 | "program": "dezoomify-rs", 16 | "repo": "lovasoa/dezoomify-rs", 17 | "name": "dezoomify-rs.exe", 18 | "cmd": "cp -f {PATH}/dezoomify-rs.exe C:/tools/bin/" 19 | }, 20 | { 21 | "program": "pandoc", 22 | "repo": "jgm/pandoc", 23 | "name": "-x86_64.zip$", 24 | "cmd": "7z e -oC:/tools/bin {PATH}/pandoc.zip -r -y > nul" 25 | }, 26 | { 27 | "program": "clink", 28 | "repo": "chrisant996/clink", 29 | "name": "clink.\\d+.\\d+.\\d+.\\w+.zip", 30 | "cmd": "7z e -oC:/tools/clink {PATH}/clink.zip -r -y > nul" 31 | } 32 | ] 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021, Aakash Gajjar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /updatev2.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | require 'http' 4 | require 'colorize' 5 | 6 | 7 | META_FILE_NAME = File.join(__dir__,'watch.info.json') 8 | LIST_FILE_NAME = File.join(__dir__,'watch.json') 9 | 10 | FORCE_UPDATE = ARGV.include?('-f') 11 | 12 | $llength = 0 13 | def log(s, newline=false) 14 | $llength = s.length if $llength < s.length 15 | print "#{s.ljust($llength, ' ')}" + (newline ? "\n" : '') + "\r" 16 | end 17 | 18 | def _read_json(filepath) 19 | JSON.parse(File.read(filepath)) 20 | end 21 | 22 | def _write_json(filepath, data) 23 | out = File.open(filepath, 'w') 24 | out.puts data.to_json 25 | out.close 26 | end 27 | 28 | $meta_info = _read_json(META_FILE_NAME) 29 | 30 | def is_new_version(repo, new_id) 31 | meta = $meta_info[repo] 32 | return [true, "0.0.0"] unless $meta_info.key?(repo) 33 | 34 | is_update = FORCE_UPDATE ? true : meta["id"] != new_id 35 | 36 | return [is_update, meta["tag_name"]] 37 | end 38 | 39 | def update_meta_info(repo, id, name, tag_name) 40 | data = _read_json(META_FILE_NAME) 41 | data[repo] = { "id": id, "name": name, "tag_name": tag_name} 42 | _write_json(META_FILE_NAME, data) 43 | end 44 | 45 | packages = JSON.parse(File.read(LIST_FILE_NAME)) 46 | 47 | packages.each do |package| 48 | program = package["program"] 49 | 50 | api_response = JSON.parse(HTTP.get("https://api.github.com/repos/#{package["repo"]}/releases").to_s) 51 | latest_release = api_response.first 52 | 53 | release_id = latest_release["id"] 54 | release_tagname = latest_release["tag_name"] 55 | 56 | is_update, old_tagname = is_new_version(package["repo"], release_id) 57 | 58 | log("#{program.white} [#{old_tagname.cyan}] is upto date.", true) unless is_update 59 | next unless is_update 60 | 61 | log("Updating #{program} ... ") 62 | 63 | target = latest_release["assets"].select { |release| 64 | Regexp.new(package["name"]).match(release["name"]) 65 | } 66 | 67 | download_url = target.first["browser_download_url"] 68 | download_name = target.first["name"] 69 | 70 | log("Updating #{program.yellow} ... downloading #{download_url.yellow}") 71 | 72 | system("wget -q \"#{download_url}\" -O #{File.join(__dir__, "packages", program)}.#{download_name.split('.').last}") 73 | 74 | log("Updating #{program.yellow} ... extracting ...") 75 | 76 | if system(package["cmd"].gsub("{PATH}", File.join(__dir__, 'packages'))) 77 | log("#{program} updated! (#{old_tagname.cyan} -> #{release_tagname.green})", true) 78 | update_meta_info(package["repo"], release_id, download_name, release_tagname) 79 | end 80 | end 81 | --------------------------------------------------------------------------------