binstall 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. #!/usr/bin/env bash
  2. # Install various binaries directly from GitHub
  3. # Set script_dir
  4. script_dir="$(dirname "$(realpath "$0")")"
  5. bin_dir=${bin_dir:-"/usr/local/bin"}
  6. delay=${delay:-0.5}
  7. # Source util lib
  8. source "${script_dir}/_util"
  9. # Overide script args if present
  10. [[ -n "${2}" ]] && bin_dir="${2}"
  11. [[ -n "${3}" ]] && delay="${3}"
  12. ran_col_str "Binary install utility" c
  13. binaries="docker-compose k9s eza bat starship mcfly fzf jq htmlq yq fd upx"
  14. cmd_arg_help \
  15. "Program name. Available: ${GREEN}${binaries}${CLEAR}" \
  16. "Bin path. Set: ${GREEN}${bin_dir}${CLEAR}" \
  17. "Curl requests delay in seconds: Set: ${GREEN}${delay}${CLEAR}s"
  18. # Check requirements
  19. command -v jq >/dev/null || error_msg "Please install jq JSON parsing utility" 1
  20. # FETCH FUNCTIONS
  21. function fetch_version_docker_compose {
  22. # Get latest Docker compose version and print result
  23. sleep "$delay"
  24. curl -s "https://api.github.com/repos/docker/compose/tags" |
  25. # Get all tag names
  26. jq -r '.[]|.name' |
  27. # Get latest "vx.x.x" pattern without additional characters
  28. grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
  29. }
  30. function fetch_version_k9s {
  31. # Get latest k9s version and print result
  32. sleep "$delay"
  33. curl -s "https://api.github.com/repos/derailed/k9s/tags" |
  34. # Get all tag names
  35. jq -r '.[]|.name' |
  36. # Get latest "vx.x.x" pattern without additional characters
  37. grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
  38. }
  39. function fetch_version_eza {
  40. # Get latest eza version and print result
  41. sleep "$delay"
  42. curl -s "https://api.github.com/repos/eza-community/eza/tags" |
  43. # Get all tag names
  44. jq -r '.[]|.name' |
  45. # Get latest "vx.x.x" pattern without additional characters
  46. grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
  47. }
  48. function fetch_version_bat {
  49. # Get latest bat version and print result
  50. sleep "$delay"
  51. curl -s "https://api.github.com/repos/sharkdp/bat/tags" |
  52. # Get all tag names
  53. jq -r '.[]|.name' |
  54. # Get latest "vx.x.x" pattern without additional characters
  55. grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
  56. }
  57. function fetch_version_starship {
  58. # Get latest starship version and print result
  59. sleep "$delay"
  60. curl -s "https://api.github.com/repos/starship/starship/tags" |
  61. # Get all tag names
  62. jq -r '.[]|.name' |
  63. # Get latest "vx.x.x" pattern without additional characters
  64. grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
  65. }
  66. function fetch_version_mcfly {
  67. # Get latest mcfly version and print result
  68. sleep "$delay"
  69. curl -s "https://api.github.com/repos/cantino/mcfly/tags" |
  70. # Get all tag names
  71. jq -r '.[]|.name' |
  72. # Get latest "vx.x.x" pattern without additional characters
  73. grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
  74. }
  75. function fetch_version_fzf {
  76. # Get latest fzf version and print result
  77. sleep "$delay"
  78. curl -s "https://api.github.com/repos/junegunn/fzf/tags" |
  79. # Get all tag names
  80. jq -r '.[]|.name' |
  81. # Get latest "x.x.x" pattern without additional characters
  82. grep -P -m 1 '[0-9]+\.[0-9]+\.[0-9]+$'
  83. }
  84. function fetch_version_jq {
  85. # Get latest jq version and print result
  86. sleep "$delay"
  87. curl -s "https://api.github.com/repos/jqlang/jq/tags" |
  88. # Get all tag names
  89. jq -r '.[]|.name' |
  90. # Get latest "jq-x.x" pattern without additional characters
  91. grep -P -m 1 'jq-[0-9]+\.[0-9]+$'
  92. }
  93. function fetch_version_htmlq {
  94. # Get latest htmlq version and print result
  95. sleep "$delay"
  96. curl -s "https://api.github.com/repos/mgdm/htmlq/tags" |
  97. # Get all tag names
  98. jq -r '.[]|.name' |
  99. # Get latest "vx.x.x" pattern without additional characters
  100. grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
  101. }
  102. function fetch_version_yq {
  103. # Get latest yq version and print result
  104. sleep "$delay"
  105. curl -s "https://api.github.com/repos/mikefarah/yq/tags" |
  106. # Get all tag names
  107. jq -r '.[]|.name' |
  108. # Get latest "vx.x.x" pattern without additional characters
  109. grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
  110. }
  111. # TODO
  112. function fetch_version_ripgrep {
  113. # Get latest ripgrep version and print result
  114. sleep "$delay"
  115. curl -s "https://api.github.com/repos/BurntSushi/ripgrep/tags" |
  116. # Get all tag names
  117. jq -r '.[]|.name' |
  118. # Get latest "vx.x.x" pattern without additional characters
  119. grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
  120. }
  121. function fetch_version_fd {
  122. # Get latest fd version and print result
  123. sleep "$delay"
  124. curl -s "https://api.github.com/repos/sharkdp/fd/tags" |
  125. # Get all tag names
  126. jq -r '.[]|.name' |
  127. # Get latest "vx.x.x" pattern without additional characters
  128. grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
  129. }
  130. function fetch_version_upx {
  131. # Get latest fd version and print result
  132. sleep "$delay"
  133. curl -s "https://api.github.com/repos/upx/upx/tags" |
  134. # Get all tag names
  135. jq -r '.[]|.name' |
  136. # Get latest "vx.x.x" pattern without additional characters
  137. grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
  138. }
  139. case $1 in
  140. all)
  141. warning_msg "Installing all binaries: ${binaries}"
  142. # Create an array from string
  143. bins=($binaries)
  144. for b in "${bins[@]}"; do
  145. # Execute self with all binaries and bin path
  146. eval "${0} ${b} ${bin_dir}"
  147. done
  148. # Create Y/N prompt
  149. if yes_no_prompt "Compress downloads binaries with upx?"; then
  150. for b in "${bins[@]}"; do
  151. # Compress binaries in array
  152. #sudo upx --best --lzma "${bin_dir}/*"
  153. if [[ -w "${bin_dir}" ]]; then
  154. upx --best --lzma "${bin_dir}/${b}"
  155. else
  156. sudo upx --best --lzma "${bin_dir}/${b}"
  157. fi
  158. done
  159. success_msg "Binaries compressed with upx!"
  160. else
  161. info_msg "Skipping compression"
  162. fi
  163. ;;
  164. docker-compose)
  165. info_msg "Fetching latest ${1} tag from GitHub"
  166. version=$(fetch_version_docker_compose)
  167. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  168. info_msg "Setting version to: ${UNDERLINE}${version}"
  169. url="https://github.com/docker/compose/releases/download/${version}/${1}-$(uname -s)-$(uname -m)"
  170. sleep "$delay"
  171. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  172. success_msg "Valid url: ${UNDERLINE}${url}"
  173. if [[ -w "${bin_dir}" ]]; then
  174. curl -L "${url}" -o "${bin_dir}/${1}"
  175. chmod +x "${bin_dir}/${1}"
  176. else
  177. sudo curl -L "${url}" -o "${bin_dir}/${1}"
  178. sudo chmod +x "${bin_dir}/${1}"
  179. fi
  180. success_msg "${1} installed"
  181. docker-compose --version
  182. ;;
  183. k9s)
  184. info_msg "Fetching latest ${1} tag from GitHub"
  185. version=$(fetch_version_k9s)
  186. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  187. info_msg "Setting version to: ${UNDERLINE}${version}"
  188. url="https://github.com/derailed/k9s/releases/download/${version}/${1}_$(uname -s)_amd64.tar.gz"
  189. sleep "$delay"
  190. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  191. success_msg "Valid url: ${UNDERLINE}${url}"
  192. [[ -n $(is_x86) ]] || error_msg "Can only download x86 binary. Your arch: $(uname -m)" 1
  193. # Set vars for file download and untar dir
  194. down_file="${url##*/}"
  195. untar_dir="${1}-${version}"
  196. mkdir -pv "/tmp/${untar_dir}"
  197. # Download archive and unpack
  198. curl -L "${url}" -o "/tmp/${down_file}"
  199. tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
  200. # Make binary excutable and move to bin directory
  201. chmod +x "/tmp/${untar_dir}/${1}"
  202. sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
  203. # Remove tmp files
  204. rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
  205. success_msg "${1} installed"
  206. # k9s version
  207. ;;
  208. eza)
  209. info_msg "Fetching latest ${1} tag from GitHub"
  210. version=$(fetch_version_eza)
  211. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  212. info_msg "Setting version to: ${UNDERLINE}${version}"
  213. url="https://github.com/eza-community/eza/releases/download/${version}/${1}_$(uname -m)-unknown-linux-musl.tar.gz"
  214. sleep "$delay"
  215. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  216. success_msg "Valid url: ${UNDERLINE}${url}"
  217. [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
  218. # Set vars for file download and untar dir
  219. down_file="${url##*/}"
  220. untar_dir="${1}-${version}"
  221. mkdir -pv "/tmp/${untar_dir}"
  222. # Download archive and unpack
  223. curl -L "${url}" -o "/tmp/${down_file}"
  224. tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
  225. # Make binary excutable and move to bin directory
  226. chmod +x "/tmp/${untar_dir}/${1}"
  227. sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
  228. # Remove tmp files
  229. rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
  230. success_msg "${1} installed"
  231. # eza --version
  232. ;;
  233. bat)
  234. info_msg "Fetching latest ${1} tag from GitHub"
  235. version=$(fetch_version_bat)
  236. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  237. info_msg "Setting version to: ${UNDERLINE}${version}"
  238. url="https://github.com/sharkdp/bat/releases/download/${version}/${1}-${version}-$(uname -m)-unknown-linux-musl.tar.gz"
  239. sleep "$delay"
  240. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  241. success_msg "Valid url: ${UNDERLINE}${url}"
  242. [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
  243. # Set vars for file download and untar dir
  244. down_file="${url##*/}"
  245. untar_dir="${1}-${version}"
  246. mkdir -pv "/tmp/${untar_dir}"
  247. # Download archive and unpack
  248. curl -L "${url}" -o "/tmp/${down_file}"
  249. tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
  250. # Make binary excutable and move to bin directory
  251. chmod +x "/tmp/${untar_dir}/${1}-${version}-$(uname -m)-unknown-linux-musl/${1}"
  252. sudo_or_mv "/tmp/${untar_dir}/${1}-${version}-$(uname -m)-unknown-linux-musl/${1}" "${bin_dir}/"
  253. # Remove tmp files
  254. rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
  255. success_msg "${1} installed"
  256. # bat --version
  257. ;;
  258. starship)
  259. info_msg "Fetching latest ${1} tag from GitHub"
  260. version=$(fetch_version_starship)
  261. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  262. info_msg "Setting version to: ${UNDERLINE}${version}"
  263. url="https://github.com/starship/starship/releases/download/${version}/${1}-$(uname -m)-unknown-linux-musl.tar.gz"
  264. sleep "$delay"
  265. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  266. success_msg "Valid url: ${UNDERLINE}${url}"
  267. [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
  268. # Set vars for file download and untar dir
  269. down_file="${url##*/}"
  270. untar_dir="${1}-${version}"
  271. mkdir -pv "/tmp/${untar_dir}"
  272. # Download archive and unpack
  273. curl -L "${url}" -o "/tmp/${down_file}"
  274. tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
  275. # Make binary excutable and move to bin directory
  276. chmod +x "/tmp/${untar_dir}/${1}"
  277. sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
  278. # Remove tmp files
  279. rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
  280. success_msg "${1} installed"
  281. # starship --version
  282. ;;
  283. mcfly)
  284. info_msg "Fetching latest ${1} tag from GitHub"
  285. version=$(fetch_version_mcfly)
  286. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  287. info_msg "Setting version to: ${UNDERLINE}${version}"
  288. url="https://github.com/cantino/mcfly/releases/download/${version}/${1}-${version}-$(uname -m)-unknown-linux-musl.tar.gz"
  289. sleep "$delay"
  290. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  291. success_msg "Valid url: ${UNDERLINE}${url}"
  292. [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
  293. # Set vars for file download and untar dir
  294. down_file="${url##*/}"
  295. untar_dir="${1}-${version}"
  296. mkdir -pv "/tmp/${untar_dir}"
  297. # Download archive and unpack
  298. curl -L "${url}" -o "/tmp/${down_file}"
  299. tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
  300. # Make binary excutable and move to bin directory
  301. chmod +x "/tmp/${untar_dir}/${1}"
  302. sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
  303. # Remove tmp files
  304. rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
  305. success_msg "${1} installed"
  306. # mcfly --version
  307. ;;
  308. fzf)
  309. info_msg "Fetching latest ${1} tag from GitHub"
  310. version=$(fetch_version_fzf)
  311. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  312. info_msg "Setting version to: ${UNDERLINE}${version}"
  313. url="https://github.com/junegunn/fzf/releases/download/${version}/${1}-${version}-linux_amd64.tar.gz"
  314. sleep "$delay"
  315. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  316. success_msg "Valid url: ${UNDERLINE}${url}"
  317. [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
  318. [[ -n $(is_x86) ]] || error_msg "Can only download x86 binary. Your arch: $(uname -m)" 1
  319. # Set vars for file download and untar dir
  320. down_file="${url##*/}"
  321. untar_dir="${1}-${version}"
  322. mkdir -pv "/tmp/${untar_dir}"
  323. # Download archive and unpack
  324. curl -L "${url}" -o "/tmp/${down_file}"
  325. tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
  326. # Make binary excutable and move to bin directory
  327. chmod +x "/tmp/${untar_dir}/${1}"
  328. sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
  329. # Remove tmp files
  330. rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
  331. success_msg "${1} installed"
  332. # fzf --version
  333. ;;
  334. jq)
  335. info_msg "Fetching latest ${1} tag from GitHub"
  336. version=$(fetch_version_jq)
  337. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  338. info_msg "Setting version to: ${UNDERLINE}${version}"
  339. url="https://github.com/jqlang/jq/releases/download/${version}/${1}-linux-amd64"
  340. sleep "$delay"
  341. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  342. success_msg "Valid url: ${UNDERLINE}${url}"
  343. [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
  344. if [[ -w "${bin_dir}" ]]; then
  345. curl -L "${url}" -o "${bin_dir}/${1}"
  346. chmod +x "${bin_dir}/${1}"
  347. else
  348. sudo curl -L "${url}" -o "${bin_dir}/${1}"
  349. sudo chmod +x "${bin_dir}/${1}"
  350. fi
  351. success_msg "${1} installed"
  352. # jq --version
  353. ;;
  354. htmlq)
  355. info_msg "Fetching latest ${1} tag from GitHub"
  356. version=$(fetch_version_htmlq)
  357. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  358. info_msg "Setting version to: ${UNDERLINE}${version}"
  359. url="https://github.com/mgdm/htmlq/releases/download/${version}/${1}-$(uname -m)-linux.tar.gz"
  360. sleep "$delay"
  361. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  362. success_msg "Valid url: ${UNDERLINE}${url}"
  363. [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
  364. # Set vars for file download and untar dir
  365. down_file="${url##*/}"
  366. untar_dir="${1}-${version}"
  367. mkdir -pv "/tmp/${untar_dir}"
  368. # Download archive and unpack
  369. curl -L "${url}" -o "/tmp/${down_file}"
  370. tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
  371. # Make binary excutable and move to bin directory
  372. chmod +x "/tmp/${untar_dir}/${1}"
  373. sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
  374. # Remove tmp files
  375. rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
  376. success_msg "${1} installed"
  377. # htmlq --version
  378. ;;
  379. yq)
  380. info_msg "Fetching latest ${1} tag from GitHub"
  381. version=$(fetch_version_yq)
  382. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  383. info_msg "Setting version to: ${UNDERLINE}${version}"
  384. url="https://github.com/mikefarah/yq/releases/download/${version}/${1}_linux_amd64"
  385. sleep "$delay"
  386. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  387. success_msg "Valid url: ${UNDERLINE}${url}"
  388. [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
  389. [[ -n $(is_x86) ]] || error_msg "Can only download x86 binary. Your arch: $(uname -m)" 1
  390. if [[ -w "${bin_dir}" ]]; then
  391. curl -L "${url}" -o "${bin_dir}/${1}"
  392. chmod +x "${bin_dir}/${1}"
  393. else
  394. sudo curl -L "${url}" -o "${bin_dir}/${1}"
  395. sudo chmod +x "${bin_dir}/${1}"
  396. fi
  397. success_msg "${1} installed"
  398. # yq --version
  399. ;;
  400. fd)
  401. info_msg "Fetching latest ${1} tag from GitHub"
  402. version=$(fetch_version_fd)
  403. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  404. info_msg "Setting version to: ${UNDERLINE}${version}"
  405. url="https://github.com/sharkdp/fd/releases/download/${version}/${1}-${version}-$(uname -m)-unknown-linux-musl.tar.gz"
  406. sleep "$delay"
  407. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  408. success_msg "Valid url: ${UNDERLINE}${url}"
  409. [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
  410. # Set vars for file download and untar dir
  411. down_file="${url##*/}"
  412. untar_dir="${1}-${version}"
  413. mkdir -pv "/tmp/${untar_dir}"
  414. # Download archive and unpack
  415. curl -L "${url}" -o "/tmp/${down_file}"
  416. tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
  417. # Make binary excutable and move to bin directory
  418. chmod +x "/tmp/${untar_dir}/${1}-${version}-$(uname -m)-unknown-linux-musl/${1}"
  419. sudo_or_mv "/tmp/${untar_dir}/${1}-${version}-$(uname -m)-unknown-linux-musl/${1}" "${bin_dir}/"
  420. # Remove tmp files
  421. rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
  422. success_msg "${1} installed"
  423. # fd --version
  424. ;;
  425. upx)
  426. info_msg "Fetching latest ${1} tag from GitHub"
  427. version=$(fetch_version_upx)
  428. [[ -n "${version}" ]] || error_msg "Error fetching version" 1
  429. info_msg "Setting version to: ${UNDERLINE}${version}"
  430. url="https://github.com/upx/upx/releases/download/${version}/${1}-${version##*v}-amd64_linux.tar.xz"
  431. sleep "$delay"
  432. [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
  433. success_msg "Valid url: ${UNDERLINE}${url}"
  434. [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
  435. [[ -n $(is_x86) ]] || error_msg "Can only download x86 binary. Your arch: $(uname -m)" 1
  436. # Set vars for file download and untar dir
  437. down_file="${url##*/}"
  438. untar_dir="${1}-${version}"
  439. mkdir -pv "/tmp/${untar_dir}"
  440. # Download archive and unpack
  441. curl -L "${url}" -o "/tmp/${down_file}"
  442. tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
  443. # Make binary excutable and move to bin directory
  444. chmod +x "/tmp/${untar_dir}/${1}-${version##*v}-amd64_linux/${1}"
  445. sudo_or_mv "/tmp/${untar_dir}/${1}-${version##*v}-amd64_linux/${1}" "${bin_dir}/"
  446. # Remove tmp files
  447. rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
  448. success_msg "${1} installed"
  449. # upx --version
  450. ;;
  451. *)
  452. error_msg "Unknown program: ${CLEAR}${UNDERLINE}${1}"
  453. error_msg "List of available binaries: ${CLEAR}${UNDERLINE}${binaries}" 1
  454. ;;
  455. esac