-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathenable_kernel_sources.sh
72 lines (59 loc) · 1.52 KB
/
enable_kernel_sources.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#
# Script to enable the Debian sources for kernel
#
# Ensure we only use safe paths
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
function update_apt_listfile {
local found=0
local apt_list=""
if [ -z "$@" ]
then
echo "No APT list file."
return ${found}
else
apt_list="$1"
fi
local apt_list_src="/tmp/sources.list.src.$$"
local apt_tmp="/tmp/apt_src_diff.$$"
# Make a copy for updates
cp -a ${apt_list} ${apt_list_src}
egrep -v '^\s*#|^\s*$' ${apt_list} | egrep ' main|main ' | sed -e 's/deb /deb-src /' | sort | uniq -u >> ${apt_list_src}
cat ${apt_list_src} ${apt_list} | sort | uniq -u > ${apt_tmp}
if [ -s ${apt_tmp} ]
then
echo "Updating ${apt_list} ..."
sudo cp -a ${apt_list} ${apt_list}.save
sudo cp -a ${apt_list_src} ${apt_list}
sudo chown root.root ${apt_list}
sudo rm -f ${apt_list_src}
found=1
else
rm -f ${APT_LIST_SRC}
fi
rm -f ${APT_TMP}
return ${found}
}
echo "Checking for APT Debian sources ..."
echo ""
echo "****************************************"
echo " Updates will require root privileges;"
echo " you may be prompted for your password."
echo "****************************************"
echo ""
COUNT=0
APT_FILES=$(find /etc/apt -name \*.list)
for apt_list in ${APT_FILES}
do
update_apt_listfile $apt_list
COUNT=$((${COUNT}+$?))
done
if [ ${COUNT} -gt 0 ]
then
echo ""
echo "Sources added, Updating APT ..."
sudo apt-get update
else
echo "No Updates required."
fi
exit 0