├── .github └── FUNDING.yml ├── .gitignore ├── .travis.yml ├── Cargo.lock ├── Cargo.toml ├── Cook.toml.example ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── post_cook.sh ├── pre_cook.sh ├── src ├── config.rs ├── container.rs ├── deploy.rs ├── hash.rs ├── main.rs └── term_print.rs └── ssh_deploy.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: iddm 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | *.swo 3 | *.swp 4 | *.md5 5 | *.tar 6 | cooked 7 | Cook.toml 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | rust: 3 | - stable 4 | - beta 5 | - nightly 6 | os: 7 | - linux 8 | matrix: 9 | allow_failures: 10 | - nightly 11 | before_script: 12 | - export PATH="$PATH:$HOME/.cargo/bin" 13 | script: 14 | - cargo build --all-features 15 | - cargo test --all-features 16 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "1.1.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "ansi_term" 16 | version = "0.12.1" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" 19 | dependencies = [ 20 | "winapi 0.3.9", 21 | ] 22 | 23 | [[package]] 24 | name = "atty" 25 | version = "0.2.14" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 28 | dependencies = [ 29 | "hermit-abi", 30 | "libc", 31 | "winapi 0.3.9", 32 | ] 33 | 34 | [[package]] 35 | name = "autocfg" 36 | version = "1.1.0" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 39 | 40 | [[package]] 41 | name = "bitflags" 42 | version = "1.3.2" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 45 | 46 | [[package]] 47 | name = "bitflags" 48 | version = "2.4.1" 49 | source = "registry+https://github.com/rust-lang/crates.io-index" 50 | checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" 51 | 52 | [[package]] 53 | name = "bzip2" 54 | version = "0.4.4" 55 | source = "registry+https://github.com/rust-lang/crates.io-index" 56 | checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" 57 | dependencies = [ 58 | "bzip2-sys", 59 | "libc", 60 | ] 61 | 62 | [[package]] 63 | name = "bzip2-sys" 64 | version = "0.1.11+1.0.8" 65 | source = "registry+https://github.com/rust-lang/crates.io-index" 66 | checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" 67 | dependencies = [ 68 | "cc", 69 | "libc", 70 | "pkg-config", 71 | ] 72 | 73 | [[package]] 74 | name = "cargo-cook" 75 | version = "1.1.0" 76 | dependencies = [ 77 | "bzip2", 78 | "clap", 79 | "lazy_static", 80 | "regex", 81 | "rpassword", 82 | "rust-crypto", 83 | "serde", 84 | "ssh2", 85 | "sysconf", 86 | "tar", 87 | "term", 88 | "toml", 89 | ] 90 | 91 | [[package]] 92 | name = "cc" 93 | version = "1.0.83" 94 | source = "registry+https://github.com/rust-lang/crates.io-index" 95 | checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" 96 | dependencies = [ 97 | "libc", 98 | ] 99 | 100 | [[package]] 101 | name = "cfg-if" 102 | version = "1.0.0" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 105 | 106 | [[package]] 107 | name = "clap" 108 | version = "2.34.0" 109 | source = "registry+https://github.com/rust-lang/crates.io-index" 110 | checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" 111 | dependencies = [ 112 | "ansi_term", 113 | "atty", 114 | "bitflags 1.3.2", 115 | "strsim", 116 | "textwrap", 117 | "unicode-width", 118 | "vec_map", 119 | ] 120 | 121 | [[package]] 122 | name = "dirs-next" 123 | version = "2.0.0" 124 | source = "registry+https://github.com/rust-lang/crates.io-index" 125 | checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" 126 | dependencies = [ 127 | "cfg-if", 128 | "dirs-sys-next", 129 | ] 130 | 131 | [[package]] 132 | name = "dirs-sys-next" 133 | version = "0.1.2" 134 | source = "registry+https://github.com/rust-lang/crates.io-index" 135 | checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" 136 | dependencies = [ 137 | "libc", 138 | "redox_users", 139 | "winapi 0.3.9", 140 | ] 141 | 142 | [[package]] 143 | name = "errno" 144 | version = "0.2.8" 145 | source = "registry+https://github.com/rust-lang/crates.io-index" 146 | checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" 147 | dependencies = [ 148 | "errno-dragonfly", 149 | "libc", 150 | "winapi 0.3.9", 151 | ] 152 | 153 | [[package]] 154 | name = "errno-dragonfly" 155 | version = "0.1.2" 156 | source = "registry+https://github.com/rust-lang/crates.io-index" 157 | checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" 158 | dependencies = [ 159 | "cc", 160 | "libc", 161 | ] 162 | 163 | [[package]] 164 | name = "filetime" 165 | version = "0.2.23" 166 | source = "registry+https://github.com/rust-lang/crates.io-index" 167 | checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" 168 | dependencies = [ 169 | "cfg-if", 170 | "libc", 171 | "redox_syscall 0.4.1", 172 | "windows-sys", 173 | ] 174 | 175 | [[package]] 176 | name = "fuchsia-cprng" 177 | version = "0.1.1" 178 | source = "registry+https://github.com/rust-lang/crates.io-index" 179 | checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" 180 | 181 | [[package]] 182 | name = "gcc" 183 | version = "0.3.55" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" 186 | 187 | [[package]] 188 | name = "getrandom" 189 | version = "0.2.11" 190 | source = "registry+https://github.com/rust-lang/crates.io-index" 191 | checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" 192 | dependencies = [ 193 | "cfg-if", 194 | "libc", 195 | "wasi 0.11.0+wasi-snapshot-preview1", 196 | ] 197 | 198 | [[package]] 199 | name = "hermit-abi" 200 | version = "0.1.19" 201 | source = "registry+https://github.com/rust-lang/crates.io-index" 202 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 203 | dependencies = [ 204 | "libc", 205 | ] 206 | 207 | [[package]] 208 | name = "instant" 209 | version = "0.1.12" 210 | source = "registry+https://github.com/rust-lang/crates.io-index" 211 | checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" 212 | dependencies = [ 213 | "cfg-if", 214 | ] 215 | 216 | [[package]] 217 | name = "kernel32-sys" 218 | version = "0.2.2" 219 | source = "registry+https://github.com/rust-lang/crates.io-index" 220 | checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" 221 | dependencies = [ 222 | "winapi 0.2.8", 223 | "winapi-build", 224 | ] 225 | 226 | [[package]] 227 | name = "lazy_static" 228 | version = "1.4.0" 229 | source = "registry+https://github.com/rust-lang/crates.io-index" 230 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 231 | 232 | [[package]] 233 | name = "libc" 234 | version = "0.2.150" 235 | source = "registry+https://github.com/rust-lang/crates.io-index" 236 | checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" 237 | 238 | [[package]] 239 | name = "libredox" 240 | version = "0.0.1" 241 | source = "registry+https://github.com/rust-lang/crates.io-index" 242 | checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" 243 | dependencies = [ 244 | "bitflags 2.4.1", 245 | "libc", 246 | "redox_syscall 0.4.1", 247 | ] 248 | 249 | [[package]] 250 | name = "libssh2-sys" 251 | version = "0.3.0" 252 | source = "registry+https://github.com/rust-lang/crates.io-index" 253 | checksum = "2dc8a030b787e2119a731f1951d6a773e2280c660f8ec4b0f5e1505a386e71ee" 254 | dependencies = [ 255 | "cc", 256 | "libc", 257 | "libz-sys", 258 | "openssl-sys", 259 | "pkg-config", 260 | "vcpkg", 261 | ] 262 | 263 | [[package]] 264 | name = "libz-sys" 265 | version = "1.1.12" 266 | source = "registry+https://github.com/rust-lang/crates.io-index" 267 | checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" 268 | dependencies = [ 269 | "cc", 270 | "libc", 271 | "pkg-config", 272 | "vcpkg", 273 | ] 274 | 275 | [[package]] 276 | name = "lock_api" 277 | version = "0.4.11" 278 | source = "registry+https://github.com/rust-lang/crates.io-index" 279 | checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" 280 | dependencies = [ 281 | "autocfg", 282 | "scopeguard", 283 | ] 284 | 285 | [[package]] 286 | name = "memchr" 287 | version = "2.6.4" 288 | source = "registry+https://github.com/rust-lang/crates.io-index" 289 | checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" 290 | 291 | [[package]] 292 | name = "openssl-sys" 293 | version = "0.9.97" 294 | source = "registry+https://github.com/rust-lang/crates.io-index" 295 | checksum = "c3eaad34cdd97d81de97964fc7f29e2d104f483840d906ef56daa1912338460b" 296 | dependencies = [ 297 | "cc", 298 | "libc", 299 | "pkg-config", 300 | "vcpkg", 301 | ] 302 | 303 | [[package]] 304 | name = "parking_lot" 305 | version = "0.11.2" 306 | source = "registry+https://github.com/rust-lang/crates.io-index" 307 | checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" 308 | dependencies = [ 309 | "instant", 310 | "lock_api", 311 | "parking_lot_core", 312 | ] 313 | 314 | [[package]] 315 | name = "parking_lot_core" 316 | version = "0.8.6" 317 | source = "registry+https://github.com/rust-lang/crates.io-index" 318 | checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" 319 | dependencies = [ 320 | "cfg-if", 321 | "instant", 322 | "libc", 323 | "redox_syscall 0.2.16", 324 | "smallvec", 325 | "winapi 0.3.9", 326 | ] 327 | 328 | [[package]] 329 | name = "pkg-config" 330 | version = "0.3.27" 331 | source = "registry+https://github.com/rust-lang/crates.io-index" 332 | checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" 333 | 334 | [[package]] 335 | name = "proc-macro2" 336 | version = "1.0.70" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" 339 | dependencies = [ 340 | "unicode-ident", 341 | ] 342 | 343 | [[package]] 344 | name = "quote" 345 | version = "1.0.33" 346 | source = "registry+https://github.com/rust-lang/crates.io-index" 347 | checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" 348 | dependencies = [ 349 | "proc-macro2", 350 | ] 351 | 352 | [[package]] 353 | name = "rand" 354 | version = "0.3.23" 355 | source = "registry+https://github.com/rust-lang/crates.io-index" 356 | checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" 357 | dependencies = [ 358 | "libc", 359 | "rand 0.4.6", 360 | ] 361 | 362 | [[package]] 363 | name = "rand" 364 | version = "0.4.6" 365 | source = "registry+https://github.com/rust-lang/crates.io-index" 366 | checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" 367 | dependencies = [ 368 | "fuchsia-cprng", 369 | "libc", 370 | "rand_core 0.3.1", 371 | "rdrand", 372 | "winapi 0.3.9", 373 | ] 374 | 375 | [[package]] 376 | name = "rand_core" 377 | version = "0.3.1" 378 | source = "registry+https://github.com/rust-lang/crates.io-index" 379 | checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" 380 | dependencies = [ 381 | "rand_core 0.4.2", 382 | ] 383 | 384 | [[package]] 385 | name = "rand_core" 386 | version = "0.4.2" 387 | source = "registry+https://github.com/rust-lang/crates.io-index" 388 | checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" 389 | 390 | [[package]] 391 | name = "rdrand" 392 | version = "0.4.0" 393 | source = "registry+https://github.com/rust-lang/crates.io-index" 394 | checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" 395 | dependencies = [ 396 | "rand_core 0.3.1", 397 | ] 398 | 399 | [[package]] 400 | name = "redox_syscall" 401 | version = "0.2.16" 402 | source = "registry+https://github.com/rust-lang/crates.io-index" 403 | checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" 404 | dependencies = [ 405 | "bitflags 1.3.2", 406 | ] 407 | 408 | [[package]] 409 | name = "redox_syscall" 410 | version = "0.4.1" 411 | source = "registry+https://github.com/rust-lang/crates.io-index" 412 | checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" 413 | dependencies = [ 414 | "bitflags 1.3.2", 415 | ] 416 | 417 | [[package]] 418 | name = "redox_users" 419 | version = "0.4.4" 420 | source = "registry+https://github.com/rust-lang/crates.io-index" 421 | checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" 422 | dependencies = [ 423 | "getrandom", 424 | "libredox", 425 | "thiserror", 426 | ] 427 | 428 | [[package]] 429 | name = "regex" 430 | version = "1.10.2" 431 | source = "registry+https://github.com/rust-lang/crates.io-index" 432 | checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" 433 | dependencies = [ 434 | "aho-corasick", 435 | "memchr", 436 | "regex-automata", 437 | "regex-syntax", 438 | ] 439 | 440 | [[package]] 441 | name = "regex-automata" 442 | version = "0.4.3" 443 | source = "registry+https://github.com/rust-lang/crates.io-index" 444 | checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" 445 | dependencies = [ 446 | "aho-corasick", 447 | "memchr", 448 | "regex-syntax", 449 | ] 450 | 451 | [[package]] 452 | name = "regex-syntax" 453 | version = "0.8.2" 454 | source = "registry+https://github.com/rust-lang/crates.io-index" 455 | checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" 456 | 457 | [[package]] 458 | name = "rpassword" 459 | version = "5.0.1" 460 | source = "registry+https://github.com/rust-lang/crates.io-index" 461 | checksum = "ffc936cf8a7ea60c58f030fd36a612a48f440610214dc54bc36431f9ea0c3efb" 462 | dependencies = [ 463 | "libc", 464 | "winapi 0.3.9", 465 | ] 466 | 467 | [[package]] 468 | name = "rust-crypto" 469 | version = "0.2.36" 470 | source = "registry+https://github.com/rust-lang/crates.io-index" 471 | checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" 472 | dependencies = [ 473 | "gcc", 474 | "libc", 475 | "rand 0.3.23", 476 | "rustc-serialize", 477 | "time", 478 | ] 479 | 480 | [[package]] 481 | name = "rustc-serialize" 482 | version = "0.3.25" 483 | source = "registry+https://github.com/rust-lang/crates.io-index" 484 | checksum = "fe834bc780604f4674073badbad26d7219cadfb4a2275802db12cbae17498401" 485 | 486 | [[package]] 487 | name = "rustversion" 488 | version = "1.0.14" 489 | source = "registry+https://github.com/rust-lang/crates.io-index" 490 | checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" 491 | 492 | [[package]] 493 | name = "scopeguard" 494 | version = "1.2.0" 495 | source = "registry+https://github.com/rust-lang/crates.io-index" 496 | checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" 497 | 498 | [[package]] 499 | name = "serde" 500 | version = "1.0.193" 501 | source = "registry+https://github.com/rust-lang/crates.io-index" 502 | checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" 503 | dependencies = [ 504 | "serde_derive", 505 | ] 506 | 507 | [[package]] 508 | name = "serde_derive" 509 | version = "1.0.193" 510 | source = "registry+https://github.com/rust-lang/crates.io-index" 511 | checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" 512 | dependencies = [ 513 | "proc-macro2", 514 | "quote", 515 | "syn", 516 | ] 517 | 518 | [[package]] 519 | name = "smallvec" 520 | version = "1.11.2" 521 | source = "registry+https://github.com/rust-lang/crates.io-index" 522 | checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" 523 | 524 | [[package]] 525 | name = "ssh2" 526 | version = "0.9.4" 527 | source = "registry+https://github.com/rust-lang/crates.io-index" 528 | checksum = "e7fe461910559f6d5604c3731d00d2aafc4a83d1665922e280f42f9a168d5455" 529 | dependencies = [ 530 | "bitflags 1.3.2", 531 | "libc", 532 | "libssh2-sys", 533 | "parking_lot", 534 | ] 535 | 536 | [[package]] 537 | name = "strsim" 538 | version = "0.8.0" 539 | source = "registry+https://github.com/rust-lang/crates.io-index" 540 | checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" 541 | 542 | [[package]] 543 | name = "syn" 544 | version = "2.0.39" 545 | source = "registry+https://github.com/rust-lang/crates.io-index" 546 | checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" 547 | dependencies = [ 548 | "proc-macro2", 549 | "quote", 550 | "unicode-ident", 551 | ] 552 | 553 | [[package]] 554 | name = "sysconf" 555 | version = "0.3.4" 556 | source = "registry+https://github.com/rust-lang/crates.io-index" 557 | checksum = "59e93f5d45535f49b6a05ef7ac2f0f795d28de494cf53a512751602c9849bea3" 558 | dependencies = [ 559 | "errno", 560 | "kernel32-sys", 561 | "libc", 562 | "winapi 0.2.8", 563 | ] 564 | 565 | [[package]] 566 | name = "tar" 567 | version = "0.4.40" 568 | source = "registry+https://github.com/rust-lang/crates.io-index" 569 | checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" 570 | dependencies = [ 571 | "filetime", 572 | "libc", 573 | "xattr", 574 | ] 575 | 576 | [[package]] 577 | name = "term" 578 | version = "0.7.0" 579 | source = "registry+https://github.com/rust-lang/crates.io-index" 580 | checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" 581 | dependencies = [ 582 | "dirs-next", 583 | "rustversion", 584 | "winapi 0.3.9", 585 | ] 586 | 587 | [[package]] 588 | name = "textwrap" 589 | version = "0.11.0" 590 | source = "registry+https://github.com/rust-lang/crates.io-index" 591 | checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" 592 | dependencies = [ 593 | "unicode-width", 594 | ] 595 | 596 | [[package]] 597 | name = "thiserror" 598 | version = "1.0.50" 599 | source = "registry+https://github.com/rust-lang/crates.io-index" 600 | checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" 601 | dependencies = [ 602 | "thiserror-impl", 603 | ] 604 | 605 | [[package]] 606 | name = "thiserror-impl" 607 | version = "1.0.50" 608 | source = "registry+https://github.com/rust-lang/crates.io-index" 609 | checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" 610 | dependencies = [ 611 | "proc-macro2", 612 | "quote", 613 | "syn", 614 | ] 615 | 616 | [[package]] 617 | name = "time" 618 | version = "0.1.45" 619 | source = "registry+https://github.com/rust-lang/crates.io-index" 620 | checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" 621 | dependencies = [ 622 | "libc", 623 | "wasi 0.10.0+wasi-snapshot-preview1", 624 | "winapi 0.3.9", 625 | ] 626 | 627 | [[package]] 628 | name = "toml" 629 | version = "0.5.11" 630 | source = "registry+https://github.com/rust-lang/crates.io-index" 631 | checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" 632 | dependencies = [ 633 | "serde", 634 | ] 635 | 636 | [[package]] 637 | name = "unicode-ident" 638 | version = "1.0.12" 639 | source = "registry+https://github.com/rust-lang/crates.io-index" 640 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 641 | 642 | [[package]] 643 | name = "unicode-width" 644 | version = "0.1.11" 645 | source = "registry+https://github.com/rust-lang/crates.io-index" 646 | checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" 647 | 648 | [[package]] 649 | name = "vcpkg" 650 | version = "0.2.15" 651 | source = "registry+https://github.com/rust-lang/crates.io-index" 652 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" 653 | 654 | [[package]] 655 | name = "vec_map" 656 | version = "0.8.2" 657 | source = "registry+https://github.com/rust-lang/crates.io-index" 658 | checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" 659 | 660 | [[package]] 661 | name = "wasi" 662 | version = "0.10.0+wasi-snapshot-preview1" 663 | source = "registry+https://github.com/rust-lang/crates.io-index" 664 | checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" 665 | 666 | [[package]] 667 | name = "wasi" 668 | version = "0.11.0+wasi-snapshot-preview1" 669 | source = "registry+https://github.com/rust-lang/crates.io-index" 670 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 671 | 672 | [[package]] 673 | name = "winapi" 674 | version = "0.2.8" 675 | source = "registry+https://github.com/rust-lang/crates.io-index" 676 | checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" 677 | 678 | [[package]] 679 | name = "winapi" 680 | version = "0.3.9" 681 | source = "registry+https://github.com/rust-lang/crates.io-index" 682 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 683 | dependencies = [ 684 | "winapi-i686-pc-windows-gnu", 685 | "winapi-x86_64-pc-windows-gnu", 686 | ] 687 | 688 | [[package]] 689 | name = "winapi-build" 690 | version = "0.1.1" 691 | source = "registry+https://github.com/rust-lang/crates.io-index" 692 | checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" 693 | 694 | [[package]] 695 | name = "winapi-i686-pc-windows-gnu" 696 | version = "0.4.0" 697 | source = "registry+https://github.com/rust-lang/crates.io-index" 698 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 699 | 700 | [[package]] 701 | name = "winapi-x86_64-pc-windows-gnu" 702 | version = "0.4.0" 703 | source = "registry+https://github.com/rust-lang/crates.io-index" 704 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 705 | 706 | [[package]] 707 | name = "windows-sys" 708 | version = "0.52.0" 709 | source = "registry+https://github.com/rust-lang/crates.io-index" 710 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 711 | dependencies = [ 712 | "windows-targets", 713 | ] 714 | 715 | [[package]] 716 | name = "windows-targets" 717 | version = "0.52.0" 718 | source = "registry+https://github.com/rust-lang/crates.io-index" 719 | checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" 720 | dependencies = [ 721 | "windows_aarch64_gnullvm", 722 | "windows_aarch64_msvc", 723 | "windows_i686_gnu", 724 | "windows_i686_msvc", 725 | "windows_x86_64_gnu", 726 | "windows_x86_64_gnullvm", 727 | "windows_x86_64_msvc", 728 | ] 729 | 730 | [[package]] 731 | name = "windows_aarch64_gnullvm" 732 | version = "0.52.0" 733 | source = "registry+https://github.com/rust-lang/crates.io-index" 734 | checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" 735 | 736 | [[package]] 737 | name = "windows_aarch64_msvc" 738 | version = "0.52.0" 739 | source = "registry+https://github.com/rust-lang/crates.io-index" 740 | checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" 741 | 742 | [[package]] 743 | name = "windows_i686_gnu" 744 | version = "0.52.0" 745 | source = "registry+https://github.com/rust-lang/crates.io-index" 746 | checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" 747 | 748 | [[package]] 749 | name = "windows_i686_msvc" 750 | version = "0.52.0" 751 | source = "registry+https://github.com/rust-lang/crates.io-index" 752 | checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" 753 | 754 | [[package]] 755 | name = "windows_x86_64_gnu" 756 | version = "0.52.0" 757 | source = "registry+https://github.com/rust-lang/crates.io-index" 758 | checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" 759 | 760 | [[package]] 761 | name = "windows_x86_64_gnullvm" 762 | version = "0.52.0" 763 | source = "registry+https://github.com/rust-lang/crates.io-index" 764 | checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" 765 | 766 | [[package]] 767 | name = "windows_x86_64_msvc" 768 | version = "0.52.0" 769 | source = "registry+https://github.com/rust-lang/crates.io-index" 770 | checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" 771 | 772 | [[package]] 773 | name = "xattr" 774 | version = "1.0.1" 775 | source = "registry+https://github.com/rust-lang/crates.io-index" 776 | checksum = "f4686009f71ff3e5c4dbcf1a282d0a44db3f021ba69350cd42086b3e5f1c6985" 777 | dependencies = [ 778 | "libc", 779 | ] 780 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cargo-cook" 3 | version = "1.1.0" 4 | authors = ["Victor Polevoy "] 5 | readme = "README.md" 6 | repository = "https://github.com/iddm/cargo-cook" 7 | homepage = "https://github.com/iddm/cargo-cook" 8 | license = "MIT/Apache-2.0" 9 | description = "A third-party cargo extension which allows you to cook your crate" 10 | edition = "2018" 11 | keywords = ["cargo", "package", "cook", "make"] 12 | categories = ["development-tools::cargo-plugins"] 13 | 14 | [[bin]] 15 | name = "cargo-cook" 16 | 17 | [dependencies] 18 | clap = "2" 19 | toml = "0.5" 20 | serde = { version = "1", features = ["derive"] } 21 | regex = "1" 22 | tar = "0.4" 23 | rust-crypto = "0.2" 24 | term = "0.7" 25 | lazy_static = "1" 26 | rpassword = "5" 27 | sysconf = "0.3" 28 | 29 | [features] 30 | default = ["compression", "deploy", "ssh"] 31 | compression = ["bzip2"] 32 | deploy = ["ssh"] 33 | ssh = ["ssh2"] 34 | 35 | [dependencies.bzip2] 36 | version = "0.4" 37 | optional = true 38 | 39 | [dependencies.ssh2] 40 | version = "0.9" 41 | optional = true 42 | -------------------------------------------------------------------------------- /Cook.toml.example: -------------------------------------------------------------------------------- 1 | [cook] 2 | target_directory = "target/release" 3 | target_rename = "cargocook" 4 | hashes = ["md5", "sha256", "sha512"] 5 | containers = ["tar", "tar.bzip2"] 6 | pre_cook = "pre_cook.sh" 7 | post_cook = "post_cook.sh" 8 | include_dependencies = true 9 | cook_directory = "cooked/" 10 | 11 | [cook.deploy] 12 | targets = ["fscopy", "ssh"] 13 | 14 | [cook.deploy.fscopy] 15 | path = "/tmp" 16 | 17 | [cook.deploy.ssh] 18 | hostname = "github.com:80" # Host:port format. 19 | username = "vvv" 20 | remote_path = "/home/vvv/cooked/" # must be absolute path! 21 | deploy_script = "ssh_deploy.sh" # Will be executed on remote server. 22 | 23 | # If source is a file then it will be copied to the destination. 24 | # If the source is a directory then the destination field is also a directory and `filter` field can be used to determine which files to take. 25 | [[cook.ingredient]] 26 | source = "Cargo.toml" 27 | destination = "Cargo.toml" 28 | 29 | [[cook.ingredient]] 30 | source = "src" 31 | destination = "src" 32 | 33 | [[cook.ingredient]] 34 | source = "./" 35 | filter = "(LICENSE-*)" 36 | destination = "licenses/" 37 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 Victor Polevoy 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Victor Polevoy 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `cargo cook` 2 | 3 | [![](https://meritbadge.herokuapp.com/cargo-cook)](https://crates.io/crates/cargo-cook) [![](https://travis-ci.org/iddm/cargo-cook.svg?branch=master)](https://travis-ci.org/iddm/cargo-cook) 4 | 5 | A third-party cargo extension which lets you cook your crate. What it does: 6 | 7 | 1. Collects all the files you specified (ingredients) as same as crate's artifact (binary or a library). 8 | 2. Puts everything from `.1` into a container with possible compression. 9 | 3. Calculates hash-sums for each of container from `.2`. 10 | 4. Uploads all the files from `.3` into desired location. 11 | 12 | If you still have not understood what is it then just read this: 13 | 14 | > After building a crate you have a produced binary file (or a library). You may want to upload it somewhere for further downloading and use. For example, you have made a game called `rustquake` in pure Rust. You want to release it so you compile it in release mode with all optimizations and then you may want to upload the binary (and some other files like config files, libraries, images, shaders, etc) somewhere. It would also be nice to compress all of this. So, you manually create an archive, for example, `rustquake-0.1.1.tar.gz` where you manually put all the files you need. Then you go to your server, put the archive in some folder which your web-server knows about manually again. This is a lot of routine work. But all ot these steps may be performed automatically by the `cargo cook`. 15 | 16 | # Configuring 17 | 18 | To make it work with your crate you must create a file `Cook.toml` in the root directory of your crate. 19 | Let's look at the [`Cook.toml.example`](https://github.com/iddm/cargo-cook/blob/master/Cook.toml.example) of `cargo-cook` crate: 20 | 21 | ```toml 22 | [cook] 23 | target_directory = "target/release" 24 | target_rename = "cargocook" 25 | hashes = ["md5", "sha256", "sha512"] 26 | containers = ["tar", "tar.bzip2"] 27 | pre_cook = "pre_cook.sh" 28 | post_cook = "post_cook.sh" 29 | include_dependencies = true 30 | cook_directory = "cooked/" 31 | 32 | [cook.deploy] 33 | targets = ["fscopy", "ssh"] 34 | 35 | [cook.deploy.fscopy] 36 | path = "/tmp" 37 | 38 | [cook.deploy.ssh] 39 | hostname = "" # Host:port format. 40 | username = "" 41 | remote_path = "" # must be absolute path! 42 | deploy_script = "ssh_deploy.sh" # Will be executed on remote server. 43 | 44 | 45 | # If source is a file then it will be copied to the destination. 46 | # If the source is a directory then the destination field is also a directory and `filter` field can be used to determine which files to take. 47 | [[cook.ingredient]] 48 | source = "Cargo.toml" 49 | destination = "Cargo.toml" 50 | 51 | [[cook.ingredient]] 52 | source = "src" 53 | destination = "src" 54 | 55 | [[cook.ingredient]] 56 | source = "./" 57 | filter = "(LICENSE-*)" 58 | destination = "licenses/" 59 | ``` 60 | 61 | **Cook** 62 | - `target_directory` - a directory where to find your crate artifacts. 63 | - `target_rename` **(Optional)** - rename the target file before packaging into a container. 64 | - `hashes` **(Optional)** - a list of hash-sum algorithms which will be used for calculating hashsumm of the containers. 65 | - `containers` - a list of containers into which your ingredients will be packed. 66 | - `pre_cook` **(Optional)** - a script which will be executed before cooking. 67 | - `post_cook` **(Optional)** - a script which will be executed after cooking. 68 | - `include_dependencies` **(Optional)** - include crate dependencies into the container. 69 | - `cook_directory` - a directory where containers will be put. 70 | 71 | **Deploy** 72 | - `targets` - a list of deploy targets. 73 | 74 | **deploy.fscopy** 75 | - `path` - a string where to copy cooked files. 76 | 77 | **deploy.ssh** 78 | - `hostname` - a string with hostname and port (`github.com:80` for example). 79 | - `username` - a string with username which will be used for deploying. Password will be asked during deployment. 80 | - `remote_path` - a string which points to a remote path where cooked files will be copied. 81 | - `deploy_script` **(Optional)** - a string which will be executed on the remote server with `remote_path` as working directory. 82 | 83 | **Ingredient** 84 | - `source` - a string which is a path to file or a directory. If it is a directory then `filter` field may be used. 85 | - `filter` **(Optional)** - a regular expression which will be used to determine the ingredients. 86 | - `destination` - a string which is a path to file or a directory. If `source` is a file then `destination` is also a file, otherwise it is a directory where files from `source` directory will be put. 87 | 88 | So, if you will just perform `cargo cook` in the directory with the `cargo cook` crate with the configuration described above it will give you: 89 | 90 | ```bash 91 | $ cd cargo-cook 92 | 93 | $ cargo cook 94 | Cooking cargo-cook v0.1.5 95 | Executing Pre-cook 96 | Hello from pre_cook.sh 97 | Pre-cook returned 0 98 | Cooked /home/workspace/cargo-cook/cooked/cargo-cook-0.1.5.tar 99 | Executing Post-cook 100 | Hello from post_cook.sh 101 | Post-cook returned 0 102 | Finished cooking 103 | 104 | $ ls cooked/ 105 | cargo-cook-0.1.5.tar 106 | cargo-cook-0.1.5.tar.md5 107 | cargo-cook-0.1.5.tar.sha256 108 | cargo-cook-0.1.5.tar.sha512 109 | 110 | $ tar -xvf cargo-cook-0.1.5.tar 111 | Cargo.toml 112 | src/main.rs 113 | src/container.rs 114 | src/hash.rs 115 | licenses/LICENSE-APACHE 116 | licenses/LICENSE-MIT 117 | cargocook 118 | ``` 119 | 120 | # Compiling 121 | 122 | Assuming you already have Rust and cargo set up. 123 | 124 | Clone this repository and go into the created directory: 125 | 126 | git clone https://github.com/iddm/cargo-cook.git 127 | cd cargo-cook 128 | 129 | And compile a release version: 130 | 131 | cargo build --release 132 | 133 | You should now have an executable in `[starting directory]/cargo-cook/target/release/cargo-cook`. 134 | 135 | # Installing and Using 136 | 137 | Compile the code as shown in the previous section, then put the `cargo-cook` executable in your PATH. 138 | 139 | My favorite way of doing this is I have a pre-existing directory in `~/bin` that contains little scripts of mine, that dir is added to my PATH in my `.bashrc` so that it's always available, and then I symlink the release version from where it exists to that directory: 140 | 141 | ln -s [starting directory]/cargo-cook/target/release/cargo-cook ~/bin/ 142 | 143 | Once you've done that, because of the way cargo is set up to use third party extensions, in any other Rust project of yours, you should be able to run: 144 | 145 | cargo cook 146 | 147 | and that crate will be cooked. 148 | 149 | There is an option for specifying non-default file name of a recipe (`Cook.toml` is the default one): 150 | 151 | cargo cook -r MyCustomRecipe.toml 152 | 153 | That way you may also invoke `cargo cook` with different recipes: 154 | 155 | cargo cook -r MyCustomRecipeForLinux.toml 156 | cargo cook -r MyCustomRecipeForWindows.toml 157 | 158 | # Contributing 159 | 160 | If you'd like to work on your own version of the code, fork this repo and follow the compiling steps above except with your fork. 161 | 162 | One weird thing if you're running the binary directly instead of through the `cargo` plugin system is that clap doesn't think you're using a subcommand. If you try, you'll get: 163 | 164 | $ ./target/release/cargo-cook whatever 165 | error: Found argument 'whatever', but cargo wasn't expecting any 166 | 167 | USAGE: 168 | cargo 169 | 170 | For more information try --help 171 | 172 | To get around this, either follow the Installation and Usage instructions above and always use `cargo cook whatever` or re-specify `cook` as the subcommand: 173 | 174 | ./target/release/cargo-cook cook whatever 175 | 176 | # License 177 | 178 | `cargo cook` is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0). 179 | 180 | See LICENSE-APACHE and LICENSE-MIT for details. 181 | -------------------------------------------------------------------------------- /post_cook.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Hello from post_cook.sh" 4 | -------------------------------------------------------------------------------- /pre_cook.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Hello from pre_cook.sh" 4 | 5 | -------------------------------------------------------------------------------- /src/config.rs: -------------------------------------------------------------------------------- 1 | #[derive(Default, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, serde::Deserialize)] 2 | pub struct CookIngredient { 3 | pub source: String, 4 | pub filter: Option, 5 | pub destination: String, 6 | } 7 | 8 | #[cfg(feature = "ssh")] 9 | #[derive(Default, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, serde::Deserialize)] 10 | pub struct SshConfig { 11 | pub hostname: String, 12 | pub username: String, 13 | pub remote_path: String, 14 | pub deploy_script: Option, 15 | } 16 | 17 | #[derive(Default, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, serde::Deserialize)] 18 | pub struct FsCopy { 19 | pub path: String, 20 | } 21 | 22 | #[cfg(feature = "deploy")] 23 | #[derive(Default, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, serde::Deserialize)] 24 | pub struct Deploy { 25 | pub targets: Option>, 26 | #[cfg(feature = "ssh")] 27 | pub ssh: Option, 28 | pub fscopy: Option, 29 | } 30 | 31 | #[derive(Default, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, serde::Deserialize)] 32 | pub struct Cook { 33 | pub target_directory: String, 34 | pub target_rename: Option, 35 | pub hashes: Option>, 36 | pub containers: Vec, 37 | pub pre_cook: Option, 38 | pub post_cook: Option, 39 | pub include_dependencies: Option, 40 | pub cook_directory: String, 41 | #[cfg(feature = "deploy")] 42 | pub deploy: Option, 43 | pub ingredient: Option>, 44 | } 45 | 46 | #[derive(Default, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, serde::Deserialize)] 47 | pub struct Package { 48 | pub name: String, 49 | pub version: String, 50 | } 51 | 52 | #[derive(Default, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, serde::Deserialize)] 53 | pub struct CookConfig { 54 | pub cook: Cook, 55 | } 56 | 57 | #[derive(Default, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, serde::Deserialize)] 58 | pub struct CargoConfig { 59 | pub package: Package, 60 | } 61 | -------------------------------------------------------------------------------- /src/container.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | /// A file name and its' content as string. 4 | pub type File = (String, String); 5 | pub type Files = Vec<(String, String)>; 6 | 7 | lazy_static::lazy_static! { 8 | static ref CONTAINERS: HashMap<&'static str, fn(&str, &[File])> = { 9 | let mut m = HashMap::new(); 10 | m.insert("tar", tar as fn(&str, &[File])); 11 | #[cfg(feature = "bzip2")] 12 | m.insert("tar.bzip2", bzip2 as fn(&str, &[File])); 13 | m 14 | }; 15 | } 16 | 17 | #[cfg(feature = "bzip2")] 18 | fn bzip2(destination_file_path: &str, files: &[File]) { 19 | use crate::term_print::*; 20 | use bzip2::read::BzEncoder; 21 | use bzip2::Compression; 22 | use std::fs::File; 23 | use std::io::{Read, Write}; 24 | 25 | const TEMP_FILE: &str = "/tmp/cooked.tar"; 26 | const BZIP2_LABEL: &str = "[bzip2]"; 27 | 28 | tar(TEMP_FILE, files); 29 | let mut tar_file = File::open(TEMP_FILE).unwrap(); 30 | let mut raw_bytes = Vec::new(); 31 | tar_file.read_to_end(&mut raw_bytes).unwrap(); 32 | let mut compressed_bytes = Vec::new(); 33 | let mut compressor = BzEncoder::new(raw_bytes.as_slice(), Compression::best()); 34 | compressor.read_to_end(&mut compressed_bytes).unwrap(); 35 | let ratio = 100f32 / (raw_bytes.len() as f32 / compressed_bytes.len() as f32); 36 | let mut compressed_archive = File::create(destination_file_path).unwrap(); 37 | term_println( 38 | term::color::WHITE, 39 | BZIP2_LABEL, 40 | &format!("Compressed ratio: {:.2}%", ratio), 41 | ); 42 | compressed_archive 43 | .write_all(compressed_bytes.as_slice()) 44 | .unwrap(); 45 | } 46 | 47 | fn tar(destination_file_path: &str, files: &[File]) { 48 | use std::fs::File; 49 | use tar::Builder; 50 | 51 | let file = File::create(destination_file_path).unwrap(); 52 | let mut ar = Builder::new(file); 53 | for f in files { 54 | if let Ok(mut dest_file) = File::open(&f.1) { 55 | ar.append_file(&f.0, &mut dest_file).unwrap(); 56 | } else { 57 | panic!("No such file or directory: {}", f.1); 58 | } 59 | } 60 | } 61 | 62 | pub fn support_container(container: &str) -> bool { 63 | CONTAINERS.get::(container).is_some() 64 | } 65 | 66 | pub fn compress(files: &[File], destination_file_path: &str, container: &str) { 67 | CONTAINERS.get::(container).unwrap()(destination_file_path, files) 68 | } 69 | -------------------------------------------------------------------------------- /src/deploy.rs: -------------------------------------------------------------------------------- 1 | use crate::config::Deploy; 2 | use std::collections::HashMap; 3 | use std::result::Result as StdResult; 4 | use sysconf::{sysconf, SysconfVariable}; 5 | 6 | pub type Result = StdResult<(), String>; 7 | 8 | const BYTES_IN_MB: f64 = 1_048_576.0; 9 | 10 | lazy_static::lazy_static! { 11 | static ref TARGETS: HashMap<&'static str, fn(&str, &Deploy) -> Result> = { 12 | let mut m = HashMap::new(); 13 | #[cfg(feature = "ssh")] 14 | m.insert("ssh", ssh as fn(&str, &Deploy) -> Result); 15 | m.insert("fscopy", fscopy as fn(&str, &Deploy) -> Result); 16 | m 17 | }; 18 | static ref PAGE_SIZE: i64 = sysconf(SysconfVariable::ScPagesize).unwrap() as i64; 19 | } 20 | 21 | fn fscopy(source: &str, d: &Deploy) -> Result { 22 | use crate::term_print::*; 23 | use std::fs; 24 | use std::path::Path; 25 | 26 | const FSCOPY_LABEL: &str = "[fscopy]"; 27 | 28 | if let Some(ref fscopy) = d.fscopy { 29 | let path = Path::new(source); 30 | let dir = fs::read_dir(path).unwrap(); 31 | for entry in dir { 32 | let e = entry.unwrap(); 33 | let entry_path = e.path(); 34 | let path = entry_path.to_str().unwrap(); 35 | if let Some(file_name) = e.file_name().to_str() { 36 | term_rprint( 37 | term::color::WHITE, 38 | FSCOPY_LABEL, 39 | &format!("Copying \"{}\" to \"{}\"", path, fscopy.path), 40 | ); 41 | if let Err(err) = fs::copy(e.path(), &format!("{}/{}", fscopy.path, file_name)) { 42 | term_rprint_finish(); 43 | return Err(err.to_string()); 44 | } 45 | term_rprint( 46 | term::color::WHITE, 47 | FSCOPY_LABEL, 48 | &format!("Copied \"{}\" to \"{}\"", path, fscopy.path), 49 | ); 50 | term_rprint_finish(); 51 | } 52 | } 53 | } 54 | 55 | Ok(()) 56 | } 57 | 58 | #[cfg(feature = "ssh")] 59 | fn ssh(source: &str, d: &Deploy) -> Result { 60 | use crate::term_print::*; 61 | use rpassword::read_password; 62 | use ssh2::Session; 63 | use std::fs::{self, File}; 64 | use std::io::{Read, Write}; 65 | use std::net::TcpStream; 66 | use std::os::unix::fs::PermissionsExt; 67 | use std::path::Path; 68 | 69 | const SSH_LABEL: &str = "[ssh]"; 70 | 71 | let exec = |sess: &Session, cmd: &str| { 72 | let channel_session = sess.channel_session(); 73 | if let Ok(mut channel) = channel_session { 74 | let res = channel.exec(cmd); 75 | if let Err(e) = res { 76 | term_println( 77 | term::color::RED, 78 | SSH_LABEL, 79 | &format!("Failed to execute command: {}", e), 80 | ); 81 | } else { 82 | let mut s = String::new(); 83 | if channel.read_to_string(&mut s).is_ok() && !s.is_empty() { 84 | term_print(term::color::WHITE, &format!("{} ({}):", SSH_LABEL, cmd), &s); 85 | } 86 | } 87 | } else { 88 | term_println( 89 | term::color::RED, 90 | SSH_LABEL, 91 | "Failed to get channel for command execution.", 92 | ); 93 | } 94 | }; 95 | 96 | let send_file = |sess: &Session, local_path: &Path, remote_path: &Path| { 97 | let mut buffer = vec![0; *PAGE_SIZE as usize]; 98 | let mut read = 0u64; 99 | if let Ok(mut file) = File::open(local_path) { 100 | let metadata = file.metadata().unwrap(); 101 | let file_size = metadata.len(); 102 | let file_path_str = local_path.to_str().unwrap(); 103 | let mut remote_file = sess 104 | .scp_send( 105 | remote_path, 106 | metadata.permissions().mode() as i32, 107 | file_size, 108 | None, 109 | ) 110 | .unwrap(); 111 | while let Ok(read_bytes) = file.read(&mut buffer) { 112 | if read_bytes == 0usize { 113 | break; 114 | } 115 | read += read_bytes as u64; 116 | remote_file.write_all(&buffer).unwrap(); 117 | term_rprint( 118 | term::color::WHITE, 119 | SSH_LABEL, 120 | &format!( 121 | "Sending \"{}\" [{:.2} MB of {:.2} MB]", 122 | file_path_str, 123 | read as f64 / BYTES_IN_MB, 124 | file_size as f64 / BYTES_IN_MB 125 | ), 126 | ); 127 | } 128 | term_rprint_finish(); 129 | } 130 | }; 131 | 132 | if let Some(ref ssh) = d.ssh { 133 | term_println( 134 | term::color::WHITE, 135 | SSH_LABEL, 136 | &format!("Connecting to {}", ssh.hostname), 137 | ); 138 | let tcp = TcpStream::connect(&ssh.hostname).unwrap(); 139 | let mut sess = Session::new().unwrap(); 140 | sess.set_tcp_stream(tcp); 141 | sess.handshake().unwrap(); 142 | 143 | for i in 0..3 { 144 | term_print( 145 | term::color::WHITE, 146 | SSH_LABEL, 147 | &format!("Password for {}: ", ssh.username), 148 | ); 149 | let ssh_password = read_password().unwrap(); 150 | 151 | if ssh_password.is_empty() { 152 | if i == 2 { 153 | return Err("SSH password can not be empty.".to_owned()); 154 | } else { 155 | term_println(term::color::YELLOW, SSH_LABEL, "Password can not be empty."); 156 | continue; 157 | } 158 | } 159 | 160 | term_println(term::color::WHITE, SSH_LABEL, "Authorizing..."); 161 | if let Err(e) = sess.userauth_password(&ssh.username, &ssh_password) { 162 | if i == 2 { 163 | return Err(e.to_string()); 164 | } else { 165 | term_println(term::color::RED, SSH_LABEL, &e.to_string()); 166 | continue; 167 | } 168 | } else { 169 | break; 170 | } 171 | } 172 | 173 | term_println(term::color::WHITE, SSH_LABEL, "Uploading files..."); 174 | 175 | let path = Path::new(source); 176 | exec(&sess, &format!("mkdir -p {}", ssh.remote_path)); 177 | let dir = fs::read_dir(path).unwrap(); 178 | for entry in dir { 179 | let e = entry.unwrap(); 180 | let file_name_str = e.file_name().into_string().unwrap(); 181 | let remote_path_str = format!("{}/{}", ssh.remote_path, file_name_str); 182 | let remote_path = Path::new(&remote_path_str); 183 | send_file(&sess, &e.path(), &remote_path); 184 | } 185 | 186 | if let Some(ref ds) = ssh.deploy_script { 187 | term_println( 188 | term::color::WHITE, 189 | SSH_LABEL, 190 | &format!("Uploading deploy script: {}", ds), 191 | ); 192 | 193 | let remote_path_str = format!("{}/{}", ssh.remote_path, ds); 194 | let local_path = Path::new(ds); 195 | let remote_path = Path::new(&remote_path_str); 196 | 197 | send_file(&sess, &local_path, &remote_path); 198 | 199 | term_println( 200 | term::color::WHITE, 201 | SSH_LABEL, 202 | &format!("Executing deploy script: {}", ds), 203 | ); 204 | exec( 205 | &sess, 206 | &format!("cd {}; sh {}", ssh.remote_path, remote_path_str), 207 | ); 208 | exec(&sess, &format!("rm {}", remote_path_str)); 209 | } 210 | } 211 | 212 | Ok(()) 213 | } 214 | 215 | pub fn support_deploy_target(target: &str) -> bool { 216 | TARGETS.get::(&target.to_lowercase()).is_some() 217 | } 218 | 219 | pub fn deploy(target: &str, cook_dir: &str, d: &Deploy) -> Result { 220 | TARGETS.get::(&target.to_lowercase()).unwrap()(cook_dir, d) 221 | } 222 | -------------------------------------------------------------------------------- /src/hash.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | use std::fs::File; 3 | use std::io::{Read, Write}; 4 | 5 | use crypto::digest::Digest; 6 | 7 | lazy_static::lazy_static! { 8 | static ref HASHES: HashMap<&'static str, fn(&[u8]) -> String> = { 9 | let mut m = HashMap::new(); 10 | m.insert("md5", md5 as fn(&[u8]) -> String); 11 | m.insert("sha256", sha256 as fn(&[u8]) -> String); 12 | m.insert("sha512", sha512 as fn(&[u8]) -> String); 13 | m 14 | }; 15 | } 16 | 17 | fn md5(bytes: &[u8]) -> String { 18 | use crypto::md5::Md5; 19 | 20 | let mut hasher = Md5::new(); 21 | hasher.input(bytes); 22 | hasher.result_str() 23 | } 24 | 25 | fn sha256(bytes: &[u8]) -> String { 26 | use crypto::sha2::Sha256; 27 | 28 | let mut hasher = Sha256::new(); 29 | hasher.input(bytes); 30 | hasher.result_str() 31 | } 32 | 33 | fn sha512(bytes: &[u8]) -> String { 34 | use crypto::sha2::Sha512; 35 | 36 | let mut hasher = Sha512::new(); 37 | hasher.input(bytes); 38 | hasher.result_str() 39 | } 40 | 41 | pub fn support_hash_type(hash: &str) -> bool { 42 | HASHES.get::(&hash.to_lowercase()).is_some() 43 | } 44 | 45 | pub fn hash(bytes: &[u8], hash: &str) -> String { 46 | HASHES.get::(&hash.to_lowercase()).unwrap()(bytes) 47 | } 48 | 49 | pub fn file_hash(path: &str, hash_type: &str) -> String { 50 | let mut bytes = Vec::new(); 51 | let mut f = File::open(path).unwrap(); 52 | let _ = f.read_to_end(&mut bytes); 53 | hash(&bytes, hash_type) 54 | } 55 | 56 | pub fn write_file_hash(source: &str, destination: &str, hash_type: &str) { 57 | let mut f = File::create(destination).unwrap(); 58 | let _ = writeln!(f, "{}", file_hash(source, hash_type)); 59 | } 60 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | mod config; 2 | mod container; 3 | #[cfg(feature = "deploy")] 4 | mod deploy; 5 | mod hash; 6 | mod term_print; 7 | 8 | use clap::{App, AppSettings, Arg, SubCommand}; 9 | use regex::Regex; 10 | 11 | use std::fs; 12 | #[cfg(not(debug_assertions))] 13 | use std::panic; 14 | use std::path::Path; 15 | use std::process::Command; 16 | 17 | use config::*; 18 | use term_print::*; 19 | 20 | const CONFIG_FILE_NAME: &str = "Cook.toml"; 21 | const CARGO_TOML: &str = "Cargo.toml"; 22 | const COMMAND_NAME: &str = "cook"; 23 | const COMMAND_DESCRIPTION: &str = "A third-party cargo extension which cooks your crate."; 24 | const COMMAND_AUTHOR: &str = "Victor Polevoy "; 25 | const COMMAND_RECIPE_ARG_NAME: &str = "recipe"; 26 | 27 | fn main() { 28 | #[cfg(not(debug_assertions))] 29 | panic::set_hook(Box::new(|panic_info| { 30 | term_panic(panic_info.payload().downcast_ref::().unwrap()); 31 | })); 32 | 33 | let matches = App::new(format!("cargo-{}", COMMAND_NAME)) 34 | .about(COMMAND_DESCRIPTION) 35 | .author(COMMAND_AUTHOR) 36 | .version(clap::crate_version!()) 37 | // We have to lie about our binary name since this will be a third party 38 | // subcommand for cargo, this trick learned from cargo-outdated 39 | .bin_name("cargo") 40 | // We use a subcommand because parsed after `cargo` is sent to the third party plugin 41 | // which will be interpreted as a subcommand/positional arg by clap 42 | .subcommand( 43 | SubCommand::with_name(COMMAND_NAME) 44 | .about(COMMAND_DESCRIPTION) 45 | .arg( 46 | Arg::with_name(COMMAND_RECIPE_ARG_NAME) 47 | .short("r") 48 | .long(COMMAND_RECIPE_ARG_NAME) 49 | .value_name("FILE") 50 | .default_value(CONFIG_FILE_NAME) 51 | .help("Sets the recipe file to use for cooking.") 52 | .takes_value(true), 53 | ), 54 | ) 55 | .settings(&[AppSettings::SubcommandRequired]) 56 | .get_matches(); 57 | 58 | cook( 59 | matches 60 | .subcommand_matches(COMMAND_NAME) 61 | .expect("The binary hasn't been invoked as a subcommand.") 62 | .value_of(COMMAND_RECIPE_ARG_NAME) 63 | .unwrap_or(CONFIG_FILE_NAME), 64 | ); 65 | } 66 | 67 | fn cook(cook_config_name: &str) { 68 | let cook_config = load_config::(cook_config_name); 69 | let cargo_config = load_config::(CARGO_TOML); 70 | #[cfg(debug_assertions)] 71 | println!( 72 | "Config file name: {}\nConfig contents: {:?}", 73 | cook_config_name, cook_config 74 | ); 75 | parse_config(&cook_config); 76 | let pkg_name = &format!( 77 | "{} v{}", 78 | cargo_config.package.name, cargo_config.package.version 79 | ); 80 | term_println(term::color::BRIGHT_GREEN, "Cooking", pkg_name); 81 | cook_hook(&cook_config.cook, true); 82 | 83 | archive( 84 | &cook_config, 85 | &cargo_config, 86 | collect(&cook_config, &cargo_config), 87 | ); 88 | 89 | #[cfg(feature = "deploy")] 90 | deploy(&cook_config); 91 | 92 | cook_hook(&cook_config.cook, false); 93 | term_println(term::color::BRIGHT_GREEN, "Finished", "cooking"); 94 | } 95 | 96 | fn collect_recursively(source: &str, destination: &str, files: &mut container::Files) { 97 | let path = Path::new(source); 98 | if !path.is_dir() { 99 | panic!("{} is not a directory!", path.display()); 100 | } 101 | for entry in fs::read_dir(path).unwrap() { 102 | let e = entry.unwrap(); 103 | let name = e.file_name().into_string().unwrap(); 104 | files.push(( 105 | format!("{}/{}", destination.to_owned(), name), 106 | e.path().to_str().unwrap().to_owned(), 107 | )); 108 | } 109 | } 110 | 111 | fn collect(c: &CookConfig, cargo: &CargoConfig) -> container::Files { 112 | let mut files = container::Files::new(); 113 | if let Some(ref ingredients) = c.cook.ingredient { 114 | for i in ingredients { 115 | let path = Path::new(&i.source); 116 | if path.is_file() { 117 | files.push((i.source.clone(), i.destination.clone())); 118 | } else if path.is_dir() { 119 | if let Some(ref filter) = i.filter { 120 | let r = Regex::new(filter).unwrap(); 121 | for entry in fs::read_dir(path).unwrap() { 122 | let e = entry.unwrap(); 123 | let name = e.file_name().into_string().unwrap(); 124 | if r.is_match(&name) { 125 | files.push(( 126 | format!("{}/{}", i.destination.clone(), name), 127 | e.path().to_str().unwrap().to_owned(), 128 | )); 129 | } 130 | } 131 | } else { 132 | collect_recursively(&i.source, &i.destination, &mut files); 133 | } 134 | } else { 135 | panic!( 136 | "Specified ingredient ({}) is neither a file nor a directory.", 137 | i.source 138 | ); 139 | } 140 | } 141 | } 142 | 143 | let target_file_name = format!("{}/{}", c.cook.target_directory, cargo.package.name); 144 | let renamed_target_file_name = if let Some(s) = c.cook.target_rename.clone() { 145 | s 146 | } else { 147 | cargo.package.name.clone() 148 | }; 149 | files.push((renamed_target_file_name, target_file_name)); 150 | files 151 | } 152 | 153 | fn archive(c: &CookConfig, cargo: &CargoConfig, cf: container::Files) { 154 | std::fs::create_dir_all(&c.cook.cook_directory).unwrap(); 155 | 156 | for cont in &c.cook.containers { 157 | let file_name = &format!( 158 | "{}/{}-{}", 159 | c.cook.cook_directory, cargo.package.name, cargo.package.version 160 | ); 161 | let archive_file_name = &format!("{}.{}", file_name, cont); 162 | // Archive 163 | container::compress(&cf, archive_file_name, cont); 164 | 165 | // Hash 166 | if let Some(ref hashes) = c.cook.hashes { 167 | for hash_type in hashes { 168 | let hash_file_name = &format!("{}.{}", archive_file_name, hash_type); 169 | hash::write_file_hash(archive_file_name, hash_file_name, hash_type); 170 | } 171 | } 172 | 173 | let archive_file_path = Path::new(archive_file_name).canonicalize().unwrap(); 174 | term_println( 175 | term::color::BRIGHT_GREEN, 176 | "Cooked", 177 | &format!("{}", archive_file_path.display()), 178 | ); 179 | } 180 | } 181 | 182 | // TODO implement uploading the cooked archives: filesystem, ssh, git, ftp, http, etc 183 | #[cfg(feature = "deploy")] 184 | fn deploy(c: &CookConfig) { 185 | if let Some(ref deploy) = c.cook.deploy { 186 | if let Some(ref targets) = deploy.targets { 187 | term_println(term::color::BRIGHT_GREEN, "Deploying", "the crate."); 188 | 189 | for t in targets { 190 | let target_str = format!("[{}]", t); 191 | if let Err(e) = deploy::deploy(t, &c.cook.cook_directory, deploy) { 192 | term_println(term::color::BRIGHT_RED, &target_str, &e); 193 | } else { 194 | term_println(term::color::BRIGHT_GREEN, &target_str, "OK"); 195 | } 196 | } 197 | } 198 | } 199 | } 200 | 201 | fn load_config(file_name: &str) -> T { 202 | let config_toml = match fs::read_to_string(file_name) { 203 | Ok(s) => s, 204 | Err(e) => panic!("Unable to read {}: {}", file_name, e), 205 | }; 206 | toml::de::from_str::(&config_toml) 207 | .unwrap_or_else(|e| panic!("Unable to parse {}: {}", file_name, e)) 208 | } 209 | 210 | fn cook_hook(c: &Cook, pre: bool) -> bool { 211 | let hook = if pre { &c.pre_cook } else { &c.post_cook }; 212 | let hook_name = if pre { "Pre-cook" } else { "Post-cook" }; 213 | 214 | if let Some(ref pre) = *hook { 215 | term_println(term::color::YELLOW, "Executing", hook_name); 216 | let res = Command::new(Path::new(pre).canonicalize().unwrap()).status(); 217 | if let Ok(s) = res { 218 | if s.success() { 219 | term_println( 220 | term::color::BRIGHT_GREEN, 221 | hook_name, 222 | &format!("returned {}", s.code().unwrap_or(0i32)), 223 | ); 224 | } else { 225 | term_println( 226 | term::color::BRIGHT_RED, 227 | hook_name, 228 | &format!("returned {}", s.code().unwrap_or(0i32)), 229 | ); 230 | } 231 | return s.success(); 232 | } else { 233 | panic!("{} failed: {}", hook_name, res.unwrap_err()); 234 | } 235 | } 236 | 237 | true 238 | } 239 | 240 | fn parse_config(c: &CookConfig) { 241 | for cont in &c.cook.containers { 242 | if !container::support_container(cont) { 243 | panic!("The \"{}\" container type is unsupported.", cont); 244 | } 245 | } 246 | 247 | if let Some(ref hashes) = c.cook.hashes { 248 | for h in hashes { 249 | if !hash::support_hash_type(h) { 250 | panic!("The \"{}\" hash type is unsupported.", h); 251 | } 252 | } 253 | } 254 | 255 | #[cfg(feature = "deploy")] 256 | let check_deploy = |c: &CookConfig| { 257 | if let Some(ref deploy) = c.cook.deploy { 258 | if let Some(ref targets) = deploy.targets { 259 | for t in targets { 260 | if !deploy::support_deploy_target(t) { 261 | panic!("The \"{}\" deploy target is unsupported.", t); 262 | } 263 | } 264 | } 265 | } 266 | }; 267 | 268 | #[cfg(feature = "deploy")] 269 | check_deploy(&c); 270 | } 271 | -------------------------------------------------------------------------------- /src/term_print.rs: -------------------------------------------------------------------------------- 1 | #[allow(dead_code)] 2 | pub fn term_rprint(color: term::color::Color, status_text: &str, text: &str) { 3 | let mut t = term::stdout().unwrap(); 4 | 5 | t.carriage_return().unwrap(); 6 | t.delete_line().unwrap(); 7 | t.attr(term::Attr::Bold).unwrap(); 8 | t.fg(color).unwrap(); 9 | write!(t, "{} ", status_text).unwrap(); 10 | let _ = t.reset(); 11 | write!(t, "{}", text).unwrap(); 12 | t.flush().unwrap(); 13 | } 14 | 15 | #[allow(dead_code)] 16 | pub fn term_rprint_finish() { 17 | let mut t = term::stdout().unwrap(); 18 | 19 | writeln!(t).unwrap(); 20 | t.flush().unwrap(); 21 | } 22 | 23 | #[allow(dead_code)] 24 | pub fn term_print(color: term::color::Color, status_text: &str, text: &str) { 25 | term_print_(color, status_text, text, false); 26 | } 27 | 28 | pub fn term_println(color: term::color::Color, status_text: &str, text: &str) { 29 | term_print_(color, status_text, text, true); 30 | } 31 | 32 | fn term_print_(color: term::color::Color, status_text: &str, text: &str, newline: bool) { 33 | let mut t = term::stdout().unwrap(); 34 | 35 | t.attr(term::Attr::Bold).unwrap(); 36 | t.fg(color).unwrap(); 37 | write!(t, "{} ", status_text).unwrap(); 38 | let _ = t.reset(); 39 | 40 | if newline { 41 | writeln!(t, "{}", text).unwrap(); 42 | } else { 43 | write!(t, "{}", text).unwrap(); 44 | t.flush().unwrap(); 45 | } 46 | } 47 | 48 | #[cfg(not(debug_assertions))] 49 | pub fn term_panic(text: &str) { 50 | term_println(term::color::BRIGHT_RED, "Failure:", text); 51 | } 52 | -------------------------------------------------------------------------------- /ssh_deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "HELLO FROM SSH!" 4 | 5 | echo "SSH DEPLOY SCRIPT WAS HERE" > ssh_deploy.log 6 | --------------------------------------------------------------------------------