A tool for updating OS packages from an external drive or an .iso file with apt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.6 KiB

#!/bin/bash
tryUpdateFromSd()
{
local sd_name=$1
# cut received line by / and take the third found result. (for /dev/sdb1 it's sdb1)
local sd_folder_name=$(echo "${sd_name}" | cut -f 3 -d '/')
exit_condition=false
while [ "$exit_condition" == false ]
do
echo "Do you want to update ${sd_name}? (Y/n)"
read input_char
if [ "$input_char" == "y" ] || [ "$input_char" == "Y" ]
then
echo " - Create folder /media/iso-$sd_folder_name"
mkdir /media/iso-$sd_folder_name
echo " - Mount ${sd_name} into /media/iso-$sd_folder_name"
mount $sd_name /media/iso-$sd_folder_name
echo " - Update the package manager."
cp /etc/apt/sources.list /etc/apt/sources-backup.list
mkdir /home/temp-apt
mv /etc/apt/sources.list.d/* /home/temp-apt/
echo "deb [trusted=yes] file:/media/iso-$sd_folder_name orel main contrib" > /etc/apt/sources.list
echo " - Update packages."
apt update
apt upgrade
echo " - Unmount ${sd_name}"
umount /media/iso-$sd_folder_name
rm -rf /media/iso-$sd_folder_name
echo " - Restore the package manager."
mv /etc/apt/sources-backup.list /etc/apt/sources.list
mv /home/temp-apt/* /etc/apt/sources.list.d/
rm -rf /home/temp-apt/
exit_condition=true
elif [ "$input_char" == "n" ] || [ "$input_char" == "N" ]
then
echo "Skip "${sd_name}""
exit_condition=true
else
echo "Please input Y or y to agree and N or n to decline."
echo "To close the application please input Ctrl+C."
fi
done
}
############################################ MAIN ############################################
if [[ $UID != 0 ]]; then
echo "Please run the application from sudo:"
echo "sudo $0 $*"
exit 1
fi
echo "Preparing to update the Operational System."
# Show devices with fdisk -l
# Filter all lines which contain "sd*" (where * -- any latin letter from B to Z) except for "sd*:"
# cut by space character and take the first found result
# so it is: /dev/sdb1 , for example
sd_arr_raw=$(fdisk -l | egrep "sd[b-zB-Z][^:]" | cut -f 1 -d ' ')
amount_of_sd=0
for sd_raw in $sd_arr_raw
do
amount_of_sd=$(($amount_of_sd+1))
echo "${sd_raw}; ID=${amount_of_sd}"
done
if (( $amount_of_sd < 1 ))
then
echo "Available external devices weren't detected. Please make sure they are connected."
else
for sd_raw in $sd_arr_raw
do
tryUpdateFromSd "${sd_raw}"
done
fi