首页 > 代码库 > cabal替代脚本
cabal替代脚本
由于网络原因,直接使用cabal update不成功,只能自己写脚本直接从网上拖包下来,自己安装。
但是这样做的缺点是需要手动处理dependency,当然,也可以把脚本写的复杂些,自动来处理dependency。
cabal.sh
1 cat<<EOF > .tmp_sed_script2 s/<\/[^>]*>/&\n/g3 s/></>\n</g4 s/a href="http://www.mamicode.com/([^"]*\)"/\n[URL: \1 ]\n/g5 EOF6 7 home_url="https://hackage.haskell.org"8 9 item_url=$home_url/"package/"$110 11 target_dir=""12 13 curl $item_url 1> .tmp_page_content 2> /dev/null14 15 for link in $(sed -f .tmp_sed_script .tmp_page_content | grep URL | awk ‘{print $2}‘)16 do17 if [[ $link == /*.tar.gz ]]18 then19 full_link=$home_url$link20 echo "wget " $full_link " --no-check-certificate ......"21 wget $full_link --no-check-certificate22 archive_file=$(basename $full_link)23 if [ -f $archive_file ]24 then25 tar -xvzf $archive_file 2>&1 > /dev/null26 fi27 target_dir=$(tar tzf $archive_file | awk ‘NR==1{print}‘)28 fi29 done30 31 rm .tmp_*32 rm *.tar.gz*33 34 cd $target_dir35 sudo cabal configure36 sudo cabal install37 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 ]thencat<<EOF > .tmp_sed_scripts/<\/[^>]*>/&\n/gs/></>\n</gs/a href="http://www.mamicode.com/([^"]*\)"/\n[URL: \1 ]\n/gEOFfiif [ ! -f .tmp_installed_pkgs ]thenghc-pkg list | sed -e ‘/[\/(]/d‘ | awk ‘BEGIN{FS="-"}{print $1}‘ | sed -e ‘/Cabal/d‘ | awk ‘NF!=0{print}‘ | sed ‘s/ //g‘ > .tmp_installed_pkgsfihome_url="https://hackage.haskell.org"item_url=$home_url/"package/"$1target_dir=""if [ ! -f $.tmp_page_content_"$1" ]thencurl $item_url 1> .tmp_page_content_"$1" 2> /dev/null fised -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 fidone
但是这种以脚本为单位的recursion效率又有点问题,所以最好将其写成一个函数。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。