【发布时间】:2013-07-30 01:51:00
【问题描述】:
我们如何转换下面的 shell 脚本,以便在 Mac OS X 上实现相同的结果?
# To generate secure SSH deploy key for a github repo to be used from Travis
# https://gist.github.com/floydpink/4631240
base64 --wrap=0 ~/.ssh/id_rsa_deploy > ~/.ssh/id_rsa_deploy_base64
ENCRYPTION_FILTER="echo \$(echo \"- secure: \")\$(travis encrypt \"\$FILE='\`cat $FILE\`'\" -r floydpink/harimenon.com)"
split --bytes=100 --numeric-suffixes --suffix-length=2 --filter="$ENCRYPTION_FILTER" ~/.ssh/id_rsa_deploy_base64 id_rsa_
# To reconstitute the private SSH key once running inside Travis (typically from 'before_script')
echo -n $id_rsa_{00..30} >> ~/.ssh/id_rsa_base64
base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
我可以算出等效的base64 命令是:
base64 --break=0 id_rsa_deploy > id_rsa_deploy_base64
但看起来split command on Mac OS X 与Linux/Unix 有点不同,并且没有--filter 选项。
编辑:这是 a gist 我从 this blog entry 偶然发现的,它详细介绍了如何使用 Travis CI 将 Octopress 博客自动部署到 GitHub。
我过去曾在 Ubuntu Linux 和 had blogged about it 上成功完成此操作,但无法在 Mac 上重复此操作。
【问题讨论】:
-
在您的问题中包含的“好”
split --filter ...的示例输出将有助于人们思考替代解决方案。就像现在一样,我/我们必须猜测。你能用awk '{while length($0) > 100) {printf("%100s\n", $0); sub(/.{100}/, "", $0 ) # or somesuch ; } printf("%s\n" $0)}'之类的东西代替split --bytes=100吗?祝你好运。
标签: macos bash shell split posix