OSDN Git Service

[disable] :Disabled upgrade.
[alterlinux/LUBS.git] / lubs
1 #!/usr/bin/env bash
2
3 set -e -u
4
5 export LANG=C
6
7
8 arch=amd64
9 work_dir="work"
10 script_path=$(readlink -f ${0%/*})
11 codename="bionic"
12 mirror="http://ftp.jaist.ac.jp/pub/Linux/ubuntu/"
13
14
15 # Show an INFO message
16 # _msg_info <message>
17 _msg_info () {
18     local _msg="${@}"
19     echo "[LUBS Core] INFO: ${_msg}"
20 }
21
22 # Show an ERROR message then exit with status
23 # _msg_error <message> <exit code>
24 _msg_error() {
25     local _msg="${1}"
26     local _error=${2}
27     echo "[LUBS Core] ERROR: ${_msg}" >&2
28     if [[ ! ${_error} = 0 ]]; then
29         exit ${_error}
30     fi
31 }
32
33
34 # Helper function to run make_*() only one time.
35 run_once() {
36     if [[ ! -e "${work_dir}/build.${1}" ]]; then
37         "$1"
38         touch "${work_dir}/build.${1}"
39     fi
40 }
41
42
43 run_cmd () {
44     "${script_path}/lubs-chroot" "${work_dir}/airootfs" ${@}
45 }
46
47 _apt_install () {
48     run_cmd apt-get --yes install ${@}
49 }
50
51
52
53
54 prepare_build () {
55     if [[ ${EUID} -ne 0 ]]; then
56         _msg_error "This script must be run as root." 1
57     fi
58     
59     [[ ! -d "${work_dir}" ]] && mkdir -p "${work_dir}"
60
61     local mount
62     for mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir})); do
63         _msg_info "Unmounting ${mount}"
64         umount "${mount}"
65     done
66
67 }
68
69
70 make_basefs () {
71     _msg_info "Installing Ubuntu to '${work_dir}/airootfs/'..."
72     mkdir -p ${work_dir}/airootfs
73     debootstrap --arch=${arch} --include=linux-image-generic  --verbose --merged-usr "${codename}" "${work_dir}/airootfs" ${mirror}
74     echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}' >> "${work_dir}/airootfs/etc/bash.bashrc"
75     run_cmd apt-get update
76     # run_cmd apt-get upgrade
77     _msg_info "${codename} installed successfully!"
78 }
79
80 make_sourcelist () {
81     cp ${script_path}/source.list.d/${codename}/* ${work_dir}/airootfs/etc/apt
82 }
83
84 make_packages () {
85     run_cmd apt-get update
86     installpkglist=($(grep -h -v ^'#' ${script_path}/packages.x86_64))
87     run_cmd apt-get --yes install ${installpkglist[@]}
88 }
89
90 prepare_build
91 run_once make_basefs
92 run_once make_sourcelist
93 # run_once make_packages