Ubuntu Pastebin

Paste from balogh at Thu, 12 Feb 2015 09:48:09 +0000

Download as text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
SCHROOT_CHROOT_PATH="/var/lib/schroot/chroots"
USE_READY_IMAGE=false
CREATE_STATIC_IMAGE=false
TARGET_ARCH="armhf"
MACHINE_TYPE=`uname -m`
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  ARCH_TYPE="amd64"
else
  ARCH_TYPE="i386"
fi

STATIC_CHROOT_NAME="click-ubuntu-sdk-15.04-${TARGET_ARCH}"
PWD=`pwd`

# Set up this use for click schroots
CLICK_USER=`who am i|awk '{print $1}'`

couple_chroot() {
    echo "Set up the mounts"
    mount -o bind /dev ${PWD}/${STATIC_CHROOT_NAME}/dev
    mount -o bind /dev/pts ${PWD}/${STATIC_CHROOT_NAME}/dev/pts
    mount -o bind /sys ${PWD}/${STATIC_CHROOT_NAME}/sys
    mount -o bind /proc ${PWD}/${STATIC_CHROOT_NAME}/proc
    mount -o bind /tmp ${PWD}/${STATIC_CHROOT_NAME}/tmp
    mount -o bind /home ${PWD}/${STATIC_CHROOT_NAME}/home
    mkdir -p ${PWD}/${STATIC_CHROOT_NAME}/run/shm
    mount -o bind /run/shm ${PWD}/${STATIC_CHROOT_NAME}/run/shm
    echo "Fixing the nssdatabases"
    pushd "${PWD}/${STATIC_CHROOT_NAME}/etc"
        mv passwd passwd-
        cp /etc/passwd ./
        mv shadow shadow-
        cp /etc/shadow ./
        mv group group-
        cp /etc/group ./
        mv gshadow gshadow-
        cp /etc/gshadow ./
        mv services  services-
        cp /etc/services ./
        mv protocols protocols-
        cp /etc/protocols ./
        mv networks networks-
        cp /etc/networks ./
        mv hosts hosts-
        cp /etc/hosts ./
        mv resolv.conf resolv.conf-
        cp /etc/resolv.conf ./
    popd
}

decouple_chroot () {
    mount|grep ${STATIC_CHROOT_NAME}|awk '{print $3}'|xargs sudo umount -lf
    echo "Reverting the nssdatabases"
    pushd "${PWD}/${STATIC_CHROOT_NAME}/etc"
        mv passwd- passwd
        mv shadow- shadow
        mv group- group
        mv gshadow- gshadow
        mv services-  services
        mv protocols- protocols
        mv networks- networks
        mv hosts- hosts
        mv resolv.conf- resolv.conf
    popd
}

fix_core_chroot() {
    echo "Install dselect"
    chroot ${PWD}/${STATIC_CHROOT_NAME} apt-get -y install dselect 2>&1 > /dev/null
    echo "Fix the sources.list"
    cat >  ${PWD}/${STATIC_CHROOT_NAME}/etc/apt/sources.list << EOF
deb [arch=$TARGET_ARCH] http://ports.ubuntu.com/ubuntu-ports vivid main restricted universe multiverse
deb [arch=$TARGET_ARCH] http://ports.ubuntu.com/ubuntu-ports vivid-updates main restricted universe multiverse
deb [arch=$TARGET_ARCH] http://ports.ubuntu.com/ubuntu-ports vivid-security main restricted universe multiverse
deb [arch=$ARCH_TYPE] http://archive.ubuntu.com/ubuntu vivid main restricted universe multiverse
deb [arch=$ARCH_TYPE] http://archive.ubuntu.com/ubuntu vivid-updates main restricted universe multiverse
deb [arch=$ARCH_TYPE] http://archive.ubuntu.com/ubuntu vivid-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu vivid main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu vivid-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu vivid-security main restricted universe multiverse
EOF
    chroot ${PWD}/${STATIC_CHROOT_NAME} apt-get -y  update 
    chroot ${PWD}/${STATIC_CHROOT_NAME} dselect update 
    chroot ${PWD}/${STATIC_CHROOT_NAME} dpkg --add-architecture $TARGET_ARCH
    chroot ${PWD}/${STATIC_CHROOT_NAME} apt-get -y update
    chroot ${PWD}/${STATIC_CHROOT_NAME} apt-get -y install ubuntu-sdk-libs:$TARGET_ARCH ubuntu-sdk-libs-dev:$TARGET_ARCH ubuntu-sdk-libs-tools 
    if [[ $TARGET_ARCH == armhf ]]; then
       chroot ${PWD}/${STATIC_CHROOT_NAME} apt-get -y install g++-arm-linux-gnueabihf pkg-config-arm-linux-gnueabihf
    else
       chroot ${PWD}/${STATIC_CHROOT_NAME} apt-get -y install g++ pkg-config
    fi
    chroot ${PWD}/${STATIC_CHROOT_NAME} apt-get -y clean
}

