os.yaml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. load:
  2. - pkg: misc.yaml
  3. tasks:
  4. # Generic tasks
  5. bash:
  6. desc: Interactive prompt
  7. run: "bash"
  8. create-dir:
  9. desc: Add a new directory
  10. run: "mkdir -p {path}"
  11. symlink:
  12. desc: Create symlink
  13. run: |
  14. if test ! -e {to}
  15. then ln -s {from} {to}
  16. fi
  17. mount:
  18. run: mount | grep ' {path} ' &> /dev/null || mount {path}
  19. move:
  20. desc: Move a file or directory (if destination does not exists)
  21. run: |
  22. if test ! -e {to}
  23. then mv {from} {to}
  24. fi
  25. copy: # XXX move is lazy but copy is not !?
  26. desc: Copy a file or directory
  27. run: |
  28. if test -f {from}
  29. then cp {from} {to}
  30. else cp -Tr {from} {to}
  31. fi
  32. remove:
  33. desc: Remove (-r) path
  34. run: "rm -r {path}"
  35. chown:
  36. desc: Chown a file or directory
  37. run: "chown -R {user}. {path}"
  38. chmod:
  39. desc: Chmod a file or directory
  40. run: "chmod -R {mode} {path}"
  41. apt-install:
  42. desc: Run apt install
  43. run: apt update && apt install -y {packages}
  44. sudo: true
  45. systemctl:
  46. desc: Call systemctl
  47. run: systemctl {action} {service}
  48. sudo: true
  49. send:
  50. desc: Send a file or a directory
  51. send: "{send}"
  52. to: "{to}"
  53. send-tpl:
  54. desc: Format a template and send it (can be file or directory)
  55. send: "{send}"
  56. to: "{to}"
  57. fmt: "{fmt}"
  58. sudo-send:
  59. desc: Combine send & sudo-move
  60. multi:
  61. - task: misc/random-string
  62. export: tmppath
  63. - task: send
  64. env:
  65. to: "/tmp/{tmppath}"
  66. - task: copy
  67. sudo: true
  68. env:
  69. from: "/tmp/{tmppath}"
  70. - task: remove
  71. env:
  72. path: "/tmp/{tmppath}"
  73. parted:
  74. desc: Create primary partition && mkfs
  75. sudo: true
  76. run: |
  77. if test ! -e {device}1
  78. then
  79. parted {device} -a optimal --script mklabel gpt mkpart primary 0% 100%
  80. sleep 1
  81. mkfs -t ext4 {device}1
  82. fi
  83. append-line:
  84. desc: Append line to file
  85. run: >-
  86. grep {guard} {file} &> /dev/null
  87. || echo {line} >> {file}
  88. add-user:
  89. desc: Create a new user
  90. run: id {user} || sudo adduser {user} --disabled-login --gecos ""
  91. add-group:
  92. desc: Add group to user
  93. run: usermod -a -G {user} {group}
  94. wget:
  95. desc: Download a file
  96. run: test -f {file} || wget -O {file} {url}
  97. unzip:
  98. desc: Unzip a zip file
  99. run: test -d {dir} || unzip {file} -d {dir}
  100. patch:
  101. desc: Patch a file with a specific local diff file
  102. run: |
  103. patch --ignore-whitespace --reject-file=/dev/null -uN {file} << EOF
  104. {diff_string}
  105. EOF
  106. send-rmcr:
  107. desc: Send a file but remove its carriage returns before.
  108. multi:
  109. - task: send
  110. - run: "tr -d '\r' < {to} > {to}-tmp"
  111. - task: move
  112. env:
  113. from: "{to}-tmp"
  114. sudo-send-rmcr:
  115. desc: Combine send & sudo-move, and remove carriage returns
  116. multi:
  117. - task: send
  118. env:
  119. to: "/tmp/{tmppath}"
  120. - task: rmcr
  121. env:
  122. from: "/tmp/{tmppath}"
  123. sudo: true
  124. - task: remove
  125. env:
  126. path: "/tmp/{tmppath}"
  127. rmcr:
  128. desc: remove carriage returns and move file
  129. run: "tr -d '\r' < {from} | tee {to} > /dev/null"
  130. unlink:
  131. desc: remove a symlink
  132. run: "test -L {path} && unlink {path}"