Compare commits

..

12 Commits

Author SHA1 Message Date
tteckster b651b404f6
Update clean.sh
tweak
2023-09-13 15:13:01 -04:00
tteckster 975bce31ba
Update clean.sh
code refactoring
2023-09-13 11:48:21 -04:00
tteckster 14390c0e9e
Update clean-lxcs.sh
code refactoring
2023-09-13 11:35:21 -04:00
tteckster c844311b54
Update CHANGELOG.md 2023-09-13 11:15:30 -04:00
tteckster 955d4b8ce5
Update kernel-clean.sh
tweak
2023-09-13 10:59:59 -04:00
tteckster e35904fbcf
Update kernel-clean.sh
tweak
2023-09-13 09:38:12 -04:00
tteckster d8044f713d
Update CHANGELOG.md 2023-09-13 08:57:02 -04:00
tteckster 4fdead6380
Delete misc/kernel-clean-test.sh 2023-09-13 08:50:28 -04:00
tteckster 644ca75dbd
Update kernel-clean.sh
Code overhaul with a fresh start.
2023-09-13 08:50:10 -04:00
tteckster e09013a8df
Update pialert-install.sh
tweak
2023-09-13 08:28:57 -04:00
tteckster 4ad11e74f7
Create pialert.sh 2023-09-13 08:10:44 -04:00
tteckster 4041a275c2
Create pialert-install.sh 2023-09-13 08:09:25 -04:00
7 changed files with 232 additions and 226 deletions

View File

@ -4,6 +4,15 @@
- All LXC instances created using this repository come pre-installed with Midnight Commander, which is a command-line tool (`mc`) that offers a user-friendly file and directory management interface for the terminal environment.
## 2023-09-13
### Changed
- **Pi.Alert LXC**
- NEW Script
- **Proxmox VE Kernel Clean**
- Code overhaul with a fresh start. This script offers the flexibility to select specific kernels for removal, unlike the previous version, which was an all-or-nothing approach.
## 2023-09-11
### Changed

69
ct/pialert.sh Normal file
View File