fix_new_schroot() {
    echo "Registering the new chroot to schroot"
    cat > /etc/schroot/chroot.d/${STATIC_CHROOT_NAME} << EOF
[${STATIC_CHROOT_NAME}]
description=Build chroot for click packages on ${TARGET_ARCH}
users=root,${CLICK_USER}
root-users=root,${CLICK_USER}
source-root-users=root,${CLICK_USER}
type=directory
profile=default
setup.fstab=click/fstab
# Not protocols or services see
# debian bug 557730
setup.nssdatabases=sbuild/nssdatabases
union-type=overlayfs
directory=${PWD}/${STATIC_CHROOT_NAME}
EOF
}

while getopts ":hc:a:f:" opt; do
    case $opt in
	a)
	    TARGET_ARCH=$OPTARG
            if [[ ${TARGET_ARCH} != i386 && ${TARGET_ARCH} != armhf ]]; then
                echo "${TARGET_ARCH} not a valid arch type. Use armhf or i386."
		exit
            fi
	    ;;
        f)
	    if [ ! -f ${IMAGE_FILE} ]; then
		echo "Error: " ${IMAGE_FILE} "does not exist."
                exit
            fi
	    USE_READY_IMAGE=true
            IMAGE_FILE=$OPTARG
	    TARGET_ARCH=${IMAGE_FILE/click-ubuntu-sdk-15\.04-/}
            TARGET_ARCH=${TARGET_ARCH/\.tar\.gz/}
            ;;
        c)
            CREATE_STATIC_IMAGE=true
            ;;
        h)
            echo "Usage: sudo create_static_schroot.sh -f [image file] -h"
            echo -e "\t-c : Create static click chroot image file for ${TARGET_ARCH}"
            echo -e "\t-f : Image file to set up as click chroot"
            echo -e "\t-h : Prints this help."
            echo ""
            echo "By default the create_static_schroot.sh downloads the ${ARCH_TYPE} image file"
            echo "and extend it with the Ubuntu 15.04 ${TARGET_ARCH} framework and SDK dev tools"
	    exit
            ;;
        :)
            echo "Option -$OPTARG requires an argument." >&2
            exit
    esac
done

if [ ${CREATE_STATIC_IMAGE} == true ]; then
    if [ ! -f vivid-core-${ARCH_TYPE}.tar.gz ]; then
        echo "Fetch the core"
        wget http://cdimage.ubuntu.com/ubuntu-core/daily/current/vivid-core-${ARCH_TYPE}.tar.gz
    fi
    if [ ! -f ${PWD}/${STATIC_CHROOT_NAME} ]; then
        mkdir ${PWD}/${STATIC_CHROOT_NAME}
        tar zxf vivid-core-${ARCH_TYPE}.tar.gz -C ${PWD}/${STATIC_CHROOT_NAME}
    fi
    couple_chroot
    fix_core_chroot
    decouple_chroot
    tar czf ${PWD}/${STATIC_CHROOT_NAME}.tar.gz ${PWD}/${STATIC_CHROOT_NAME}
    rm ${PWD}/${STATIC_CHROOT_NAME} -rf
    IMAGE_FILE=${PWD}/${STATIC_CHROOT_NAME}.tar.gz
fi 

if [ ${USE_READY_IMAGE} == true ]; then
    echo "Extracting ${IMAGE_FILE}"
    tar zxf ${IMAGE_FILE}
    if [ -f ${SCHROOT_CHROOT_PATH}/click-ubuntu-sdk-15.04-${TARGET_ARCH} ]; then
        mount|egrep "click-ubuntu-sdk-15\.04-${TARGET_ARCH}" |awk '{print $3}'|xargs sudo umount -lf
        mv ${SCHROOT_CHROOT_PATH}/click-ubuntu-sdk-15.04-${TARGET_ARCH} ${SCHROOT_CHROOT_PATH}/click-ubuntu-sdk-15.04-${TARGET_ARCH}-backup
    fi
    echo "Copy over the chroot"
    cp ${PWD}/${STATIC_CHROOT_NAME} ${SCHROOT_CHROOT_PATH}/ -r
    PWD="${SCHROOT_CHROOT_PATH}"
    STATIC_CHROOT_NAME="click-ubuntu-sdk-15.04-${TARGET_ARCH}"
    couple_chroot
    fix_new_schroot
fi
Download as text