1
0
mirror of https://gitlab.com/JKANetwork/JKArch.git synced 2026-02-15 09:41:31 +01:00
Files
JKArch/archinstall/archinstall.sh
2016-09-23 09:24:40 +02:00

384 lines
12 KiB
Bash
Executable File

#!/bin/bash
## Note: Some text editors in some lines its wrong the "markup color" because much '"'($) things.
sclang=$1
source translations.sh
##Offline var
isoffline=0
if [[ ! -z "$2" ]];then
isoffline="$2" #If its offline will be 1
fi
#Try to disable ctrl+C
trap '' INT
#No black screensaver
setterm -blank 0 -powerdown 0 -powersave off
#Fix para caracteres de dialog, ñ o tildes
export NCURSES_NO_UTF8_ACS=1
function pause {
echo "$(T "Press enter to continue...")"
read
}
function mostrardialog {
local titled
local msgd
titled=$1
msgd=$2
dialog --title "$titled" --msgbox "$msgd" 15 60
}
function fatalerror {
razon=$1
mostrardialog "Error" "$(T "An error has ocurred, setup will be stopped") $razon"
exit
}
function isanetworkerror {
if [[ $? != 0 ]];then
fatalerror "$(T "Network connection error, please check it")"
fi
}
function particiones {
clear
mostrardialog "$(T "Questions about partitions where system will be installed")" "$(T "Questions about partitions dialog. Text")"
clear
if [[ ! $(lsblk --output KNAME | cut -c1-3 | sort | uniq | sed '1d' | grep 'sd\|hd') ]];then
mostrardialog "ERROR" "$(T "ERROR: You dont have HDD, insert one, poweroff")"
reboot
fi
optpa=`dialog --stdout --nocancel --menu "$(T "¿Do you want to edit partitions?¿How?")" 0 0 5 1 "Grafico con Gparted (Recomendado)" 2 "Terminal (Pequeño asistente o por tu cuenta)" 3 "Borrar un disco duro e instalar JKArch en el (usar con cuidado!)" 4 "No editar nada"`
case $optpa in
1)
#Abrir gparted grafico
mostrardialog "Gparted" "$(T "Gparted will be opened. Help text")"
startx;;
2)
#Terminal
echo $(T "Select hard disk to edit")
echo "AVISO, GPT/UEFI ES EXPERMIENTAL, FALTA PROBARLO MAS, PUEDES QUEDARTE SIN ARRANQUE"
lsblk --output NAME,KNAME,FSTYPE,SIZE,LABEL
options=($(lsblk --output KNAME | cut -c1-3 | sort | uniq | sed '1d' | grep 'sd\|hd') "No editar" "Terminal")
select opt in "${options[@]}"
do
case $opt in
"Terminal")
echo "Haga los cambios pertinentes, asegurese, y escriba exit continuar la instalación"
bash
break;;
"No editar") break;;
*) cfdisk /dev/$opt;break;;
esac
done
;;
3)
mostrardialog "$(T "Full hard disk install")" "$(T "Full hard disk install. Text")"
clear
tput setaf 6 ; echo "$(T "Your partition scheme")" ; tput setaf 9
lsblk --output NAME,KNAME,FSTYPE,SIZE,LABEL
tput setaf 6 ; echo "$(T "Select hard disk to delete and use by JKArch")" ; tput setaf 9
options=($(lsblk --output KNAME | cut -c1-3 | sort | uniq | sed '1d' | grep 'sd\|hd') "$(T "Exit")")
select opt in "${options[@]}"
do
case $opt in
"$(T "Exit")")
mostrardialog "Instalacion detenida" "Se detuvo la instalacion. No se hicieron cambios. Al aceptar, reiniciara la instalacion"
exec ./selectlang.sh
;;
*)
if [[ -z $opt ]];then
echo "$(T "Not valid")"
else
optseg=`dialog --stdout --nocancel --menu "¿Estas seguro de borrar todo /dev/$opt y meter JKArch aqui? No es reversible" 0 0 4 1 "No" 2 "No" 3 "Si, estoy seguro" 4 "No"`
case $optseg in
3)
echo -e "o\nn\np\n1\n\n\nw\n" | fdisk /dev/$opt
particionraiz=${opt}1
formatoraiz="mkfs.ext4 -F"
ram=$(free -m | grep Mem: | awk '1 {print $2 }')
if [[ $ram -le 7500 ]];then
swaptype=1
swapamount=$(expr $ram / 3)
if [[ $ram -le 3700 ]];then
swapamount=$(expr $swapamount \* 2)
fi
if [[ $ram -le 1500 ]];then
swapamount=$(expr $swapamount \* 2)
fi
if [[ $ram -le 700 ]];then
swapamount=$(expr $swapamount \* 2)
fi
fi
break;;
*)
mostrardialog "Instalacion detenida" "Se detuvo la instalacion. No se hicieron cambios. Al aceptar, se apagara el ordenador"
poweroff;;
esac
fi;;
esac
done
;;
esac
clear
# Solo pedir datos si no esta en modo automatico, evidentemente.
if [[ ! $optpa -eq 3 ]];then
tput setaf 6 ; echo "$(T "Your partition scheme")" ; tput setaf 9
lsblk --output NAME,KNAME,FSTYPE,SIZE,LABEL
tput setaf 6 ; echo "Selecciona disco duro a utilizar para seleccionar las particiones" ; tput setaf 9
options=($(lsblk --output KNAME | cut -c1-3 | sort | uniq | sed '1d' | grep 'sd\|hd'))
select opt in "${options[@]}"
do
case $opt in
*)
if [[ -z $opt ]];then
echo "$(T "Not valid")"
else
hd=$opt
break
fi;;
esac
done
#Detectar tipo de tabla de particiones (gpt o msdos) y si es gpt, preparar para UEFI
tabletype="$(parted /dev/${hd} p | grep "Partition Table" | awk '1 {print $3}')"
if [[ $tabletype = "gpt" ]];then
mostrardialog "$(T "GPT Partition Table")" "$(T "You are using GPT, you will have to select EFI")"
fi
clear
tput setaf 6 ; echo "$(T "Your partition scheme")" ; tput setaf 9
lsblk --output NAME,KNAME,FSTYPE,SIZE,LABEL
tput setaf 6 ; echo "$(T "Select root ('/') partition")" ; tput setaf 9
options=($(lsblk --output KNAME | sed '1d' | grep ${hd} | grep '[1-9]$'))
select opt in "${options[@]}"
do
case $opt in
*)
if [[ -z $opt ]];then
echo "$(T "Not valid")"
else
particionraiz=$opt
break
fi;;
esac
done
optfr=`dialog --stdout --nocancel --menu "Formato para la particion raiz(/)" 0 0 4 1 "EXT4 (Recomendado)" 2 "BTRFS" 3 "XFS" 4 "No formatear (Si ya esta formateada)"`
case $optfr in
1) formatoraiz="mkfs.ext4 -F";;
2) formatoraiz="mkfs.btrfs -f";;
3) formatoraiz="mkfs.xfs -f";;
4) formatoraiz="echo No formatear ";;
esac
clear
opthpart=`dialog --stdout --nocancel --menu "¿Quieres separar la particion /home de /?" 0 0 4 1 "No (Por defecto)" 2 "Si (Tendras que elegir la particion)"`
case $opthpart in
2)
#Selección de home
lsblk --output NAME,KNAME,FSTYPE,SIZE,LABEL
tput setaf 6 ; echo "$(T "Select home partition")" ; tput setaf 9
options=($(lsblk --output KNAME | sed '1d' | grep ${hd} | grep '[1-9]$') "$(T "Not select")")
select opt in "${options[@]}"
do
case $opt in
"$(T "Not select")")
break;;
*)
if [[ -z $opt ]];then
echo "$(T "Not valid")"
else
particionhome=$opt
break
fi;;
esac
done
if [[ $particionhome ]];then
optfh=`dialog --stdout --nocancel --menu "Formato para la particion home (/home)" 0 0 4 1 "EXT4 (Recomendado)" 2 "BTRFS" 3 "XFS" 4 "No formatear (Si ya esta formateada)"`
case $optfh in
1)
formatohome="mkfs.ext4 -F";;
2)
formatohome="mkfs.btrfs -f";;
3)
formatohome="mkfs.xfs -f";;
4)
formatohome="echo No formatear ";;
esac
fi
;;
esac
if [[ $formatoraiz -eq "mkfs.btrfs -f" ]];then
mostrardialog "No swapfile" "Es contraproducente hacer un fichero swap en una particion btrfs, no debes hacerlo, pero si antes creaste una particion swap, se puede utilizar"
fi
ram=$(free -m | grep Mem: | awk '1 {print $2 }')
optswap=`dialog --stdout --nocancel --menu "¿Quieres crear un archivo swap (Memoria virtual)?" 0 0 4 1 "Si (Con valores por defecto, recomendado)" 2 "Si (Valores a mano)" 3 "Si, pero con una particion que ya cree" 4 "No"`
case $optswap in
1)
if [[ $ram -le 7500 ]];then
swaptype=1
swapamount=$(expr $ram / 3)
if [[ $ram -le 3700 ]];then
swapamount=$(expr $swapamount \* 2)
fi
if [[ $ram -le 1500 ]];then
swapamount=$(expr $swapamount \* 2)
fi
if [[ $ram -le 700 ]];then
swapamount=$(expr $swapamount \* 2)
fi
else
#No es que sea necesario, pero como ha pulsado en si, se crea un archivo minimo"
swaptype=1
swapamount="512"
fi
;;
2) swapamount=`dialog --stdout --inputbox "RAM: $(echo $ram) . $(T "Enter how much memory you want to use for swap (MB)")" 9 50`;;
3) mostrardialog "Swap" "$(T "JKArch autodetects swap partitions")";;
esac
clear
if [[ $tabletype = "gpt" ]];then
lsblk --output NAME,KNAME,FSTYPE,SIZE,LABEL
tput setaf 6 ; echo "$(T "Select EFI partition")" ; tput setaf 9
options=($(lsblk --output KNAME | sed '1d' | grep 'sd\|hd' | grep '[1-9]$'))
select opt in "${options[@]}"
do
case $opt in
*)
if [[ -z $opt ]];then
echo "$(T "Not valid")"
else
partefi=$opt
break
fi;;
esac
done
fi
fi
#fin del if de pedir los datos si no esta en automatico
}
function install {
clear
tput setaf 2 ; echo "$(T "Installing system, this can take about 10 minutes, wait")" ; tput setaf 9
sleep 2
tput setaf 2 ; echo "$(T "Formatting and mounting partitions")" ; tput setaf 9
$formatoraiz /dev/$particionraiz
e2label /dev/$particionraiz "JKArch"
mount /dev/$particionraiz /mnt/
if [[ $particionhome ]];then
$formatohome /dev/$particionhome
mkdir -p /mnt/home/
mount /dev/$particionhome /mnt/home/
fi
if [[ $partefi ]];then
mkdir -p /mnt/boot/efi
mount /dev/$partefi /mnt/boot/efi/
fi
if [[ $isoffline = "0" ]];then
wget -nv https://gitlab.com/JKANetwork/JKArch/raw/master/archinstall/pacman.conf -O /tmp/pacman.conf
isanetworkerror #Comprueba si hubo un error de descarga
tput setaf 2 ; echo "$(T "Optimizing download")" ; tput setaf 9
reflector --verbose -l 6 --sort rate --save /etc/pacman.d/mirrorlist
tput setaf 2 ; echo "$(T "Downloading")" ; tput setaf 9
pacstrap -C /tmp/pacman.conf /mnt/ base btrfs-progs jkarch-mirrorlist
fi
if [[ $isoffline = "1" ]];then
tput setaf 2 ; echo "$(T "Installing packages")..." ; tput setaf 9
pacstrap -C /root/offlinefiles/pacman-offline.conf /mnt/ base btrfs-progs jkarch-mirrorlist
mv pacman.conf /mnt/etc/pacman.conf.post #Move pacman.conf ("original online") to a chroot location
mv pacman-offline.conf /mnt/etc/pacman.conf #Move pacman.conf (offline) to pacman chroot location
fi
#Create fstab
genfstab -U /mnt >> /mnt/etc/fstab
#Create or activate swap if neccesary
if [[ $swaptype ]];then
case $swaptype in
1)
echo "$(T "Creating swap file")"
dd if=/dev/zero of=/mnt/swapfile bs=1M count=$swapamount
chmod 600 /mnt/swapfile
mkswap /mnt/swapfile
echo "/swapfile none swap defaults 0 0" >> /mnt/etc/fstab
;;
esac
fi
mkdir -p /mnt/root/inst/
if [[ $isoffline = 0 ]];then
wget -nv https://gitlab.com/JKANetwork/JKArch/raw/master/archinstall/chrootinstall.sh -O /mnt/root/inst/chrootinstall.sh
isanetworkerror
cp -r /etc/netctl/* /mnt/etc/netctl/
else # Its offline
mv chrootinstall.sh /mnt/root/inst/chrootinstall.sh
ln -s /root/offlinefiles/ /run/archiso/offlinefiles #Crear link para resto de la instalacion
fi
chmod +x /mnt/root/inst/chrootinstall.sh
cp translations.sh /mnt/root/inst/translations.sh
arch-chroot /mnt /bin/bash -c "./root/inst/chrootinstall.sh $sclang $particionraiz $partefi"
}
clear
mostrardialog "$(T "JKArch install script")" "$(T "Intro arch install script")"
mostrardialog "JKArch" "El script esta en estado beta y se esta actualizando casi constantemente. Puede haber fallos importantes. En caso de fallo, vuelva a probar en unas horas"
echo "Desmontando posibles particiones"
umount /mnt/boot/efi/
umount /mnt/*
umount /mnt/
particiones
clear
tput setaf 6
echo "$(T "Ok, last thing before start installing, summary of changes")"
echo "$(T "Partition scheme before your changes")"
tput setaf 9
lsblk --output NAME,KNAME,FSTYPE,SIZE,LABEL
tput setaf 6
echo "$(T "Your changes")"
tput setaf 9
case $formatoraiz in
"mkfs.ext4 -F")
mosfraiz="$(T "ext4 formatted")";;
"mkfs.btrfs -f")
mosfraiz="$(T "btrfs formatted")";;
"mkfs.xfs -f")
mosfraiz="$(T "XFS formatted")";;
"echo No formatear ")
mosfraiz="$(T "not formatted")";;
esac
echo "$(T "Root partition"): $particionraiz , $mosfraiz"
if [[ $particionhome ]];then
case $formatohome in
"mkfs.ext4 -F")
mosfhome="$(T "ext4 formatted")";;
"mkfs.btrfs -f")
mosfhome="$(T "btrfs formatted")";;
"mkfs.xfs -f")
mosfhome="$(T "XFS formatted")";;
"echo No formatear ")
mosfhome="$(T "not formatted")";;
esac
echo "$(T "Home partition"): $particionhome , $mosfhome"
fi
if [[ $partefi ]];then
echo "$(T "EFI partition in") $partefi"
fi
tput setaf 1 ; echo "$(T "If you agree with that, press enter. If not, turn off the computer")" ; tput setaf 9
pause
install
clear
mostrardialog "$(T "End")" "$(T "Setup finished, press enter to reboot.")"
rm -rf /mnt/root/inst
reboot