@ -0,0 +1,69 @@
#!/usr/bin/env bash
source <(curl -s https://raw.githubusercontent.com/tteck/Proxmox/main/misc/build.func)
# Copyright (c) 2021-2023 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE
function header_info {
clear
cat <<"EOF"
____ _ ___ __ __
/ __ \(_) / | / /__ _____/ /_
/ /_/ / / / /| | / / _ \/ ___/ __/
/ ____/ / / ___ |/ / __/ / / /_
/_/ /_(_)_/ |_/_/\___/_/ \__/
EOF
}
header_info
echo -e "Loading..."
APP="PiAlert"
var_disk="3"
var_cpu="1"
var_ram="512"
var_os="debian"
var_version="12"
variables
color
catch_errors
function default_settings() {
CT_TYPE="1"
PW=""
CT_ID=$NEXTID
HN=$NSAPP
DISK_SIZE="$var_disk"
CORE_COUNT="$var_cpu"
RAM_SIZE="$var_ram"
BRG="vmbr0"
NET="dhcp"
GATE=""
DISABLEIP6="no"
MTU=""
SD=""
NS=""
MAC=""
VLAN=""
SSH="no"
VERB="no"
echo_default
}
function update_script() {
header_info
if [[ ! -d /var ]]; then msg_error "No ${APP} Installation Found!"; exit; fi
msg_info "Updating $APP LXC"
apt-get update &>/dev/null
apt-get -y upgrade &>/dev/null
msg_ok "Updated $APP LXC"
exit
}
start
build_container
description
msg_ok "Completed Successfully!\n"
echo -e "${APP} should be reachable by going to the following URL.
${BL}http://${IP}/pialert/${CL} \n"

View File

@ -0,0 +1,97 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2023 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE
source /dev/stdin <<< "$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os
msg_info "Installing Dependencies"
$STD apt-get -y install \
sudo \
mc \
curl \
apt-utils \
lighttpd \
sqlite3 \
mmdb-bin \
arp-scan \
dnsutils \
net-tools \
libwww-perl \
nmap \
zip \
wakeonlan
msg_ok "Installed Dependencies"
msg_info "Installing PHP Dependencies"
$STD apt-get -y install \
php \
php-cgi \
php-fpm \
php-curl \
php-sqlite3
$STD lighttpd-enable-mod fastcgi-php
service lighttpd force-reload
msg_ok "Installed PHP Dependencies"
#arp-scan -l
msg_info "Installing Python Dependencies"
$STD apt-get -y install \
python3-pip \
python3-requests
$STD pip3 install mac-vendor-lookup
$STD pip3 install fritzconnection
$STD pip3 install cryptography
msg_ok "Installed Python Dependencies"
msg_info "Installing Pi.Alert"
curl -sL https://github.com/leiweibau/Pi.Alert/raw/main/tar/pialert_latest.tar | tar xvf - -C /opt >/dev/null 2>&1
rm /var/www/html/index.html
mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.html.old
ln -s /opt/pialert/install/index.html /var/www/html/index.html
ln -s /opt/pialert/front /var/www/html/pialert
chmod go+x /opt/pialert
chgrp -R www-data /opt/pialert/db
chmod -R 775 /opt/pialert/db
chmod -R 775 /opt/pialert/db/temp
chgrp www-data /opt/pialert/config
chmod -R 775 /opt/pialert/config
chgrp www-data /opt/pialert/config/pialert.conf
chmod -R 775 /opt/pialert/front/reports
chgrp -R www-data /opt/pialert/front/reports
chmod +x /opt/pialert/back/shoutrrr/x86/shoutrrr
touch "/opt/pialert/log/pialert.vendors.log"
touch "/opt/pialert/log/pialert.IP.log"
touch "/opt/pialert/log/pialert.1.log"
touch "/opt/pialert/log/pialert.cleanup.log"
touch "/opt/pialert/log/pialert.webservices.log"
ln -s "/opt/pialert/log/pialert.vendors.log" "/opt/pialert/front/php/server/pialert.vendors.log"
ln -s "/opt/pialert/log/pialert.IP.log" "/opt/pialert/front/php/server/pialert.IP.log"
ln -s "/opt/pialert/log/pialert.1.log" "/opt/pialert/front/php/server/pialert.1.log"
ln -s "/opt/pialert/log/pialert.cleanup.log" "/opt/pialert/front/php/server/pialert.cleanup.log"
ln -s "/opt/pialert/log/pialert.webservices.log" "/opt/pialert/front/php/server/pialert.webservices.log"
sed -i 's#PIALERT_PATH\s*=\s*'\''/home/pi/pialert'\''#PIALERT_PATH = '\''/opt/pialert'\''#' /opt/pialert/config/pialert.conf
msg_ok "Installed Pi.Alert"
msg_info "Start Pi.Alert Scan (Patience)"
$STD python3 /opt/pialert/back/pialert.py update_vendors
$STD python3 /opt/pialert/back/pialert.py internet_IP
$STD python3 /opt/pialert/back/pialert.py 1
msg_ok "Finished Pi.Alert Scan"
motd_ssh
customize
msg_info "Cleaning up"
$STD apt-get autoremove
$STD apt-get autoclean
msg_ok "Cleaned"

View File

@ -16,37 +16,22 @@ function header_info() {
EOF
}
set -e
YW=$(echo "\033[33m")
BL=$(echo "\033[36m")
RD=$(echo "\033[01;31m")
CM='\xE2\x9C\x94\033'
GN=$(echo "\033[1;92m")
CL=$(echo "\033[m")
header_info
while true; do
read -p "This Will Clean logs, cache and update apt lists on selected LXC Containers. Proceed(y/n)?" yn
case $yn in
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
done
clear
echo "Loading..."
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Proxmox VE LXC Updater" --yesno "This Will Clean logs, cache and update apt lists on selected LXC Containers. Proceed?" 10 58 || exit
NODE=$(hostname)
while read -r line; do
TAG=$(echo "$line" | awk '{print $1}')
ITEM=$(echo "$line" | awk '{print substr($0,36)}')
while read -r TAG ITEM; do
OFFSET=2
if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then
MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET))
fi
((${#ITEM} + OFFSET > MSG_MAX_LENGTH)) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
CTID_MENU+=("$TAG" "$ITEM " "OFF")
done < <(pct list | awk 'NR>1')
excluded_containers=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Containers on $NODE" --checklist \
"\nSelect containers to skip from cleaning:\n" \
16 $(($MSG_MAX_LENGTH + 23)) 6 \
"${CTID_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
excluded_containers=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Containers on $NODE" --checklist "\nSelect containers to skip from cleaning:\n" \
16 $((MSG_MAX_LENGTH + 23)) 6 "${CTID_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
function clean_container() {
container=$1
@ -87,4 +72,4 @@ done
wait
header_info
echo -e "${GN} Finished, Containers Cleaned. ${CL} \n"
echo -e "${GN} Finished, Selected Containers Cleaned. ${CL} \n"

View File

@ -6,8 +6,8 @@
# https://github.com/tteck/Proxmox/raw/main/LICENSE
function header_info() {
clear
cat <<"EOF"
clear
cat <<"EOF"
________ __ _ ________
/ ____/ /__ ____ _____ / / | |/ / ____/
/ / / / _ \/ __ `/ __ \ / / | / /
@ -27,16 +27,9 @@ if [[ -z "$cache" ]]; then
echo -e "It appears there are no cached files on your system. \n"
sleep 2
else
echo -e "$cache \n"
echo -e "${GN}Cache in $name${CL}"
read -p "Would you like to remove the selected cache listed above? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Removing cache"
find /var/cache -type f -delete
echo "Successfully Removed cache"
sleep 2
fi
find /var/cache -type f -delete
echo "Successfully Removed Cache"
sleep 2
fi
header_info
echo -e "${BL}[Info]${GN} Cleaning $name${CL} \n"
@ -45,16 +38,9 @@ if [[ -z "$logs" ]]; then
echo -e "It appears there are no logs on your system. \n"
sleep 2
else
echo -e "$logs \n"
echo -e "${GN}Logs in $name${CL}"
read -p "Would you like to remove the selected logs listed above? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Removing logs"
find /var/log -type f -delete
echo "Successfully Removed logs"
sleep 2
fi
find /var/log -type f -delete
echo "Successfully Removed Logs"
sleep 2
fi
header_info
echo -e "${BL}[Info]${GN} Cleaning $name${CL} \n"

View File

@ -1,70 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2023 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE
function header_info {
clear
cat <<"EOF"
__ __ __ ________
/ //_/__ _________ ___ / / / ____/ /__ ____ _____
/ ,< / _ \/ ___/ __ \/ _ \/ / / / / / _ \/ __ `/ __ \
/ /| / __/ / / / / / __/ / / /___/ / __/ /_/ / / / /
/_/ |_\___/_/ /_/ /_/\___/_/ \____/_/\___/\__,_/_/ /_/
EOF
}
YW=$(echo "\033[33m")
RD=$(echo "\033[01;31m")
GN=$(echo "\033[1;92m")
CL=$(echo "\033[m")
BFR="\\r\\033[K"
HOLD="-"
CM="${GN}${CL}"
current_kernel=$(uname -r)
available_kernels=$(dpkg --list | grep 'kernel-.*-pve' | awk '{print $2}' | grep -v "$current_kernel" | sort -V)
header_info
function msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}
function msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Proxmox VE Kernel Clean" --yesno "This will Clean Unused Kernel Images, USE AT YOUR OWN RISK. Proceed?" 10 68 || exit
if [ -z "$available_kernels" ]; then
whiptail --backtitle "Proxmox VE Helper Scripts" --title "No Other Kernels" --msgbox "It appears there are no old Kernels on your system. \nCurrent kernel ($current_kernel)." 10 68
msg_info "Exiting"
sleep 2
msg_ok "Done"
exit
fi
while read -r TAG ITEM; do
OFFSET=2
((${#ITEM} + OFFSET > MSG_MAX_LENGTH)) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
CTID_MENU+=("$TAG" "$ITEM " "OFF")
done < <(echo "$available_kernels")
remove_kernels=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Current Kernel $current_kernel" --checklist "\nSelect Kernels to remove:\n" \
16 $((MSG_MAX_LENGTH + 58)) 6 "${CTID_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Remove Kernels" --yesno "Would you like to remove the selected Kernels\n $remove_kernels\n Proceed?" 10 68 || exit
msg_info "Removing ${CL}${RD}$(echo $remove_kernels | awk '{print NF}') ${CL}${YW}old Kernels${CL}"
/usr/bin/apt purge -y $remove_kernels >/dev/null 2>&1
msg_ok "Successfully Removed Kernels"
msg_info "Updating GRUB"
/usr/sbin/update-grub >/dev/null 2>&1
msg_ok "Successfully Updated GRUB"
msg_info "Exiting"
sleep 2
msg_ok "Done"

View File

@ -6,7 +6,8 @@
# https://github.com/tteck/Proxmox/raw/main/LICENSE
function header_info {
cat <<"EOF"
clear
cat <<"EOF"
__ __ __ ________
/ //_/__ _________ ___ / / / ____/ /__ ____ _____
/ ,< / _ \/ ___/ __ \/ _ \/ / / / / / _ \/ __ `/ __ \
@ -15,126 +16,55 @@ function header_info {
EOF
}
set -euo pipefail
shopt -s inherit_errexit nullglob
YW=$(echo "\033[33m")
BL=$(echo "\033[36m")
RD=$(echo "\033[01;31m")
BGN=$(echo "\033[4;92m")
GN=$(echo "\033[1;92m")
DGN=$(echo "\033[32m")
CL=$(echo "\033[m")
BFR="\\r\\033[K"
HOLD="-"
CM="${GN}${CL}"
CROSS="${RD}${CL}"
PARTY="🎉"
current_kernel=$(uname -r)
clear
available_kernels=$(dpkg --list | grep 'kernel-.*-pve' | awk '{print $2}' | grep -v "$current_kernel" | sort -V)
header_info
while true; do
read -p "This will Clean Unused Kernel Images, USE AT YOUR OWN RISK. Proceed(y/n)?" yn
case $yn in
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo -e "${RD}Please answer y/n${CL}" ;;
esac
done
clear
function msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}
function msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
function check_root() {
if [[ $EUID -ne 0 ]]; then
echo -e "${CROSS}${RD}Error: This script must be ran as the root user.\n${CL}"
exit 1
else
header_info
other_kernel
kernel_info
kernel_clean
fi
}
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Proxmox VE Kernel Clean" --yesno "This will Clean Unused Kernel Images, USE AT YOUR OWN RISK. Proceed?" 10 68 || exit
VERSION="$(awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release)"
function other_kernel() {
if [[ "${VERSION}" == "bullseye" ]]; then
if [[ "$current_kernel" == *"edge"* ]]; then
echo -e "\n${CROSS} ${RD}ERROR:${CL} Proxmox ${BL}${current_kernel}${CL} Kernel Active"
echo -e "\nAn Active PVE Kernel is required to use Kernel Clean\n"
exit 1
fi
if [[ "$current_kernel" == *"6.1"* || "$current_kernel" == *"6.2"* ]]; then
echo -e "\n${CROSS} ${RD}ERROR:${CL} Proxmox ${BL}${current_kernel}${CL} Kernel Active"
echo -e "\nThe script cannot be used when running opt-in kernels. \nProxmox VE's package management relies directly on the current default kernel, which is 5.15. \nTherefore, it is not possible to utilize this script. In this case, you should use autoremove instead. \n`apt-get autoremove`\n"
exit 1
fi
fi
}
function kernel_info() {
if [[ "$MODE" != "PBS" ]]; then
echo -e "${YW}PVE Version: ${BL}$(pveversion)\n${CL}"
fi
if [[ "$current_kernel" == *"pve"* ]]; then
echo -e "${YW}Current Kernel: ${BL}$current_kernel\n${CL}"
else
echo -e "\n${CROSS} ${RD}ERROR: No PVE Kernel Found\n${CL}"
exit 1
fi
}
function kernel_clean() {
kernels=$(dpkg --list | grep 'kernel-.*-pve' | awk '{print $2}' | sort -V)
remove_kernels=""
for kernel in $kernels; do
if [ "$(echo $kernel | grep $current_kernel)" ]; then
break
else
echo -e "${BL}'$kernel' ${CL}${YW}has been added to the remove Kernel list\n${CL}"
remove_kernels+=" $kernel"
fi
done
msg_ok "Kernel Search Completed\n"
if [[ "$remove_kernels" != *"pve"* ]]; then
echo -e "${PARTY} ${GN}It appears there are no old Kernels on your system. \n${CL}"
msg_info "Exiting"
sleep 2
msg_ok "Done"
else
read -p "Would you like to remove the $(echo $remove_kernels | awk '{print NF}') selected Kernels listed above? [y/n]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
msg_info "Removing ${CL}${RD}$(echo $remove_kernels | awk '{print NF}') ${CL}${YW}old Kernels${CL}"
/usr/bin/apt purge -y $remove_kernels >/dev/null 2>&1
msg_ok "Successfully Removed Kernels"
msg_info "Updating GRUB"
/usr/sbin/update-grub >/dev/null 2>&1
msg_ok "Successfully Updated GRUB"
msg_info "Exiting"
sleep 2
msg_ok "Done"
else
msg_info "Exiting"
sleep 2
msg_ok "Done"
fi
fi
}
if ! command -v pveversion >/dev/null 2>&1; then
echo -e " Switching to PBS mode"
MODE="PBS"
sleep 2
else
MODE="PVE"
if [ -z "$available_kernels" ]; then
whiptail --backtitle "Proxmox VE Helper Scripts" --title "No Old Kernels" --msgbox "It appears there are no old Kernels on your system. \nCurrent kernel ($current_kernel)." 10 68
msg_info "Exiting"
sleep 2
msg_ok "Done"
exit
fi
check_root
while read -r TAG ITEM; do
OFFSET=2
((${#ITEM} + OFFSET > MSG_MAX_LENGTH)) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
CTID_MENU+=("$TAG" "$ITEM " "OFF")
done < <(echo "$available_kernels")
remove_kernels=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Current Kernel $current_kernel" --checklist "\nSelect Kernels to remove:\n" \
16 $((MSG_MAX_LENGTH + 58)) 6 "${CTID_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Remove Kernels" --yesno "Would you like to remove the previously selected Kernels?" 10 68 || exit
msg_info "Removing ${CL}${RD}$(echo $remove_kernels | awk '{print NF}') ${CL}${YW}old Kernels${CL}"
/usr/bin/apt purge -y $remove_kernels >/dev/null 2>&1
msg_ok "Successfully Removed Kernels"
msg_info "Updating GRUB"
/usr/sbin/update-grub >/dev/null 2>&1
msg_ok "Successfully Updated GRUB"
msg_info "Exiting"
sleep 2
msg_ok "Done"