由于网络原因,直接使用cabal update不成功,只能自己写脚本直接从网上拖包下来,自己安装。
但是这样做的缺点是需要手动处理dependency,当然,也可以把脚本写的复杂些,自动来处理dependency。
cabal.sh
1 cat<<EOF > .tmp_sed_script 2 s/<\/[^>]*>/&\n/g 3 s/></>\n</g 4 s/a href="\([^"]*\)"/\n[URL: \1 ]\n/g 5 EOF 6 7 home_url="https://hackage.haskell.org" 8 9 item_url=$home_url/"package/"$1 10 11 target_dir="" 12 13 curl $item_url 1> .tmp_page_content 2> /dev/null 14 15 for link in $(sed -f .tmp_sed_script .tmp_page_content | grep URL | awk ‘{print $2}‘) 16 do 17 if [[ $link == /*.tar.gz ]] 18 then 19 full_link=$home_url$link 20 echo "wget " $full_link " --no-check-certificate ......" 21 wget $full_link --no-check-certificate 22 archive_file=$(basename $full_link) 23 if [ -f $archive_file ] 24 then 25 tar -xvzf $archive_file 2>&1 > /dev/null 26 fi 27 target_dir=$(tar tzf $archive_file | awk ‘NR==1{print}‘) 28 fi 29 done 30 31 rm .tmp_* 32 rm *.tar.gz* 33 34 cd $target_dir 35 sudo cabal configure 36 sudo cabal install 37 cd ..
不过好像必须要处理dependency了,这样才能真正自动化。
ghc-pkg list | sed -e ‘/[\/(]/d‘ | awk ‘BEGIN{FS="-"}{print $1}‘ | sed -e ‘/Cabal/d‘ | awk ‘NF!=0{print}‘ | sed ‘s/ //g‘ > .installed_pkgs
if [ ! -f .tmp_sed_script ] then cat<<EOF > .tmp_sed_script s/<\/[^>]*>/&\n/g s/></>\n</g s/a href="\([^"]*\)"/\n[URL: \1 ]\n/g EOF fi if [ ! -f .tmp_installed_pkgs ] then ghc-pkg list | sed -e ‘/[\/(]/d‘ | awk ‘BEGIN{FS="-"}{print $1}‘ | sed -e ‘/Cabal/d‘ | awk ‘NF!=0{print}‘ | sed ‘s/ //g‘ > .tmp_installed_pkgs fi home_url="https://hackage.haskell.org" item_url=$home_url/"package/"$1 target_dir="" if [ ! -f $.tmp_page_content_"$1" ] then curl $item_url 1> .tmp_page_content_"$1" 2> /dev/null fi sed -f .tmp_sed_script .tmp_page_content_"$1" | grep "URL: /package/" | sed -e "/$1/d" > .tmp_dependency_"$1" # we should make sure that all the package in .tmp_dependency_XXX file should be installed first than this package # # for dependency in $(cat .tmp_dependency_"$1") do if [[ $dependency == /package/* ]] then #echo $dependency dep=$(echo $dependency | cut -b 10-) b_installed=false for installed in $(cat .tmp_installed_pkgs) do if [[ $installed == $dep ]] then b_installed=true fi done #echo $b_installed " for " $dep if [[ $b_installed == "false" ]] then echo "$1 depends on $dep" echo "$dep" >> .tmp_installed_pkgs bash cabal_ex.sh $dep fi fi done
但是这种以脚本为单位的recursion效率又有点问题,所以最好将其写成一个函数。
cabal替代脚本
时间: 2024-10-09 05:33:48