cabal替代脚本
由于网络原因,直接使用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效率又有点问题,所以最好将其写成一个函数。
home_url="https://hackage.haskell.org" function prepare()
{
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
} function pull_info_page()
{
# This function will pull info page from web
echo "[CABAL_SCRIPT:]Parsing info page for $1 ......"
item_url=$home_url/"package/"$1 if [ ! -f .tmp_sed_script_"$1" ]
then
cat<<EOF > .tmp_sed_script_"$1"
s/<\/[^>]*>/&\n/g
s/></>\n</g
s/a href="\([^"]*\)"/\n[URL: \1 ]\n/g
EOF
fi if [ ! -f .tmp_page_content_"$1" ]
then
curl $item_url 1> .tmp_page_content_"$1" 2> /dev/null
fi if [ ! -f .tmp_dependency_"$1" ]
then
sed -f .tmp_sed_script_"$1" .tmp_page_content_"$1" | grep "URL: /package/" | sed -e "/$1/d" > .tmp_dependency_"$1"
fi
} function calc_dependency()
{
# This function just calculate the dependency packages of $1
# and append it to the global list
echo "[CABAL_SCRIPT:]Resolving dependencies for $1 ......"
pull_info_page $1 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
install_package $dep
fi
fi
done
} function install_package()
{
# This function just download and install a package $1
# it doesn't care about dependency
target_dir="" calc_dependency $1 # Download package
for link in $(sed -f .tmp_sed_script_"$1" .tmp_page_content_"$1" | grep URL | awk '{print $2}')
do
if [[ $link == /*.tar.gz ]]
then
full_link=$home_url$link
archive_file=$(basename $full_link)
#target_dir=$(tar tzf $archive_file | awk 'NR==1{print}')
target_dir=$(echo $archive_file | sed -re 's/(.*)\.tar\.gz$/\1/g')
#echo "target_dir is $target_dir" if [ ! -d $target_dir ]
then
if [ ! -f $archive_file ]
then
#echo "wget " $full_link " --no-check-certificate ......"
echo "[CABAL_SCRIPT:]Downloading $full_link ......"
wget $full_link --no-check-certificate
fi if [ -f $archive_file ]
then
echo "[CABAL_SCRIPT:]Extracting $archive_file ......"
tar -xvzf $archive_file 2> /dev/null 1> /dev/null
fi
fi
fi
done # rm .tmp_*
# rm *.tar.gz* # Install package
cd $target_dir
echo "[CABAL_SCRIPT:]Installing $1 ......"
sudo cabal configure
sudo cabal install
cd ..
} prepare
install_package $1
rm .tmp_*
但是仍然有问题,这里没有对dependency的版本做判定,因此仍然失败。
cabal替代脚本的更多相关文章
- SQL SERVER 2008向ORACLE 11G迁移示例
来源于:http://www.cnblogs.com/hiizsk/ 由SQL SERVER 2008向ORACLE 11G迁移过程记录之一-表 使用Oracle Sql Developer将SQL ...
- 通过DOS、SHELL批处理命令加载Lib并编译和打包Java项目(或者运行项目)
有些时候,需要通过DOS批处理来编译整个项目的JAVA文件:并且编译后还要对Class文件进行打包成jar文件...这还不是最烦的,最烦的是,编译和打包的时候需要依赖其他多个jar文件,困难就这么来了 ...
- JS实现上下左右四方向无间隙滚动
想必大家都注意到<marquee>的不循环滚动,所以出现了很多替代脚本,或iframe或JS输出< marquee>,不管怎么做,都略显麻烦.下面说一下这个相对简单的实现思路: ...
- js图片无缝滚动代码
想必大家都注意到<marquee>的不循环滚动,所以出现了很多替代脚本,或iframe或JS输出<marquee>,不管怎么做,都略显麻烦.下面说一下这个相对简单的实现思路:一 ...
- jsp内置对象和el表达式
九个内置对象 *out jsp的输出流,用来向客户端响应 *page 当前jsp页面, 它的引用数据类型是Object,即真身中有如下代码 Object page=this; *config 它对应真 ...
- WebLogic域配置策略
WebLogic域配置策略--手动和模板选项,第一部分 域含有BEA WebLogic Server实例的配置信息.它包含有关服务器.集群和机器的配置信息.域还含有关于资源,例如Java数据库连接(J ...
- java新知识系列 三
1:trycatch中需要注意的地方. 2:ServletConfig以及ServletContext对象. 3: Spring事务属性的种类: 传播行为.隔离级别.只读和事务超时. 5:关于程序 ...
- go第三方日志系统-seelog-Basic sections
https://github.com/cihub/seelog 文档学习:https://github.com/cihub/seelog/wiki 1.安装: go get github.com/ci ...
- SharePoint Framework 企业向导(二)
博客地址:http://blog.csdn.net/FoxDave 开发者视角 SharePoint开发者,无论是新手还是有经验的,都可以从SPFx中获取一些东西.当前SPFx的发布版本专注于以一 ...
随机推荐
- 在Linux下将HTML文件转换成PDF文件
今天要写一个上交的作业,本来是想用Office Word来写的,但是,我的Office貌似不能用了,但是,Linux下的LibreOffice写出的文档,在打印的时候是经常出现乱码的.所以,后来想到可 ...
- poi小案例
一:pom <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http: ...
- rabbitmq部署安装
1.安装rabbitmq需要提前安装erlang,相关下载地址:http://www.erlang.org/downloads,需要注意:默认安装的RabbitMQ 监听端口是5672 启动和 ...
- 修改 IIS 默认文件上传大小
IIS 7 默认文件上传大小是30M 要突破这个限制: 修改IIS的applicationhost.config 打开 c:/windows/system32/inetsrv/config/appli ...
- Spring学习笔记(3)——快速入门
项目目录如下: Say.java为主函数通过ApplicationContext创建对象,利用方法ClassPathXmlApplicationContext访问配置文件Applicationcont ...
- 记一次用Linux curl命令获取Django url返回值异常的问题
问题描述: curl 检测 URL 返回值以判断服务器是否正常 原命令:curl -I -m 10 -o /dev/null -s -w %{http_code} --insecure $url 问题 ...
- python 子类继承父类__init__(转载)
转载: http://www.jb51.net/article/100195.htm 前言 使用Python写过面向对象的代码的同学,可能对 __init__ 方法已经非常熟悉了,__init__方法 ...
- Zookeeper3.4.14集群搭建
环境: 3台centos7.4 1. 下载release:wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3. ...
- 系统调用system_call处理过程
原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 作者:严哲璟 linux的系 ...
- bzoj2669 [cqoi2012]局部极小值 状压DP+容斥
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=2669 题解 可以发现一个 \(4\times 7\) 的矩阵中,有局部最小值的点最多有 \(2 ...