archlinux安装脚本-3-标准安装

本文分享了一个用于ArchLinux自动化安装的bash脚本,详细介绍了从磁盘分区、软件包安装到系统配置的全过程,包括对话框交互、软件选择、系统初始化等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

系统默认分区:

sda1    swap

sda2    /

sda3    /home

#!/bin/bash
function install_dialog(){
    is_dialog_install=`pacman -Qi dialog 2> /dev/null`
    #install dialog if not install
    if [ -z "$is_dialog_install" ]
    then
        pacman -S --noconfirm dialog
    fi
}

function install_powerpill(){
    cp /etc/pacman.conf /etc/pacman.conf.default
    
    echo "[archlinuxcn]" >> /etc/pacman.conf
    echo "SigLevel = Optional TrustAll" >> /etc/pacman.conf
    echo "Server = http://repo.archlinuxcn.org/$arch" >> /etc/pacman.conf
    
    pacman -Syy
    pacman -S --noconfirm archlinuxcn-keyring
    pacman -S --noconfirm yaourt
    echo 1 | yaourt --noconfirm powerpill
    
    rm -rf /etc/pacman.conf
    cp /etc/pacman.conf.default /etc/pacman.conf
    pacman -Syy
}


function jbase(){
    dialog --backtitle "Archlinux install script" --clear 
    --title "Description" 
    --yesno "By default: 

    mount sda1 to swap 

    mount sda2 to /  

    mount sda3 to /home 


    Click yes to start install.
Click no to exit
Click esc to reboot" 20 90
    
    respose=$?
    case $respose in
    0)
    ;;
    1)
    exit 1
    ;;
    *)
    reboot;;
    esac
    
    #mount
    mkswap /dev/sda1
    swapon /dev/sda1
    mkfs.ext4 /dev/sda2
    mkfs.ext4 /dev/sda3
    mount /dev/sda2 /mnt
    mkdir /mnt/home
    mount /dev/sda3 /mnt/home
    
    #add packages source
    if [ -f "/etc/pacman.d/mirrorlist" ]
    then
        mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.default
    fi
    
    echo "Server = http://mirrors.aliyun.com/archlinux/$repo/os/$arch" > /etc/pacman.d/mirrorlist
    echo "Server = http://mirror.bit.edu.cn/archlinux/$repo/os/$arch" >> /etc/pacman.d/mirrorlist
    echo "Server = http://mirrors.163.com/archlinux/$repo/os/$arch" >> /etc/pacman.d/mirrorlist
    echo "Server = http://mirrors.sohu.com/archlinux/$repo/os/$arch" >> /etc/pacman.d/mirrorlist
    echo "Server = http://mirrors.yun-idc.com/archlinux/$repo/os/$arch" >> /etc/pacman.d/mirrorlist
    echo "Server = http://ftp.sjtu.edu.cn/archlinux/$repo/os/$arch" >> /etc/pacman.d/mirrorlist
    echo "Server = http://mirrors.4.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch" >> /etc/pacman.d/mirrorlist
    echo "Server = http://mirror.lzu.edu.cn/archlinux/$repo/os/$arch" >> /etc/pacman.d/mirrorlist
    echo "update packages"
    pacman -Syy
    
    pacstrap /mnt base base-devel
    
    #set fstab
    echo "make fstab "
    genfstab -p /mnt >> /mnt/etc/fstab
    
    cp -a ${0} /mnt/root
    
    #Chroot
    clear
    echo "/root/${0} to continue"
    arch-chroot /mnt
    
    umount -R /mnt
    systemctl reboot
}

