Last active
May 12, 2021 10:15
-
-
Save TBog/665ac53d4e6a418b64504ac53f444b60 to your computer and use it in GitHub Desktop.
Replay an upgarde log. Send log archive name as parameter.
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 | |
UNPACK_THEN_EXIT="" | |
CLEANUP="yes" | |
TIMING="yes" | |
filename="" | |
POSITIONAL=() | |
while [[ $# -gt 0 ]] | |
do | |
key="$1" | |
case $key in | |
-u|--unpack) | |
UNPACK_THEN_EXIT="$1" | |
shift # past argument | |
;; | |
-nc|--no-cleanup) | |
CLEANUP="" | |
shift # past argument | |
;; | |
-nt|--no-timing) | |
TIMING="" | |
shift # past argument | |
;; | |
-f|--file) | |
filename="$2" | |
shift # past argument | |
shift # past value | |
;; | |
*) # unknown option | |
POSITIONAL+=("$1") # save it in an array for later | |
shift # past argument | |
;; | |
esac | |
done | |
set -- "${POSITIONAL[@]}" # restore positional parameters | |
if [[ -z $filename ]]; then | |
filename=$1 | |
fi | |
# remove all extensions | |
timestamp=${filename%%.*} | |
# remove `upgrade_log_` prefix | |
timestamp=${timestamp##*_} | |
# echo "log timestamp: $timestamp" | |
if [[ ! -z "$UNPACK_THEN_EXIT" ]]; | |
then | |
echo "Unpacking \"$filename\" then exiting" | |
tar -xaf $filename | |
exit | |
else | |
if [[ $filename =~ \.tar\. ]]; | |
then | |
tar -xaf $filename | |
if [[ ! -z "$CLEANUP" ]]; then | |
CLEANUP="silent" | |
fi | |
else | |
# don't remove log, it's not temporary | |
CLEANUP="" | |
fi | |
fi | |
if [[ ! -z "$TIMING" ]]; | |
then | |
scriptreplay -m 0.5 -t $timestamp.timing $timestamp.log | |
else | |
# dummy="/tmp/dummy_$timestamp.timing" | |
# echo "0 " > $dummy | |
# wc -c < $timestamp.log >> $dummy | |
# scriptreplay -t $dummy $timestamp.log | |
# echo "y" | unlink $dummy | |
scriptreplay -m 0 -t $timestamp.timing $timestamp.log | |
fi | |
if [[ ! -z "$CLEANUP" ]]; | |
then | |
[[ $CLEANUP != "silent" ]] && echo "Removing \"$timestamp.timing\" and \"$timestamp.log\"" | |
echo "y" | unlink $timestamp.timing | |
echo "y" | unlink $timestamp.log | |
exit | |
fi |
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 | |
SCRIPT_DIR=$(cd `dirname $0` && pwd) | |
# if not root, run as root | |
if (( $EUID != 0 )); then | |
echo sudo $SCRIPT_DIR/`basename $0` "$@" | |
sudo $SCRIPT_DIR/`basename $0` "$@" | |
exit | |
fi | |
# the current directory is used for output | |
pushd $SCRIPT_DIR &> /dev/null | |
TEXT_YELLOW='\e[0;33m' | |
TEXT_RED='\e[1;31m' | |
TEXT_RESET='\e[0m' | |
if [[ "$(ps -ocommand= -p $PPID | awk '{print $1}')" != "script" ]]; then | |
# forward all params escaped | |
COMMAND="$0" | |
for arg in "$@"; do | |
COMMAND+=" " | |
COMMAND+=$(printf %q "$arg") | |
done | |
timestamp=$(date +%Y%m%d-%H%M%S) | |
script --quiet --command "$COMMAND" --timing=$timestamp.timing $timestamp.log | |
TAR_FILE="upgrade_log_$timestamp.tar.bz2" | |
tar -cjf $TAR_FILE $timestamp.timing $timestamp.log | |
if [[ $? -eq 0 ]]; then | |
rm --interactive=never $timestamp.timing | |
rm --interactive=never $timestamp.log | |
echo -e "Logs: $(pwd)/${TEXT_YELLOW}${TAR_FILE}${TEXT_RESET}" | |
else | |
echo -e "${TEXT_RED}Failed to compress logs$TEXT_RESET" | |
echo -e "timing file: $(pwd)/${TEXT_YELLOW}$timestamp.timing${TEXT_RESET}" | |
echo -e " log file: $(pwd)/${TEXT_YELLOW}$timestamp.log${TEXT_RESET}" | |
fi | |
popd &> /dev/null | |
exit | |
fi | |
time ( \ | |
apt update && \ | |
echo -e "${TEXT_YELLOW}apt update${TEXT_RESET} finished\n" && \ | |
apt -y autoremove && \ | |
echo -e "${TEXT_YELLOW}apt autoremove${TEXT_RESET} finished\n" && \ | |
apt -y full-upgrade && \ | |
echo -e "${TEXT_YELLOW}apt full-update${TEXT_RESET} finished\n" && \ | |
apt purge -y $(dpkg --get-selections | awk '{if ($2=="deinstall") print $1}') && \ | |
echo -e "${TEXT_YELLOW}apt purge${TEXT_RESET} finished" \ | |
) | |
if [ -f /var/run/reboot-required ]; then | |
echo -e $TEXT_RED | |
cat /var/run/reboot-required | |
echo -e $TEXT_RESET | |
fi | |
updatedb | |
popd &> /dev/null | |
echo "done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment