我有一个混帐以下post-commit钩子:这可以摧毁我的整个网站吗?
#!/bin/sh
# Save this in: /home/qwertymk/website-live.git/hooks/post-receive
# let's save all of out js files before the checkout
FILES="$(find /home/qwertymk/public_html -type f -name '*.js')"
for f in $FILES
do
if [[ $f =~ /home/qwertymk/ignore-dir/dev-staging-area/ ]]; then continue; fi
echo "copying - $f"
cp $f $f.jscache
done
# done saving js files before checkout
export GIT_WORK_TREE=/home/qwertymk/public_html/
git checkout -f
# minify each js file that changed
cd /home/qwertymk/website-live.git
FILES=$(git whatchanged -n 1 --pretty=format: --name-only | grep '\.js$')
for f in $FILES
do
echo "processing - $f"
rm /home/qwertymk/public_html/$f.jscache
php /home/qwertymk/jsmin/curl.php /home/qwertymk/public_html/$f
done
# done minifing
# anything that has a .jscache should be moved to the .js
FILES="$(find /home/qwertymk/public_html -type f -name '*.js')"
for f in $FILES
do
if [[ $f =~ /home/qwertymk/public_html/dev-staging-area/ ]]; then continue; fi
if [ ! -f $f.jscache ]; then continue; fi
echo "restoring - $f"
rm $f
mv $f.jscache $f
done
有什么不对的脚本?
我可以安心使用吗?
是否有任何角落的情况下,这个剧本可以搞砸我的网站?
有什么特别令你担心吗? – abresas 2012-02-21 03:20:07
@abresas:事实上,我可能会意外删除所有myjs文件 – qwertymk 2012-02-21 03:32:45
看看其他文章,使用'find ... |同时读取文件名;在S.O.上张贴这里。它每天都会被提及。使用'FILES = $(find ...)'将在文件名中有空格或其他奇数字符时破坏,无论是通过设计还是事故。它还有助于将'rm $ f'转换为'printf - rm $ f'\ n“'等,这样您就可以看到将执行的命令。当你满意时,输出是安全的,然后将整个脚本输出重定向到一个shell。即'myGitThing | bash'。祝你好运。 – shellter 2012-02-21 03:55:32