function install_software(){
    clear
    if dialog --backtitle "Configure" --title "Install software" 
    --checklist "Click space to select or deselect ,enter to confirm ,click other to cancel" 20 90 20 
    libreoffice "office" on
    abiword "office work" on
    gnumeric "office excel" on
    adwaita-icon-theme  "" on 
    evince "pdf reader" on
    faience-icon-theme "icon theme" on
    fcitx "input method" off
    fcitx-im "input method" off
    fcitx-configtool "input method" off
    fcitx-sunpinyin "input method" off
    ibus "input method" on
    ibus-qt "input method" on
    ibus-pinyin "input method" on
    firefox "web brower" on
    epiphany "web brower" off
    flashplugin "brower plugin" on
    gftp "ftp client" on
    gimp "picture editor" on
    git "" on
    gnome-mplayer  "video player" off
    vlc "video player" on 
    parole "video player" on 
    gnome-screenshot "" off
    gstreamer0.10-plugins "" on
    gtk-engines "" on
    gvfs "" on
    gvfs-mtp "" on
    lightdm-gtk-greeter-settings "" on 
    lxde "desktop environment" on
    cinnamon "desktop environment" off
    xfce4 "desktop environment" off
    mate "desktop environment" off
    plasma "desktop environment" off
    gnome "desktop environment" off
    enlightenment "desktop environment" off
    cairo-dock "customer desktop-taskbar" off
    plank "customer desktop-taskbar" off
    tint2 "customer desktop-taskbar" off
    awesome "customer desktop-window manager" off
    lxterminal "customer desktop-terminal emulator" off
    medit "editor" on
    network-manager-applet "" on
    networkmanager-openconnect "" on
    networkmanager-openvpn "" on
    networkmanager-pptp "" on
    networkmanager-vpnc "" on
    ntfs-3g "" on
    numlockx "" off
    openssh "" on
    p7zip "" on
    plank "" off
    thunderbird "" off
    udisks2 "" on
    unrar "" on
    unzip "" on
    virtualbox "" on
    virtualbox-host-modules "" on
    wiznote "" on
    xarchiver "" off
    xcompmgr "" off
    zip "" on
    2>/tmp/jarch/software.txt
    then
    dialog --backtitle "Configure" --title "Install software" --infobox "ing..." 20 90
    powerpill -S --noconfirm mesa
    powerpill -S --noconfirm wqy-microhei
    powerpill -S --noconfirm ttf-dejavu
    powerpill -S --noconfirm xf86-video-vesa
    powerpill -S --noconfirm xf86-input-evdev
    powerpill -S --noconfirm xorg-xinit
    powerpill -S --noconfirm xorg-server
    powerpill -S --noconfirm alsa-utils
    powerpill -S --noconfirm ntfs-3g gvfs
    powerpill -S --noconfirm lightdm lightdm-gtk-greeter
    systemctl enable lightdm
       selections=`cat /tmp/jarch/software.txt`
    for i in $selections ; do
    powerpill -S --noconfirm $i
    done
    fi
}
    
function jconfig(){
    mkdir /tmp/jarch
    install_dialog
    install_powerpill
    #init
    clear
    mkinitcpio -p linux
    
    #locale
    clear
    echo "locale-gen"
    echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
    echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen
    locale-gen
    echo "make language "
    echo.UTF-8 > /etc/locale.conf
    ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    echo "make time"
    hwclock --systohc --utc
    
    #GRUB
    clear
    echo "install and config grub"
    powerpill -S --noconfirm grub
    grub-install /dev/sda
    grub-mkconfig -o /boot/grub/grub.cfg
    
    #network
    clear
    echo "auto start network"
    powerpill -S --noconfirm networkmanager
    systemctl enable NetworkManager
    
    
    #pc name
    clear
    dialog --backtitle "Configure" --title "pc" 
    --inputbox "Enter the pc name." "Archlinux" 20 90 2>/tmp/jarch/pc.txt
    case $? in
    0)
    pcname=$( /etc/hostname
    
    #root password
    clear
    dialog --backtitle "Configure" --title "root passowrd" 
    --insecure --passwordbox "enter the root password" 20 90 2>/tmp/jarch/rootpw.txt
    case $? in
    0)
    rootpwd=$( /dev/null
    ;;
    *)
    ;;
    esac
    
    #new user
    powerpill -S --noconfirm sudo
    powerpill -S --noconfirm zsh
    rm -rf /etc/skel/*
    echo "autoload -U compinit promptinit" > .zshrc
    echo "compinit" >> .zshrc
    echo "promptinit" >> .zshrc
    echo "prompt adam2" >> .zshrc
    echo ""
    echo 'bindkey "e[1~" beginning-of-line # Home' >> .zshrc
    echo 'bindkey "e[4~" end-of-line # End' >> .zshrc
    echo 'bindkey "e[5~" beginning-of-history # PageUp' >> .zshrc
    echo 'bindkey "e[6~" end-of-history # PageDown' >> .zshrc
    echo 'bindkey "e[2~" quoted-insert # Ins' >> .zshrc
    echo 'bindkey "e[3~" delete-char # Del' >> .zshrc
    
    
    clear
    dialog --backtitle "Configure" --title "user" 
    --inputbox "Enter the new user name." "arch" 20 90 2>/tmp/jarch/newuser.txt
    case $? in
    0)
    newuser=$(/tmp/jarch/userpw.txt
    case $? in
    0)
    userpwd=$( /dev/null
    
    echo "${newuser} ALL=(ALL) ALL" >> /etc/sudoer
    echo "Defaults:${newuser} timestamp_timeout=22" >> /etc/sudoer
    echo "Defaults rootpw" >> /etc/sudoer
    
    #install software
    install_software
    systemctl enable lightdm
    
    clear
    echo "Delete something"
    mkdir /tmp/jarch
    pacman -Rscn --noconfirm dialog
    
    clear
    echo "Install over . Input exit and click enter to reboot"
    exit 0
}



if [ -z $1 ]
then
    dialog_install=`pacman -Qi dialog 2> /dev/null`
    if [ -z "$dialog_install" ]
    then
        jconfig
    else
        jbase
    fi
else
    $@
fi


转载于:https://my.oschina.net/jonetwelve/blog/617196

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值