Created
May 31, 2023 19:56
-
-
Save carlos-a-g-h/599f14734af32e6d27328455382b798b to your computer and use it in GitHub Desktop.
Script for mounting Debian DVDs and adding them to /etc/sources.list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DVDs_DIRPATH="$1" | |
DVDs_PATTERN="$2" | |
TOTAL=$(ls "$DVDs_DIRPATH"|grep "$DVDs_PATTERN"|grep ".iso$"|wc -l) | |
INDEX=0 | |
INDEX_MAX=$(expr $TOTAL + 1) | |
sed -i 's/^deb/# deb/' "$PATH_APT_SRC" | |
while [ $INDEX -lt $INDEX_MAX ] | |
do | |
INDEX=$(expr $INDEX + 1) | |
ISO_FILENAME=$(ls "$DVDs_DIRPATH"|grep "$DVDs_PATTERN"|grep ".iso$"|head -n$INDEX|tail -n1) | |
ISO_FILEPATH="$DVDs_DIRPATH/$ISO_FILENAME" | |
MPATH="/dvd$INDEX" | |
mkdir -p "$MPATH" | |
printf "\n$ISO_FILENAME\n[!] Checking $MPATH ...\n" | |
mountpoint "$MPATH" | |
if [ $? -eq 0 ] | |
then | |
continue | |
fi | |
echo "[!] Mounting $ISO_FILEPATH to $MPATH ..." | |
mount -ro loop "$ISO_FILEPATH" "$MPATH" | |
if ! [ $? -eq 0 ] | |
then | |
continue | |
fi | |
echo "deb [trusted=yes] file://$MPATH bullseye main contrib" >> "$PATH_APT_SRC" | |
if ! [ $? -eq 0 ] | |
then | |
continue | |
fi | |
echo "[!] Added $MPATH to $PATH_APT_SRC" | |
done | |
printf "\n[!] Updating ...\n" | |
apt update |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment