124 lines
3.2 KiB
Bash
Executable File
124 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# copy (hosts hostname mailname resolv.conf)
|
|
function copy_host_conf(){
|
|
mount_dir=$1
|
|
cd "$mount_dir"
|
|
|
|
rm -f "$mount_dir/etc/hosts"
|
|
cp /etc/hosts "$mount_dir/etc/hosts"
|
|
|
|
rm -f "$mount_dir/etc/hostname"
|
|
cp /etc/hostname "$mount_dir/etc/hostname"
|
|
|
|
rm -f "$mount_dir/etc/mailname"
|
|
cp /etc/mailname "$mount_dir/etc/mailname"
|
|
|
|
rm -f "$mount_dir/etc/resolv.conf"
|
|
if [ ! -f "/run/resolvconf/resolv.conf" ]; then
|
|
cp /etc/resolv.conf "$mount_dir/etc/resolv.conf"
|
|
else
|
|
cp /run/resolvconf/resolv.conf "$mount_dir/etc/resolv.conf"
|
|
fi
|
|
|
|
}
|
|
|
|
# mount /proc /run/shm /dev/pts
|
|
function mounting_filesystem(){
|
|
mount_dir=$1
|
|
cd "$mount_dir"
|
|
|
|
mkdir -p "$mount_dir/proc"
|
|
mount -t proc /proc "$mount_dir/proc"
|
|
ln -s ../proc/mounts "$mount_dir/etc/mtab"
|
|
|
|
mkdir -p "$mount_dir/run/shm"
|
|
mount -t tmpfs tmpfs "$mount_dir/run/shm"
|
|
|
|
mkdir -p "$mount_dir/dev/pts"
|
|
mount -t devpts none "$mount_dir/dev/pts" -onoexec,nosuid,gid=5,mode=620
|
|
}
|
|
# umount /proc /run/shm /dev/pts
|
|
function umount_filesystem(){
|
|
mount_dir=$1
|
|
umount "$mount_dir/dev/pts"
|
|
umount "$mount_dir/run/shm"
|
|
umount "$mount_dir/proc"
|
|
chroot $mount_dir /usr/bin/apt-get clean
|
|
}
|
|
|
|
#
|
|
function ln_aptcache(){
|
|
mount_dir=$1
|
|
cd "$mount_dir"
|
|
|
|
for file in `find $APTCACHE_DIR -maxdepth 1 -name '*.deb'`
|
|
do
|
|
ln "$file" "$mount_dir/var/cache/apt/archives/"
|
|
done
|
|
|
|
}
|
|
#
|
|
function rmln_aptcache(){
|
|
mount_dir=$1
|
|
cd "$mount_dir"
|
|
|
|
for file in `find "$mount_dir/var/cache/apt/archives/" -maxdepth 1 -name '*.deb'`
|
|
do
|
|
rm -f "$file"
|
|
done
|
|
}
|
|
#
|
|
function save_aptcache(){
|
|
mount_dir=$1
|
|
cd "$mount_dir"
|
|
mkdir -p $APTCACHE_DIR
|
|
|
|
for file in `find "$mount_dir/var/cache/apt/archives/" -maxdepth 1 -name '*.deb'`
|
|
do
|
|
file_name=`basename "$file"`
|
|
if [ ! -f "$APTCACHE_DIR/$file_name" ]; then
|
|
echo "$file_name not exist,copy"
|
|
cp "$file" $APTCACHE_DIR
|
|
fi
|
|
done
|
|
}
|
|
#
|
|
function save_base_tgz(){
|
|
mount_dir=$1
|
|
cd "$mount_dir"
|
|
mkdir -p build lib64
|
|
mkdir -p $TOOLS_COMMOD_DIR
|
|
base_name="base-$DISTRIBUTION-$ARCH"
|
|
rm -f $TOOLS_COMMOD_DIR/$base_name.tgz.tmp
|
|
tar -c --use-compress-program gzip -f $TOOLS_COMMOD_DIR/$base_name.tgz.tmp ./bin ./boot ./build ./dev ./etc ./home ./lib ./lib64 ./media ./mnt ./opt ./proc ./root ./run ./sbin ./srv ./sys ./tmp ./usr ./var
|
|
mv $TOOLS_COMMOD_DIR/$base_name.tgz.tmp $TOOLS_COMMOD_DIR/$base_name.tgz
|
|
}
|
|
#
|
|
function decompress_base_tgz(){
|
|
mount_dir=$1
|
|
cd "$mount_dir"
|
|
base_name="base-$DISTRIBUTION-$ARCH"
|
|
tar -x --use-compress-program gzip -p -f $TOOLS_COMMOD_DIR/$base_name.tgz
|
|
}
|
|
#
|
|
function rm_mount_dir(){
|
|
mount_dir=$1
|
|
rm -rf "$mount_dir"
|
|
}
|
|
# 设置 sources.list 并更新
|
|
function set_sources_update(){
|
|
mount_dir=$1
|
|
chroot $mount_dir /bin/bash -c "echo 'deb $MIRRORS xenial main universe' > /etc/apt/sources.list"
|
|
chroot $mount_dir /usr/bin/apt-get -q update
|
|
chroot $mount_dir /usr/bin/apt-get -q -y -o DPkg::Options::=--force-confnew dist-upgrade
|
|
chroot $mount_dir /usr/bin/apt-get -q -y install build-essential dpkg-dev wget
|
|
|
|
# ubports repo
|
|
chroot $mount_dir wget http://repo.ubports.com/keyring.gpg
|
|
chroot $mount_dir apt-key add keyring.gpg
|
|
|
|
chroot $mount_dir /bin/bash -c "echo 'deb $UBPORTS_MIRRORS xenial main' >> /etc/apt/sources.list"
|
|
chroot $mount_dir /usr/bin/apt-get -q update
|
|
chroot $mount_dir /usr/bin/apt-get -q -y -o DPkg::Options::=--force-confnew dist-upgrade
|
|
} |