2024-06-02 15:12:27 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-06-02 20:06:59 -07:00
|
|
|
# Copyright (C) 2024 Thien Tran
|
2024-06-02 15:12:27 -07:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
# use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations under
|
|
|
|
# the License.
|
|
|
|
|
2024-07-20 18:27:34 -07:00
|
|
|
set -eu
|
|
|
|
|
2024-06-02 21:47:06 -07:00
|
|
|
output(){
|
|
|
|
echo -e '\e[36m'"$1"'\e[0m';
|
|
|
|
}
|
|
|
|
|
|
|
|
dataset_selection() {
|
|
|
|
output 'Which dataset do you want to generate the kmod blacklist for?'
|
|
|
|
output '1) VPS'
|
2024-06-03 10:31:47 -07:00
|
|
|
output '2) Bare Metal Servers'
|
|
|
|
output '3) Workstation'
|
2024-06-02 21:47:06 -07:00
|
|
|
output 'Insert the number of your selection:'
|
|
|
|
read -r choice
|
|
|
|
case $choice in
|
|
|
|
1 ) dataset='vps'
|
|
|
|
;;
|
2024-06-03 10:31:47 -07:00
|
|
|
2 ) dataset='server'
|
|
|
|
;;
|
|
|
|
3 ) dataset='workstation'
|
2024-06-02 21:47:06 -07:00
|
|
|
;;
|
|
|
|
* ) output 'You did not enter a valid selection.'
|
|
|
|
dataset_selection
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
dataset_selection
|
|
|
|
|
2024-06-02 20:06:59 -07:00
|
|
|
# Combine all sample data for available
|
2024-06-02 21:47:06 -07:00
|
|
|
sort -u sample-data/"${dataset}"/available/* > blacklist.txt
|
2024-06-02 15:12:27 -07:00
|
|
|
|
2024-06-02 20:06:59 -07:00
|
|
|
# Combine all sample data for necessary
|
2024-06-03 19:00:20 -07:00
|
|
|
sort -u sample-data/"${dataset}"/necessary/* > necessary.txt
|
2024-06-02 15:12:27 -07:00
|
|
|
|
2024-06-03 11:26:11 -07:00
|
|
|
# Remove blacklisted modules from the necessary list
|
|
|
|
|
|
|
|
while read -r KMOD; do
|
|
|
|
sed -i "s/^${KMOD}.*//gm" necessary.txt
|
|
|
|
done < kmod-blacklist-start
|
|
|
|
|
|
|
|
while read -r KMOD; do
|
|
|
|
sed -i "s/.*${KMOD}.*//gm" necessary.txt
|
|
|
|
done < kmod-blacklist-all
|
|
|
|
|
2024-06-02 15:12:27 -07:00
|
|
|
# Create the list to blacklist
|
|
|
|
while read -r KMOD; do
|
2024-06-02 22:13:27 -07:00
|
|
|
sed -i "s/^${KMOD}$//gm" blacklist.txt
|
2024-06-02 15:12:27 -07:00
|
|
|
done < necessary.txt
|
|
|
|
|
2024-06-03 11:26:11 -07:00
|
|
|
# Remove whitelisted modules from the blacklist
|
2024-06-02 20:06:59 -07:00
|
|
|
|
|
|
|
while read -r KMOD; do
|
2024-06-02 22:13:27 -07:00
|
|
|
sed -i "s/^${KMOD}.*//gm" blacklist.txt
|
2024-06-03 11:26:11 -07:00
|
|
|
done < kmod-whitelist-start
|
2024-06-02 20:06:59 -07:00
|
|
|
|
|
|
|
while read -r KMOD; do
|
2024-06-02 22:13:27 -07:00
|
|
|
sed -i "s/.*${KMOD}.*//gm" blacklist.txt
|
2024-06-03 11:26:11 -07:00
|
|
|
done < kmod-whitelist-all
|
2024-06-02 20:06:59 -07:00
|
|
|
|
2024-06-03 12:11:10 -07:00
|
|
|
# Only apply vendor whitelist for non VPS installations
|
2024-06-03 12:06:02 -07:00
|
|
|
if [ "${dataset}" != 'vps' ]; then
|
|
|
|
while read -r KMOD; do
|
|
|
|
sed -i "s/^${KMOD}.*//gm" blacklist.txt
|
2024-06-03 16:05:25 -07:00
|
|
|
done < kmod-whitelist-bare-metal-start
|
2024-06-03 12:06:02 -07:00
|
|
|
|
|
|
|
while read -r KMOD; do
|
|
|
|
sed -i "s/.*${KMOD}.*//gm" blacklist.txt
|
2024-06-03 16:05:25 -07:00
|
|
|
done < kmod-whitelist-bare-metal-all
|
2024-06-03 12:06:02 -07:00
|
|
|
fi
|
|
|
|
|
2024-06-03 15:45:18 -07:00
|
|
|
# Apply whitelist for workstation
|
|
|
|
if [ "${dataset}" = 'workstation' ]; then
|
|
|
|
while read -r KMOD; do
|
|
|
|
sed -i "s/^${KMOD}.*//gm" blacklist.txt
|
|
|
|
done < kmod-whitelist-workstation-start
|
|
|
|
|
|
|
|
while read -r KMOD; do
|
|
|
|
sed -i "s/.*${KMOD}.*//gm" blacklist.txt
|
|
|
|
done < kmod-whitelist-workstation-all
|
|
|
|
fi
|
|
|
|
|
2024-06-03 16:05:25 -07:00
|
|
|
# Reapply blacklists that got removed by the whitelist section
|
|
|
|
while read -r KMOD; do
|
|
|
|
echo "${KMOD}" >> blacklist.txt
|
|
|
|
done < kmod-blacklist-reapply
|
|
|
|
|
2024-06-03 16:25:29 -07:00
|
|
|
# Delete empty lines
|
|
|
|
sed -i '/^$/d' blacklist.txt
|
|
|
|
|
2024-06-02 23:01:45 -07:00
|
|
|
# Delete old files
|
2024-06-03 10:31:47 -07:00
|
|
|
rm -f etc/modprobe.d/"${dataset}"-blacklist.conf
|
2024-06-02 23:01:45 -07:00
|
|
|
|
2024-06-02 15:12:27 -07:00
|
|
|
# Create final blacklist config
|
|
|
|
while read -r KMOD; do
|
2024-06-02 23:01:45 -07:00
|
|
|
echo "install ${KMOD} /bin/false" >> etc/modprobe.d/"${dataset}"-blacklist.conf
|
2024-06-02 15:12:27 -07:00
|
|
|
done < blacklist.txt
|
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
rm necessary.txt blacklist.txt
|