Skip to content

Instantly share code, notes, and snippets.

@benjaoming
Created July 19, 2019 23:17
Show Gist options
  • Save benjaoming/28b8ddc9f0ee6ef74d113625bd667d90 to your computer and use it in GitHub Desktop.
Save benjaoming/28b8ddc9f0ee6ef74d113625bd667d90 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Fixes a downloaded apt mirror
# See: https://github.com/apt-mirror/apt-mirror/issues/113#issuecomment-464932493
## first parameter is optional mirror list file
if [ "$1" != "" ]
then
mirrorlist=$1
else
mirrorlist="/etc/apt/mirror.list"
fi
dataFolder=$(grep -F "set base_path" $mirrorlist | tr -s " " | cut -d' ' -f4)
if [ "$dataFolder" == "" ]
then
dataFolder=/var/spool/apt-mirror
fi
# combined solutions for apt mirror from: https://github.com/apt-mirror/apt-mirror/issues/49,https://github.com/apt-mirror/apt-mirror/issues/102
# I had to create this file, in order to solve the issue of not downloading DEP-11 @2 files
# so all what I'm doing is running apt mirror manually, then downloading the other icon files every time
# Grep will grep the line starting with "set base_path"
# then we trim all extra white spaces
# then we cut the string by delimiter white space and take third value
echo "Base Folder path set in /etc/apt/mirror.list is: $dataFolder"
apt-mirror
echo
echo -n "Do you want to Check MD5 Sum and Download Failed (auto Y in 5 seconds)? [Y/n]"
echo
read -t 5 answer
exit_status=$?
if [ $exit_status -ne 0 ] || [ "$answer" == "" ] || [ "$answer" != "${answer#[Yy]}" ];then
FAILEDPACKAGES=""
echo "Reading and Checking MD5 checksum using file: $dataFolder/var/MD5"
#cd $dataFolder/mirror
rm -f FAILED_MD5.txt
echo "Failed File will be stored in: $(PWD)/FAILED_MD5.txt"
while IFS='' read -r line || [[ -n "$line" ]]; do
#echo "Checking: $line"
sum=$(echo $line | cut -d' ' -f1)
filename=$(echo $line | cut -d' ' -f2)
echo "$sum $dataFolder/mirror/$filename" | md5sum -c -
RESULT=$?
if [ $RESULT -ne 0 ];then
echo "$dataFolder/mirror/$filename" >> FAILED_MD5.txt
wget -O $dataFolder/mirror/$filename $filename
echo "$sum $dataFolder/mirror/$filename" | md5sum -c -
SUBRESULT=$?
if [ $SUBRESULT -ne 0 ];then
echo "Sorry failed checksum again for file: $dataFolder/mirror/$filename"
$FAILEDPACKAGES+="$dataFolder/mirror/$filename Failed again, sorry cannot help"
fi
fi
done < "$dataFolder/var/MD5"
#md5sum -c $dataFolder/var/MD5 | grep --line-buffered -i "FAILED" | tee FAILED_MD5.txt
echo $FAILEDPACKAGES
else
echo "ok I will not check MD5"
fi
echo -n "Do you want Download DEP-11 @ 2 icons (auto Y in 5 seconds)? [Y/n]"
echo
read -t 5 answer
exit_status=$?
ubuserv=$(grep -m1 ubuntu.com /etc/apt/mirror.list |awk '{print $2}' |cut -d '/' -f3)
if [ "$answer" != "${answer#[Yy]}" ] || [ "$answer" == "" ] || [ $exit_status -ne 0 ] ;then
cd $dataFolder/mirror/${ubuserv}/ubuntu/dists
downloadRoot="$dataFolder/mirror/${ubuserv}/ubuntu/dists"
echo "Downloading fixes to $downloadRoot"
cd $downloadRoot
for dist in *; do
dist=$(basename $dist)
for comp in main multiverse universe; do
mkdir -p ${dist}/${comp}/dep11
for size in 48 64 128; do
wget http://${ubuserv}/ubuntu/dists/${dist}/${comp}/dep11/icons-${size}x${size}@2.tar.gz -O ${dist}/${comp}/dep11/icons-${size}x${size}@2.tar.gz;
done
done
done
else
echo "ok no downloading for icons"
fi
echo -n "Do you want to run Clean Script (auto Y in 5 seconds)? [Y/n]"
echo
read -t 5 answer
exit_status=$?
if [ "$answer" != "${answer#[Yy]}" ] || [ "$answer" == "" ] || [ $exit_status -ne 0 ] ;then
$dataFolder/var/clean.sh
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment