系统编译脚本[一]

系统编译脚本 

 

  • scripts/clean------------------------------------

  • 2  
    3  .scripts/common
    4  .config/global.conf
    5
    6 check_uid
    7  #load_dest_conf$1
    8  
    9 [-d $rootdir ] && rm -rf $rootdir
  • scripts/clipping---------------------------------

代码
1 #!/bin/sh
2  
3  .scripts/common
4  .config/global.conf
5
6 echo"=============start scripts/clipping=========="
7 echo"#";echo "#";echo "#";echo "#";echo"#";
8 echo"#";echo "#";echo "#";echo "#";echo"#";
9 echo"#";echo "#";echo "#";echo "#";echo"#";
10
11 check_uid
12 load_dest_conf$1
13
14 echo"Start Clipping ..."
15 clip_sh=$(abs_path"config/$clipping_list")
16 clip_dir=`dirname$clip_sh`
17
18
19 echo"******** clip_sh=$clip_sh;;;clip_dir=$clip_dir"
20  #依次执行./config/loongson/clip.d/下面的脚本文件
21  grep-v "^#" $clip_sh|while read line
22  do
23  if[ ! -z $debug ]
24 then
25 echo"running $line ..."
26 fi
27
28 chroot_run$(abs_path $rootdir) $clip_dir/$line
29 done
30
31 echo"=============end scripts/clipping=========="
32 echo"#";echo "#";echo "#";echo "#";echo"#";
33 echo"#";echo "#";echo "#";echo "#";echo"#";
34 echo"#";echo "#";echo "#";echo "#";echo"#";
  • scripts/common------------------------------------------

代码
1 #!/bin/sh
2
3 #check_uid: make certain run as root.
4  functioncheck_uid()
5 {
6 [`id -u` != "0" ] && echo "must run as root!"&& exit 0;
7 }
8
9  #abs_path: get the absolute path.
10 #$1: the relation path.
11  
12 functionabs_path()
13 {
14  if[ `echo $1 | grep -E "^/.*"` ]
15 then
16 echo $1
17  else
18 echo "`pwd`/$1"
19 fi
20 }
21
22  #load_dest_conf: load dest ruler config.
23 functionload_dest_conf()
24 {
25 dest=$1
26 if[ -z $dest ]
27 then
28 echo"there has no baserpms in 'config/$dest.conf'"
29 exit1
30
31 else
32 pwd
33 ."config/$dest.conf"
34 fi
35 }
36
37 #chroot_run(): chroot and run scripts.
38 #$1: rootdir
39 #$2: script path
40 functionchroot_run()
41 {
42 echo"======> start here !!!"
43 rootdir=$1
44 scpath=$2
45
46 echo"rootdir: $rootdir"
47 echo"scpath: $scpath"
48 scname=`basename$scpath`
49 echo"scname: $scname"
50
51 if[ ! -e "$rootdir/tmp/" ];then
52 mkdir$rootdir/tmp/
53 fi
54
55 cp-r -f $scpath $rootdir/tmp/
56 chmodu+x $rootdir/tmp/$scname
57 chroot$rootdir /tmp/$scname
58 rm-f $rootdir/tmp/$scname
59 }
60
61 #$1:bin full path
62 functionget_ldd()
63 {
64 path=$1
65 file_list=$(ldd$path |while read line; do echo $line | grep --color -o -e "\/.*";done)
66 echo$file_list
67 }
68
69 functioncopy_file()
70 {
71 dest_root=$1
72 base_path=$2
73 dest=$dest_root$base_path
74 [-e $dest ] && return
75 dir=`dirname$dest`
76 echomkdir -p $dir
77 mkdir-p $dir
78 echocp -p $base_path $dest
79 cp-p $base_path $dest
80 }
81
82 functioncopy_elf()
83 {
84 dest_root=$1
85 shift
86 fori in $@
87 do
88 forn in $(get_ldd $i)
89 do
90 copy_file$dest_root $n
91 done
92 copy_file$dest_root $i
93 done
94 }
  •  scripts/extra--------------------------------

