代码拉取完成,页面将自动刷新
同步操作将从 junlangit/自动化脚本 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/bin/bash
#===========module select =======================================
busybox_install_is="no"
arm_linux_kernel_make_is="no"
#===========argv select =======================================
embeded_linux_shell_type="arm_linux_kernel" #"arm_linux_kernel" "update_kernel"
arm_linux_kernel_type="qemu" #"qemu" "device"
sys_pack_update="n" #"y" "Y" "n" "N"
kernel_config_way="oneself_kernel" #"sys_kernel"
#===========cmd================================================
sudo_pre=sudo
package_cmd=apt-get
#===========package=============================================
packages=("libncurses5-dev" "libssl-dev" "build-essential" "openssl" "bison" "bc" "flex" "libelf-dev" "git" )
arm_linux_packages=("gcc-arm-linux-gnueabi" "gcc-5-arm-linux-gnueabi" )
qemu_packages=("pkg-config" "libglib2.0-dev" "libpixman-1-dev")
#===========static info====================================
update_kernel_vesion=5.16.10
arm_linux_kernel_version=4.0
linux_kernel_download_path=.
sys_sleep=1
#======================================================================
function package_install()
{
#package=$1
${sudo_pre} dpkg -l |awk '{print $2}'|grep -w ^${package}
if [ $? -eq 0 ];then
echo "软件包"${pName}"已经安装。"
else
echo "软件包"${package}"没有安装"
#read -p "是否安装(y|n):" -n 1 OK #-n 1 表示只能输一下,输入到OK的变量
OK="y"
#y或者Y用双竖线‘||’分割的多条命令,执行的时候遵循如下规则,如果前一条命令为真,则后面的命令不会执行,如果前一条命令为假,则继续执行后面的命令。
if [ ${OK} = "y" ] || [ ${OK} = "Y" ];then
echo "开始安装"${package}"……"
${sudo_pre} ${package_cmd} -y install ${package} #>> /dev/null
if test $? -eq 0
then
echo "安装"${package}"完成。"
else
echo "安装"${package}"失败。"
fi
else
echo "您选择了不安装"
fi
fi
}
function packages_install()
{
echo "packages install begin,all [ ${#packages[@]} ]"
for ((i=0; i<${#packages[@]}; i++))
do
package=${packages[${i}]}
#echo "===install [ ${package} ] package==="
package_install ${package}
#sleep 1
done
echo "packages install over"
}
#=========================================================================
#检测网络链接畅通
function network()
{
#超时时间
local timeout=1
#目标网站
local target=www.baidu.com
i=1
check_timers=10
while [ ${i} -le ${check_timers} ]
do
if true ; then
#获取响应状态码
local ret_code=`curl -I -s --connect-timeout ${timeout} ${target} -w %{http_code} | tail -n1`
if [ "x$ret_code" = "x200" ]; then
echo "network is ok"
return 1 #网络畅通
fi
else
pingres= ping -c 1 ${target} | sed -n '/64 bytes from/p'
if [! -z "${pingres}" ];then
echo "network is ok"
return 1 #网络畅通
fi
fi
echo "the ${i} check..."
let i+=1
sleep 1
done
echo "network error,plesa check"
exit 1
}
#========================================================================
function file_download()
{
file_type=0
#download_file_name=$1
#download_link=$2
#download_path=$3
while true
do
if [ -f ${download_file_name} ];then
echo "${download_file_name} ok."
else
echo "${download_file_name} download begin..."
sleep ${sys_sleep}
${sudo_pre} wget -P ${download_path}/ ${download_link}
if [ -f ${download_file_name} ];then
echo "${download_file_name} download over..."
sleep ${sys_sleep}
else
echo "${download_file_name} download failed,please check..."
exit 0
fi
fi
echo "${download_file_name}" | grep ".tar.xz"
if [ $? -eq 0 ];then
download_file_tar_name=${download_file_name%.tar.xz}
else
download_file_tar_name=${download_file_name%.tar.bz2}
fi
if [ -d ${download_path}${download_file_tar_name} ];then
read -p $'find old package,do you need to remove\n ,if you want,input \"y\" ,else \"n\" :\n'
if [ ${sys_pack_update} == "y" -o ${sys_pack_update} == "Y" ];then
${sudo_pre} mv ${download_path}${download_file_tar_name} ${download_path}${download_file_tar_name}-backup
else
break
fi
fi
echo " ${download_path}${download_file_name} tar..."
echo "${download_file_name}" | grep ".tar.xz"
if [ $? -eq 0 ];then
${sudo_pre} tar -Jxf ${download_path}${download_file_name}
else
echo "${download_file_name}" | grep ".tar.bz2"
if [ $? -eq 0 ];then
${sudo_pre} tar -jxvf ${download_path}${download_file_name}
fi
fi
if [ ! $? -eq 0 ];then
echo "tar failed"
if [ -d ${download_path}${download_file_tar_name} ];then
${sudo_pre} rm -r ${download_path}${download_file_tar_name}
fi
${sudo_pre} rm ${download_path}${download_file_name}
else
echo "tar ok"
sleep ${sys_sleep}
break
fi
done
}
#==============================================================================================
function device_select()
{
while true
do
if [ ${mode} == "1" ];then
read -p $'please input arm_linux_kernel_type name:\n \"update_kernel\" or \"arm_linux_kernel\"\n' embeded_linux_shell_type
fi
if [ ${embeded_linux_shell_type} == "update_kernel" ] || [ ${embeded_linux_shell_type} == "arm_linux_kernel" ];then
if [ ${embeded_linux_shell_type} == "arm_linux_kernel" ];then
while true
do
if [ mode == 1 ];then
read -p $'please input embeded_linux_shell_type name:\n \"device\" or \"qemu\"\n' arm_linux_kernel_type
fi
if [ ${arm_linux_kernel_type} == "device" -o ${arm_linux_kernel_type} == "qemu" ];then
packages+=(${arm_linux_packages[@]})
#echo ${packages}
linux_kernel_version=${arm_linux_kernel_version}
#echo ${linux_kernel_version}
break
else
echo "please input the correct arm_linux_kernel_type name..."
fi
done
else
linux_kernel_version=${update_kernel_vesion}
fi
break
else
echo "please input the correct embeded_linux_shell_type name..."
fi
done
echo "[${embeded_linux_shell_type}] ${arm_linux_kernel_type} will begin..."
}
#==============================================================================================
echo "emebed linux package install"
echo "designed by junzhu,2022.2.18"
sleep ${sys_sleep}
mode="0"
device_select mode
echo "network check..."
sleep ${sys_sleep}
network
#====================================================================
echo "step1 prepare..."
echo "package update..."
read -p $'do you need to update package \n ,if you want,input \"y\": \n' sys_pack_update
if [ ${sys_pack_update} == "y" -o ${sys_pack_update} == "Y" ];then
${sudo_pre} ${package_cmd} update
fi
echo "prepare ok,packages will install"
#====================================================================
echo "step2 packages install..."
sleep ${sys_sleep}
packages_install packages
#******************************************************************
if [ ${embeded_linux_shell_type} == "update_kernel" ];then
echo "kernel dependent..."
${sudo_pre} ${package_cmd} build-dep linux-image-generic
fi
sleep ${sys_sleep}
#====================================================================
echo "step3 prepare linux kernel..."
#**************************************************************************
echo "(1) linux kernel download..."
sleep ${sys_sleep}
download_file_name="linux-${linux_kernel_version}.tar.xz"
download_link="https://cdn.kernel.org/pub/linux/kernel/v${linux_kernel_version:0:1}.x/linux-${linux_kernel_version}.tar.xz"
download_path="${linux_kernel_download_path}/"
file_download ${download_file_name} ${download_link} ${download_path}
#**************************************************************************
if [ ${embeded_linux_shell_type} == "arm_linux_kernel" ];then
echo "(2) linux compiler replacement..."
#while true
#do
sleep ${sys_sleep}
arm-linux-gnueabi-gcc -v #| grep "5.5.0"
#if [ ! $? -eq 0 ];then
${sudo_pre} update-alternatives --install /usr/bin/arm-linux-gnueabi-gcc arm-linux-gnueabi-gcc /usr/bin/arm-linux-gnueabi-gcc-5 5
${sudo_pre} update-alternatives --install /usr/bin/arm-linux-gnueabi-gcc arm-linux-gnueabi-gcc /usr/bin/arm-linux-gnueabi-gcc-7 7
${sudo_pre} update-alternatives --config arm-linux-gnueabi-gcc
#else
# break
#fi
#done
echo "linux compiler replacement ok, 5.5.0..."
#**************************************************************************
echo "(3) busybox download & make..."
sleep ${sys_sleep}
download_file_name="busybox-1.28.0.tar.bz2"
download_link="https://busybox.net/downloads/busybox-1.28.0.tar.bz2"
download_path="${linux_kernel_download_path}/"
file_download ${download_file_name} ${download_link} ${download_path}
echo "if you open kernel configuration success,please select \"build static binary\" of \"build option\",then select \"Exit\" and \"Save\""
sleep ${sys_sleep}
cd ${download_path}busybox-1.28.0
if [ ${busybox_install_is} == "" ] ;then
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
make menuconfig
make install
fi
echo "busbox make install success"
cp -r ./_install ../linux-4.0/
cd ../linux-4.0/_install
${sudo_pre} mkdir ./etc
${sudo_pre} mkdir ./dev
${sudo_pre} mkdir ./mnt
${sudo_pre} mkdir -p etc/init.d/
${sudo_pre} touch ./etc/init.d/rcS
write_to_content="mkdir -p /proc\nmkdir -p /tmp\nmkdir -p /sys\nmkdir -p /mnt\n/bin/mount -a\nmkdir -p /dev/pts\nmount -t devpts devpts /dev/pts\necho /sbin/mdev > /proc/sys/kernel/hotplug\nmdev -s\n"
echo -e ${write_to_content} > ./etc/init.d/rcS
${sudo_pre} chmod +x ./etc/init.d/rcS
${sudo_pre} touch ./etc/fstab ./etc/inittab
write_to_content="proc /proc proc defaults 0 0\ntmpfs /tmp tmpfs defaults 0 0\nsysfs /sys sysfs defaults 0 0\ntmpfs /dev tmpfs defaults 0 0\ndebugfs /sys/kernel/debug debugfs defaults 0 0\n"
echo -e ${write_to_content} > ./etc/fstab
write_to_content="::sysinit:/etc/init.d/rcS\n::respawn:-/bin/sh\n::askfirst:-/bin/sh\n::ctrlaltdel:/bin/umount -a -r\n"
echo -e ${write_to_content} > ./etc/inittab
cd ./dev/
${sudo_pre} mknod console c 5 1
${sudo_pre} mknod null c 1 3
cd ../../../
#**************************************************************************
if [ ${arm_linux_kernel_type} == "qemu" ];then
echo "(4) qemu download & install..."
if false ; then
sleep ${sys_sleep}
download_file_name="qemu-4.1.0.tar.xz"
download_link="https://download.qemu.org/qemu-4.1.0.tar.xz"
download_path="${linux_kernel_download_path}/"
file_download ${download_file_name} ${download_link} ${download_path}
echo "qemu config & make..."
if false ;then
cd ${download_path}${download_file_name%.tar.xz}
./configure
make
cd ..
fi
echo "qemu make success"
else
${sudo_pre} ${package_cmd} install qemu-system-arm
fi
echo "qemu ok"
fi
fi
#====================================================================
echo "step4 linux kernel configuration..."
cd ${linux_kernel_download_path}/linux-${linux_kernel_version}
if [ ${embeded_linux_shell_type} == "arm_linux_kernel" ];then
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
make vexpress_defconfig
sleep ${sys_sleep}
else
if [ ${kernel_config_way} == "sys_kernel" ];then
echo "use kylin's kernel configuration..."
echo "backup first..."
${sudo_pre} mv ${linux_kernel_download_path}/.config ${linux_kernel_download_path}/.config-backup
kernel_name=`uname -r`
kernel_config_file=/boot/config-${kernel_name}
echo "the linux kernel_config_file is [${kernel_config_file}]"
if [ ! -f ${kernel_config_file} ];then
${sudo_pre} cp ${kernel_config_file} ${linux_kernel_download_path}/.config
fi
echo "[${kernel_config_file}] use ok"
fi
fi
echo "if you open kernel configuration success,please select \"Exit\" and \"Save\""
while true
do
make_menuconfig= make menuconfig
if [ ! $? -eq 0 ];then
${make_menuconfig} # | grep "Your display is too small to run Menuconfig!"
if [ ! $? -eq 0 ];then
if false ; then
display_size_current=`${sudo_pre} xrandr | sed -n '3p' | awk '{print $1}' | sed 's/x/ /g'`
display_size_max=`${sudo_pre} xrandr | sed -n '4p'| awk '{print $1}' | sed 's/x/ /g'`
echo "resize display size [${display_size_current}] to [${display_size_max}]..."
${sudo_pre} cvt ${display_size_max}
source /etc/profile
else
echo "please check ,and try again"
exit 0
fi
fi
else
if false ; then
echo "recovery display size ..."
echo "resize display size [${display_size_max}] to [${display_size_current}]..."
${sudo_pre} cvt ${display_size_current}
source /etc/profile
fi
echo "linux kernel configuration ok ..."
break
fi
sleep ${sys_sleep}
done
sleep ${sys_sleep}
#====================================================================
echo "step5 moudle make..."
cpu_num=`cat /proc/stat | grep cpu[0-9] -c`
if [ ${embeded_linux_shell_type} == "arm_linux_kernel" ];then
if [ ${arm_linux_kernel_make_is} == "yes" ] ;then
make bzImage -j${cpu_num} ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
make dtbs
fi
else
echo "make -j${cpu_num}"
#make -j${cpu_num}
#sudo make modules_install
#sudo make install
fi
echo "make success ..."
#====================================================================
if [ ${embeded_linux_shell_type} == "arm_linux_kernel" ];then
echo "step6 Run QEMU to simulate the 4-core cortex-a9 versatile express development platform ..."
qemu-system-arm -M vexpress-a9 -smp 4 -m 200M -kernel arch/arm/boot/zImage -append "rdinit=/linuxrc console=ttyAMA0 loglevel=8" -dtb arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic
fi
exit 0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。