我試圖讓我的第一個「真正的」bash腳本來做一些真正的工作,可以手動執行和通過cron作業。bash腳本安裝/更新ffmpeg靜態構建
腳本應該從https://johnvansickle.com/ffmpeg
這裏下載並安裝ffmpeg的靜電建造就是我這麼遠:
#!/bin/bash
# Still to come, see if the script runs with root privileges else exit
#Download FFMPEG static daily build and it's md5
cd ~
wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz | tar -xf
#wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz.md5
curl -L https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz.md5 | tar -xf | tee -a https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz | cut -d\ -f1 | md5sum > md5sum.txt
#Chech the md5 is currect
#md5sum -c MD5SUMS
file1="md5sum.txt"
file2="ffmpeg-git-64bit-static.tar.xz.md5"
if ! cmp --silent "$file1" "$file2"; then
echo "md5sum doesn't match...\n exit" >&2
exit 1
fi
#tar -xf ffmpeg-*.tar.xz
cp ffmpeg-*-static/ff* /usr/bin/
cp ffmpeg-*-static/ff* /usr/local/bin/
cp ffmpeg-*-static/qt-faststart /usr/bin/
cp ffmpeg-*-static/qt-faststart /usr/local/bin/
# Consider change second location to use ln -s
# Remove downloads and do some clean up
rm -fr ffmpeg-*
#EOF
正如你可以在腳本看,我想添加md5sum檢查,但它失敗(從Compare md5 sums in bash script得到md5sum檢查部分)
如果我刪除md5sum部分腳本正在工作,但現在腳本失敗在| tar -xf |與此代碼部分
2017-02-28 00:10:24 (617 KB/s) - ‘ffmpeg-git-64bit-static.tar.xz’ saved [17564756/17564756]
tar: option requires an argument -- 'f'
Try 'tar --help' or 'tar --usage' for more information.
tee: 'https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz': No such file or directory
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 65 100 65 0 0 87 0 --:--:-- --:--:-- --:--:-- 87
(23) Failed writing body
md5sum doesn't match...
exit
因爲這是我第一次,我將不勝感激任何「我4歲的」建議和爲什麼
更新
已經取得了一些變化到基於這個線程的建議腳本,但我的問題是我沒有輸出什麼這樣在這種狀態:(所以我認爲是時候要求下一個線索
#!/bin/bash
# version 0.3z
## Download FFMPEG static daily build and it's md5
##
## To make this script working you might need to change the below values
## based on whether you are using a 32bit or 64 bit OS
## to obtain the right links you have to have a look @ https://johnvansickle.com/ffmpeg/
## and then change those below
##
## If you are running on a shared server or dowsn't have root priviliges you might need to uncomment
## point 5.
# a "~" means running users home folder :) and should be different from destination dir
download_dir=~
# as this can change if the ffmpeg is to be stored on ex. shared server
dest_dir=/usr/bin/
# The version it equal the filename from above link
version=ffmpeg-git-64bit-static.tar.xz
## Do not change anything below here!!
source_url=https://johnvansickle.com/ffmpeg/builds/${version}
md5_url=https://johnvansickle.com/ffmpeg/builds/${version}.md5
# Still to come, see if the script runs with write privileges else exit
# 1. Can we enter download directory else exit
cd ${download_dir} ||
printf "%s\n" "You can't enter this folder.\nPlease chage download_dir in this script..." >&2
exit 1
# 2. Check the md5 is correct or have changed from last check
## instead of downloading ffmpeg-git-64bit-static.tar.xz every time,
## regardless if it is new or not, I recommend only downloading it
## if the md5 does not match. Would save John some bandwidth at least
## thx for the idea to @LordNeckbeard
## So somehow i'll guess some sed or grep only first part is nessesary :(
## This is getting more advance than expected for a first time script :/
if ! diff <(md5sum ${version}) <(curl -s ${md5_url})
then
printf "%s\n" "md5sum doesn't match...\n
Downloading new version" >&2
rm -f ${version} >&2
curl ${source_url} -o ${download_dir}/${version} >&2
#exit 2
elif
diff <(md5sum ${version}) <(curl -s ${md5_url})
printf "%s\n" "Nothing new to download" >&2
exit 3
fi
# 3. untar
tar -xf ffmpeg-git-*-static.tar.xz
# 4. Move builds to destination directories
mv ${download_dir}/ffmpeg-*-static/ff* ${dest_dir}/
mv ${download_dir}/ffmpeg-*-static/qt-faststart ${dest_dir}/
# 5. Make soft links to static builds
ln -sfn ${dest_dir}/qt-faststart /usr/local/bin/qt-faststart
ln -sfn ${dest_dir}/ffmpeg /usr/local/bin/ffmpeg
ln -sfn ${dest_dir}/ffmpeg-10bit /usr/local/bin/ffmpeg-10bit
ln -sfn ${dest_dir}/ffprobe /usr/local/bin/ffprobe
ln -sfn ${dest_dir}/ffserver /usr/local/bin/ffserver
# Remove unzipped folder to do some clean up
rm -fr ffmpeg-git-*-static/
#EOF
注:做一些更多的在爲什麼不從源代碼編譯深入回答: 1.此預編譯的是所有Linux的變化可用,儘管發行和版本 2.使用與ssh訪問
共享託管服務器更新2
#!/bin/bash
# version 0.4z
## Download FFMPEG static daily build and it's md5
##
## To make this script working you might need to change the below values
## based on whether you are using a 32bit or 64 bit OS
## to obtain the right links you have to have a look @ https://johnvansickle.com/ffmpeg/
## and then change those below
##
## Finished and working script should be distributed under GPLv3: free as in freedom
##
## If you are running on a shared server or dowsn't have root priviliges you might need to uncomment
## point 5.
# a "~" means running users home folder :) and should be different from destination dir
download_dir=~
# as this can change if the ffmpeg is to be stored on ex. shared server
dest_dir=/usr/bin/
# The version it equal the filename from above link
version=ffmpeg-git-64bit-static.tar.xz
## Do not change anything below here!!
source_url=https://johnvansickle.com/ffmpeg/builds/${version}
md5="curl -s https://johnvansickle.com/ffmpeg/builds/${version}.md5"
# Still to come, see if the script runs with write privileges else exit
# 1. Can we enter download directory else exit
cd ${download_dir} ||
printf "%s\n" "You can't enter this folder.\nPlease chage download_dir in this script..." >&2
exit 1
# 2. Check the md5 is correct or have changed from last check
## instead of downloading ffmpeg-git-64bit-static.tar.xz every time,
## regardless if it is new or not, I recommend only downloading it
## if the md5 does not match. Would save John some bandwidth at least
## thx for the idea to @LordNeckbeard
## This is getting more advance than expected for a first time script :/
if diff <(md5sum ${version}) <(${md5})
then
printf "%s\n" "No new version availeble" >&2
exit 1
elif ! diff <(md5sum ${version}) <(${md5})
then
rm -f ${version}
curl ${source_url} > ${version}
exit 0
#only proceed if downloaded version match it's md5
if ! diff <(md5sum ${version}) <(${md5})
then
rm -f ${version}
printf "%s\n" "Downloaded version is damaged, try later\ndamaged version have been deleted" >&2
exit 1
fi
# 3. untar
tar -xf ffmpeg-git-*-static.tar.xz
# 4. Move builds to destination directories
mv ${download_dir}/ffmpeg-*-static/ff* ${dest_dir}/
mv ${download_dir}/ffmpeg-*-static/qt-faststart ${dest_dir}/
# 5. Make soft links to static builds
ln -sfn ${dest_dir}/qt-faststart /usr/local/bin/qt-faststart
ln -sfn ${dest_dir}/ffmpeg /usr/local/bin/ffmpeg
ln -sfn ${dest_dir}/ffmpeg-10bit /usr/local/bin/ffmpeg-10bit
ln -sfn ${dest_dir}/ffprobe /usr/local/bin/ffprobe
ln -sfn ${dest_dir}/ffserver /usr/local/bin/ffserver
# Remove unzipped folder to do some clean up
rm -fr ffmpeg-git-*-static/
printf "%s\n" "Going to install new version" >&2
exit 1
fi
#EOF
但仍然有一些問題:(
- 運行此腳本返回:一個相思的外殼,但我預計printf語句的一個
- 當我試圖縮小問題以及回到基礎,並試圖只與運行腳本「if」部分失敗,出現44:語法錯誤:「(」意外
運行直接輸入到shell /終端本身的「if」部分。
if diff <(md5sum ffmpeg-git-64bit-static.tar.xz) <(curl -s "https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz.md5"); then printf "%s\n" "No new version availeble" >&2; elif ! diff <(md5sum ffmpeg-git-64bit-static.tar.xz) <(curl -s "https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz.md5"); then rm -f ffmpeg-git-64bit-static.tar.xz; curl https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz > ffmpeg-git-64bit-static.tar.xz; printf "%s\n" "Going to install new version" >&2; fi
我很困惑
更新3 它已經到了我的注意,還受到質疑3運行腳本由sh update_ffmpeg.sh
ofcurse是錯誤的,應該只是@tomas通過輸入腳本ex的完整路徑從其位置執行。/home/username/update_ffmpeg.sh
所以分享當前工作版本(但仍然不完全):
#!/bin/bash
# version 0.4z
## Download FFMPEG static daily build and it's md5
##
## To make this script working you might need to change the below values
## based on whether you are using a 32bit or 64 bit OS
## to obtain the right links you have to have a look @ https://johnvansickle.com/ffmpeg/
## and then change those below
##
## Finished and working script should be distributed under GPLv3: free as in freedom
##
## If you are running on a shared server or dowsn't have root priviliges you might need to uncomment
## point 5.
# a "~" means running users home folder :) and should be different from destination dir
download_dir=~
# as this can change if the ffmpeg is to be stored on ex. shared server
dest_dir=/usr/bin/
# The version it equal the filename from above link
version=ffmpeg-git-64bit-static.tar.xz
## Do not change anything below here!!
source_url=https://johnvansickle.com/ffmpeg/builds/${version}
md5_url=https://johnvansickle.com/ffmpeg/builds/${version}.md5
# Still to come, see if the script runs with write privileges else exit
# 1. Can we enter download directory else exit
cd ${download_dir} || {
printf "%s\n" "You can't enter this folder." "Please change download_dir in this script..." >&2
exit 1
}
# 2. Check the md5 is correct or have changed from last check
## instead of downloading ffmpeg-git-64bit-static.tar.xz every time,
## regardless if it is new or not, I recommend only downloading it
## if the md5 does not match. Would save John some bandwidth at least
## thx for the idea to @LordNeckbeard
## This is getting more advance than expected for a first time script :/
if ! diff <(md5sum ${version}) <(curl -s ${md5_url})
then
# Sum doesn't match is not really an error... I comment out the redirection.
printf "%s\n" "md5sum doesn't match..." "Downloading new version"
rm -f ${version}
curl ${source_url} -o ${download_dir}/${version}
# 3. untar
tar -xf ffmpeg-git-*-static.tar.xz
# 4. Move builds to destination directories
mv ${download_dir}/ffmpeg-*-static/ff* ${dest_dir}/
mv ${download_dir}/ffmpeg-*-static/qt-faststart ${dest_dir}/
# 5. Make soft links to static builds
ln -sfn ${dest_dir}/qt-faststart /usr/local/bin/qt-faststart >&2
ln -sfn ${dest_dir}/ffmpeg /usr/local/bin/ffmpeg >&2
ln -sfn ${dest_dir}/ffmpeg-10bit /usr/local/bin/ffmpeg-10bit >&2
ln -sfn ${dest_dir}/ffprobe /usr/local/bin/ffprobe >&2
ln -sfn ${dest_dir}/ffserver /usr/local/bin/ffserver >&2
# Remove unzipped folder to do some clean up
rm -fr ffmpeg-git-*-static/
printf "%s\n" "Installing new version" >&2
else
printf "%s\n" "Nothing new to download" # >&2 -- Why is this an error?
exit # 3 -- I don't think this is any error. You checked and it's fine.
fi
#EOF
下一個任務:
- 獲取腳本檢查當前用戶必須
download_dir
和dest_dir
寫訪問否則退出並提示要求新的位置或提升用戶權利
再次,我很高興迄今爲止收到的所有幫助:)
如何經常會被你執行這個的cronjob? – LordNeckbeard
hi @LordNeckbeard hi @LordNeckbeard我在想每週一次的想法 – Joakim
如果你對其他想法持開放態度,只是一種替代解決方案,但是在那個頻率下,我會下載源代碼,然後每週更新一次[編譯](http:// trac .ffmpeg.org /#CompilingFFmpeg)。你可以自定義它,並不會依賴別人進行更新。 – LordNeckbeard