Skip to content

Instantly share code, notes, and snippets.

@Mukundan314
Created January 18, 2020 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mukundan314/8bfa623bd5128e567baf5ef3c1039fc0 to your computer and use it in GitHub Desktop.
Save Mukundan314/8bfa623bd5128e567baf5ef3c1039fc0 to your computer and use it in GitHub Desktop.
#!/bin/bash
all_devices=($(ls /sys/block/))
usb_devices=()
for device in "${all_devices[@]}"
do
if readlink -f "/sys/block/$device/device" | grep -q "usb"
then
usb_devices+=($device)
fi
done
choices_list="usb"
choices=${usb_devices[@]}
while [ -z "$chosen_device" ]
do
printf "\n"
for i in "${!choices[@]}"
do
printf " $((i+1))) ${choices[$i]} (%s)\n" $(lsblk -n --output SIZE -d /dev/${choices[$i]})
done
if [ $choices_list == "all" ]
then
printf " u) Show Usb Devices only\n"
else
printf " a) Show all devices\n"
fi
printf " c) Cancel\n"
printf "\n"
while true
do
printf "Choose device to flash feodra on (enter s to show options): "
read -r
if [ $REPLY -gt 0 ] 2>/dev/null && [ $REPLY -le ${#choices[@]} ] 2>/dev/null
then
chosen_device=${choices[$((REPLY - 1))]}
break
elif [ "$REPLY" == "a" ]
then
choices_list="all"
choices=(${all_devices[@]})
break
elif [ "$REPLY" == "u" ]
then
choices_list="usb"
choices=(${usb_devices[@]})
break
elif [ "$REPLY" == "s" ]
then
break
elif [ "$REPLY" == "c" ]
then
exit
fi
done
done
declare -A checksums urls
spins=(Cinnamon KDE LXDE LXQt MATE_Compiz SoaS Xfce Workstation)
urls[Cinnamon]="https://download.fedoraproject.org/pub/fedora/linux/releases/31/Spins/x86_64/iso/Fedora-Cinnamon-Live-x86_64-31-1.9.iso"
urls[KDE]="https://download.fedoraproject.org/pub/fedora/linux/releases/31/Spins/x86_64/iso/Fedora-KDE-Live-x86_64-31-1.9.iso"
urls[LXDE]="https://download.fedoraproject.org/pub/fedora/linux/releases/31/Spins/x86_64/iso/Fedora-LXDE-Live-x86_64-31-1.9.iso"
urls[LXQt]="https://download.fedoraproject.org/pub/fedora/linux/releases/31/Spins/x86_64/iso/Fedora-LXQt-Live-x86_64-31-1.9.iso"
urls[MATE_Compiz]="https://download.fedoraproject.org/pub/fedora/linux/releases/31/Spins/x86_64/iso/Fedora-MATE_Compiz-Live-x86_64-31-1.9.iso"
urls[SoaS]="https://download.fedoraproject.org/pub/fedora/linux/releases/31/Spins/x86_64/iso/Fedora-SoaS-Live-x86_64-31-1.9.iso"
urls[Xfce]="https://download.fedoraproject.org/pub/fedora/linux/releases/31/Spins/x86_64/iso/Fedora-Xfce-Live-x86_64-31-1.9.iso"
urls[Workstation]="https://download.fedoraproject.org/pub/fedora/linux/releases/31/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-31-1.9.iso"
checksums[Cinnamon]="e3922da372153fb008a83bd49dd5aa88db6d5b38f692cece186b031d0a2c3163"
checksums[KDE]="b3a69e365815531cd3d4439f099749949eb8a60444ec9b743f2c264232f1c519"
checksums[LXDE]="b601a424137d736760dedf1a2c0f56904e6b5402a2f381bbd7e2fe18afe61e33"
checksums[LXQt]="752a444d2be937c37e9586b5e93ddafe76ce87de4c3146793bf07fa0a23561fe"
checksums[MATE_Compiz]="8a5f6c7cfad2e632bee710f8bd5daf90babe5880f9da7d209464d055fcead50d"
checksums[SoaS]="f154dcf421a5a00f392e09f9f396798fc99760d7e78d5ee775186c6e9c137d71"
checksums[Xfce]="e2b05ee78dc5e4c39258d2d068a5c891366de02440ebcd7bcedf1fa31d15354e"
checksums[Workstation]="1d73ce30bfb96274c53b09013ea23320f0f64a1b0c663217110a5baf0b2c6528"
while [ -z "$chosen_spin" ]
do
printf "\n"
for i in "${!spins[@]}"
do
printf " $((i+1))) ${spins[$i]}\n"
done
printf " c) Cancel\n"
printf "\n"
while true
do
printf "Choose the fedora spin to flash on the device (enter s to show options): "
read -r
if [ $REPLY -gt 0 ] 2>/dev/null && [ $REPLY -le ${#spins[@]} ] 2>/dev/null
then
chosen_spin=${spins[$((REPLY - 1))]}
break
elif [ "$REPLY" == "s" ]
then
break
elif [ "$REPLY" == "c" ]
then
exit
fi
done
done
mkdir -p ~/Downloads
while true
do
curl -L ${urls[$chosen_spin]} -o ~/Downloads/fedora.iso
if ! sha256sum -c <<< "${checksums[$chosen_spin]} $HOME/Downloads/fedora.iso" &>/dev/null
then
printf "Checksums do not match redownload? [Y/n/q]: "
read -r
if [ "${REPLY,,}" == "n" ]
then
break
elif [ "${REPLY,,}" == "q" ]
then
exit
fi
else
break
fi
done
while true
do
printf "Start flashing iso onto disk (will erase all data on disk)? [Y/n] "
read -r
if [ "$REPLY" == "" ] || [ "${REPLY,,}" == "y" ]
then
break
elif [ "${REPLY,,}" == "n" ]
then
exit
fi
done
sudo dd if=~/Downloads/fedora.iso of=/dev/$chosen_device bs=8M status=progress oflag=direct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment