背景

本文主要是为了研究一下makeself包的原理, 以及通过监控文件变动,提取makeself临时文件目录

工具

inotifywait 用于监听文件变动

代码

bash.sh

  1. #!/usr/bin/env bash
  2. src=/tmp
  3. des=/home/harmonyos/tmp
  4. cd ${src}
  5. inotifywait -mrq --format '%Xe %w%f' -e close_write ./ | while read file; do
  6. INO_EVENT=$(echo $file | awk '{print $1}')
  7. INO_FILE=$(echo $file | awk '{print $2}')
  8. INO_FILE_NAME="${INO_FILE##*/}"
  9. # copy file
  10. cp --parents -av $INO_FILE $des
  11. done

核心原理就是 通过 inotifywait 监控tmp 文件变动 (同时执行makeself的包),并把变动的文件目录,写入到另外的目录下面

参考资料