代码
1 #!/bin/sh
2
3 .scripts/common
4 .config/global.conf
5
6 check_uid
7 load_dest_conf$1
8
9 real_rootdir=$(abs_path$rootdir)
10 echo"Start extra scripts..."
11 extra_sh=$(abs_path"config/$extra_list")
12 extra_dir=`dirname$extra_sh`
13
14 grep-v "^#" $extra_sh|while read line
15 do
16 if[ ! -z $debug ]
17 then
18 echo"running $line ..."
19 fi
20 $extra_dir/$line
21 done
22 size=$(du-sh $real_rootdir)
23 echo">>>>>now $rootdir is: [$size] <<<<<"
  • scripts/mkrootfs-------------------------------------

代码
1 #!/bin/sh
2
3 echo"=============start scripts/mkrootfs=========="
4 echo"#";echo "#";echo "#";echo "#";echo"#";
5 echo"#";echo "#";echo "#";echo "#";echo"#";
6 echo"#";echo "#";echo "#";echo "#";echo"#";
7
8 .scripts/common
9 .config/global.conf
10
11 echo"~~~~~~> \$1=$1"
12 check_uid
13 load_dest_conf$1
14
15 case$issue in
16 archlinux)
17 [-d $rootdir ] || mkdir $rootdir
18 if[ ! -d ${rootdir}/tmp/rootfs/var/lib/pacman ]; then
19 mkdir-p ${rootdir}/var/lib/pacman
20 pacman-r ${rootdir} -Sy
21 fi
22 pacman-r ${rootdir} -S $baserpms
23 ;;
24 redflag)
25 ;;
26 *)
27 if[ $useyum == "yes" ]
28 then
29 #[-d $rootdir ] || mkdir $rootdir
30 if[ ! -z $debug ]
31 then
32 yuminstall --installroot=$(abs_path $rootdir) -c /etc/yum.conf install$baserpms
33 else
34 yuminstall -y -q --installroot=$(abs_path $rootdir) -c /etc/yum.confinstall $baserpms
35 fi
36 else
37 if[ ! -z $debug ]
38 then
39 echo"======>>> debug !"
40 tools/rpm2rootfs-r $(abs_path $rootdir) -d $(abs_path $rpmsdir) -i $baserpms
41
42 else
43 echo"======>>> no debug !"
44 tools/rpm2rootfs-r $(abs_path $rootdir) -d $(abs_path $rpmsdir) $baserpms
45 fi
46 fi
47 ;;
48 esac
49 echo"============end scripts/mkrootfs==========="
50 echo"#";echo "#";echo "#";echo "#";echo"#";
51 echo"#";echo "#";echo "#";echo "#";echo"#";
52 echo"#";echo "#";echo "#";echo "#";echo"#";
  • scripts/setup-----------------------------------
代码
1 #!/bin/sh
2 .scripts/common
3 .config/global.conf
4
5 check_uid
6 load_dest_conf$1
7 real_rootdir=$(abs_path$rootdir)
8 setup_sh=$(abs_path"config/$setup_list")
9 setup_dir=`dirname$setup_sh`
10 echo"******setup_sh :$setup_sh"
11 echo"******setup_dir :$setup_dir"
12 grep-v "^#" $setup_sh|while read line
13 do
14 if[ ! -z $debug ]
15 then
16 echo"running $line ..."
17 fi
18 chroot_run$real_rootdir $setup_dir/$line
19 done
20 #if[ -n $extra_scripts ]
21 #then
22 ##echo"extra_scripts is" $(abs_path "config/$extra_scripts")
23 #. $(abs_path "config/$extra_scripts")
24 #fi
25 #
26 #size=$(du-sh $real_rootdir)
27 #
28
29 #echo">>>>>now $rootdir is: [$size] <<<<<"
posted @ 2010-11-17 11:11  solookin  阅读(381)  评论(0编辑  收藏  举报