AN00BIS
/dev/comfy
Postet hier hilfreiche Skripte, welche den GNU/Linux Alltag erleichtern
Natürlich können auch Projekte gepostet werden, an welchen ihr gerade Arbeitet, oder bei denen ihr Hilfe benötigt.
--- [2016-07-11 09:59 CEST] Automatisch zusammengeführter Beitrag ---
Ich arbeite zurzeit an einem Bash Skript zur Installation von Arch Linux, da Arch über keinen Installationsmanager verfügt und ich mich mit Bash ein wenig auseinandersetzen wollte.
Der Code sieht wie folgt aus:
[src=bash]#!/bin/bash
function pause(){
read -p "$*" #pause
}
function step(){
echo " " #make the script look less ugly
}
function yesno(){
response=$?
case $response in
0) #yes
;;
1) #no
exit;;
255) #esc key
exit
esac
}
###### partition names ######
name[1]="boot"
name[2]="root"
name[3]="swap"
B[1]="MiB"
B[2]="GiB"
B[3]="GiB"
B[4]="GiB"
x="/dev/sda"
i=1 #counter
#pacman -Sy dialog #enable if dialog is not already installed in the live-version
loadkeys de_CH-latin1 #swiss layout
clear
#search for disks in /dev/sd*
for i in {1..6}
do
disc[$i]=$(ls $x)
clear
if [[ $x == '/dev/sda' ]]
then
x="/dev/sdb"
elif [[ $x == '/dev/sdb' ]]
then
x="/dev/sdc"
elif [[ $x == '/dev/sdc' ]]
then
x="/dev/sdd"
elif [[ $x == '/dev/sdd' ]]
then
x="/dev/sdx"
fi
done
echo "########## Arch Installation Script ##########"
step
echo "Welcome to the installation of arch linux"
step
pause "Press [Enter] to start..."
step
echo "discs:"
step
lsblk #list all discs
pause "Choose the disc where arch should be installed and press [Enter]..."
exec 3>&1
select_disc=$(dialog --title "Select disc" \
--radiolist "select disc where arch should be installed" \
30 50 10 \
"${disc[1]}" "" "" \
"${disc[2]}" "" "" \
"${disc[3]}" "" "" \
"${disc[4]}" "" "" \
"${disc[5]}" "" "" \
"${disc[6]}" "" "" \
3>&1 1>&2 2>&3 3>&- ) #gets all discs at /dev/sd.. and saves the chosen disc as $select_disc
yesno
clear
dialog --title "Warning" \
--yesno "This will erase all data on the disc. Are you sure?" \
10 40
yesno
exec 3>&1
i=1
while [ $i -le 3 ]
do
size[$i]=$(dialog --title ${name[$i]} \
--inputbox "Select the size of the ${name[$i]} partition ( ${B[$i]} )" \
10 40 "" \
3>&1 1>&2 2>&3 3>&- ) #set the disc sizes
echo ${size[$i]}
yesno
i=$(( $i + 1 ))
done
size_area[1]=$(( ${size[1]} / 1000 ))
size_area[2]=$(( ${size_area[1]} + ${size[2]} ))
size_area[3]=$(( ${size_area[2]} + ${size[3]} ))
parted $select_disc mklabel msdos;
parted $select_disc mkpart primary ext4 1MiB ${size[1]}MiB;
parted $select_disc set 1 boot on;
parted $select_disc mkpart primary ext4 ${size[1]}MiB ${size_area[2]}GiB;
parted $select_disc mkpart primary linux-swap ${size_area[2]}GiB ${size_area[3]}GiB;
parted $select_disc mkpart primary ext4 ${size_area[3]}GiB 100%;
fdisk -l
pause
mkfs.ext4 "${select_disc}1"
mkfs.ext4 "${select_disc}2"
mkswap "${select_disc}3"
mkfs.ext4 "${select_disc}4"
swapon "${select_disc}3"
mount "${select_disc}2" /mnt
mkdir -p /mnt/boot
mkdir -p /mnt/home
mount "${select_disc}1" /boot
mount "${select_disc}4" /home
pacstrap -i /mnt base base-devel
genfstab -U /mnt > /mnt/etc/fstab
echo "select_disc=${select_disc}" > selected_disc.txt
mv selected_disc.txt /mnt/temp/
## create a bash script with the second part of the installation in the chroot ##
echo '
#!/bin/bash
function pause(){
read -p "$*" #pause
}
function step(){
echo " " #make the script look less ugly
}
select_disc=$(cat "/temp/selected_disc.txt")
echo "${select_disc}"
pause "You are in the installed System now. Press [Enter]"
vi /etc/locale.gen
locale-gen
pause "Press [Enter]"
ln -sf /usr/share/zoneinfo/CET /etc/localtime #change time to CET
date
pause "check date"
pacman -S --noconfirm grub os-prober
pacman -S --noconfirm dialog
pacman -S --noconfirm networkmanager
pacman -S --noconfirm gnome-keyring
pacman -Syu --noconfirm
grub-install --recheck "${select_disc}"
pause "check 1"
grub-mkconfig -o /boot/grub/grub.cfg
pause "check 2"
systemctl enable dhcpcd
pause "check 3"
exit
' > chroot.sh
mv chroot.sh /mnt/bin/
chmod +x /mnt/bin/chroot.sh
arch-chroot /mnt /bin/chroot.sh #chroot into the installed system and run the second script
[/src]
Leider funktioniert das Skript noch nicht und der Code ist vermutlich auch nicht besonders gut. Deshalb bin ich froh um Verbesserungsvorschläge und sonstige Tipps
Natürlich können auch Projekte gepostet werden, an welchen ihr gerade Arbeitet, oder bei denen ihr Hilfe benötigt.
--- [2016-07-11 09:59 CEST] Automatisch zusammengeführter Beitrag ---
Ich arbeite zurzeit an einem Bash Skript zur Installation von Arch Linux, da Arch über keinen Installationsmanager verfügt und ich mich mit Bash ein wenig auseinandersetzen wollte.
Der Code sieht wie folgt aus:
[src=bash]#!/bin/bash
function pause(){
read -p "$*" #pause
}
function step(){
echo " " #make the script look less ugly
}
function yesno(){
response=$?
case $response in
0) #yes
;;
1) #no
exit;;
255) #esc key
exit
esac
}
###### partition names ######
name[1]="boot"
name[2]="root"
name[3]="swap"
B[1]="MiB"
B[2]="GiB"
B[3]="GiB"
B[4]="GiB"
x="/dev/sda"
i=1 #counter
#pacman -Sy dialog #enable if dialog is not already installed in the live-version
loadkeys de_CH-latin1 #swiss layout
clear
#search for disks in /dev/sd*
for i in {1..6}
do
disc[$i]=$(ls $x)
clear
if [[ $x == '/dev/sda' ]]
then
x="/dev/sdb"
elif [[ $x == '/dev/sdb' ]]
then
x="/dev/sdc"
elif [[ $x == '/dev/sdc' ]]
then
x="/dev/sdd"
elif [[ $x == '/dev/sdd' ]]
then
x="/dev/sdx"
fi
done
echo "########## Arch Installation Script ##########"
step
echo "Welcome to the installation of arch linux"
step
pause "Press [Enter] to start..."
step
echo "discs:"
step
lsblk #list all discs
pause "Choose the disc where arch should be installed and press [Enter]..."
exec 3>&1
select_disc=$(dialog --title "Select disc" \
--radiolist "select disc where arch should be installed" \
30 50 10 \
"${disc[1]}" "" "" \
"${disc[2]}" "" "" \
"${disc[3]}" "" "" \
"${disc[4]}" "" "" \
"${disc[5]}" "" "" \
"${disc[6]}" "" "" \
3>&1 1>&2 2>&3 3>&- ) #gets all discs at /dev/sd.. and saves the chosen disc as $select_disc
yesno
clear
dialog --title "Warning" \
--yesno "This will erase all data on the disc. Are you sure?" \
10 40
yesno
exec 3>&1
i=1
while [ $i -le 3 ]
do
size[$i]=$(dialog --title ${name[$i]} \
--inputbox "Select the size of the ${name[$i]} partition ( ${B[$i]} )" \
10 40 "" \
3>&1 1>&2 2>&3 3>&- ) #set the disc sizes
echo ${size[$i]}
yesno
i=$(( $i + 1 ))
done
size_area[1]=$(( ${size[1]} / 1000 ))
size_area[2]=$(( ${size_area[1]} + ${size[2]} ))
size_area[3]=$(( ${size_area[2]} + ${size[3]} ))
parted $select_disc mklabel msdos;
parted $select_disc mkpart primary ext4 1MiB ${size[1]}MiB;
parted $select_disc set 1 boot on;
parted $select_disc mkpart primary ext4 ${size[1]}MiB ${size_area[2]}GiB;
parted $select_disc mkpart primary linux-swap ${size_area[2]}GiB ${size_area[3]}GiB;
parted $select_disc mkpart primary ext4 ${size_area[3]}GiB 100%;
fdisk -l
pause
mkfs.ext4 "${select_disc}1"
mkfs.ext4 "${select_disc}2"
mkswap "${select_disc}3"
mkfs.ext4 "${select_disc}4"
swapon "${select_disc}3"
mount "${select_disc}2" /mnt
mkdir -p /mnt/boot
mkdir -p /mnt/home
mount "${select_disc}1" /boot
mount "${select_disc}4" /home
pacstrap -i /mnt base base-devel
genfstab -U /mnt > /mnt/etc/fstab
echo "select_disc=${select_disc}" > selected_disc.txt
mv selected_disc.txt /mnt/temp/
## create a bash script with the second part of the installation in the chroot ##
echo '
#!/bin/bash
function pause(){
read -p "$*" #pause
}
function step(){
echo " " #make the script look less ugly
}
select_disc=$(cat "/temp/selected_disc.txt")
echo "${select_disc}"
pause "You are in the installed System now. Press [Enter]"
vi /etc/locale.gen
locale-gen
pause "Press [Enter]"
ln -sf /usr/share/zoneinfo/CET /etc/localtime #change time to CET
date
pause "check date"
pacman -S --noconfirm grub os-prober
pacman -S --noconfirm dialog
pacman -S --noconfirm networkmanager
pacman -S --noconfirm gnome-keyring
pacman -Syu --noconfirm
grub-install --recheck "${select_disc}"
pause "check 1"
grub-mkconfig -o /boot/grub/grub.cfg
pause "check 2"
systemctl enable dhcpcd
pause "check 3"
exit
' > chroot.sh
mv chroot.sh /mnt/bin/
chmod +x /mnt/bin/chroot.sh
arch-chroot /mnt /bin/chroot.sh #chroot into the installed system and run the second script
[/src]
Leider funktioniert das Skript noch nicht und der Code ist vermutlich auch nicht besonders gut. Deshalb bin ich froh um Verbesserungsvorschläge und sonstige Tipps
Zuletzt bearbeitet: