os.yaml 2.9 KB

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