scripts

watchdmesg.sh
#!/bin/bash
watch --color -n 0.5 "dmesg --color=always | tail -n 30"


removeoldkernels.sh
#!/bin/bash

KERNEL_VARIANT="$(uname -r | awk -F "-" '{print $NF}')"
KERNEL_VERSION="$(uname -r | sed -e "s/-${KERNEL_VARIANT}//")"

echo "Currently running: ${KERNEL_VERSION}-${KERNEL_VARIANT}"

ALL_VER="$(dpkg --list | grep -e linux-image -e linux-headers | grep -v -e linux-headers-${KERNEL_VARIANT} -e linux-image-${KERNEL_VARIANT} | awk '{print $3}' | sort -uV)"

echo "All installed:" ${ALL_VER}

NUM_INSTALLED="$(echo "${ALL_VER}" | wc -l)"

if [ ${NUM_INSTALLED} -lt 3 ]; then
    echo "2 or fewer kernel versions installed, quitting"
    exit
fi

NUM_TO_REMOVE="$(expr ${NUM_INSTALLED} - 2)"
REMOVE_VER="$(echo "${ALL_VER}" | head -n ${NUM_TO_REMOVE})"
REMOVE_PACKAGES="$(dpkg --list | grep -e "${REMOVE_VER}" | grep -v libc | awk '{print $2}')"

echo "Removing:" ${REMOVE_PACKAGES}

sudo apt-get purge ${REMOVE_PACKAGES}

# would be nice: check that the current version is the most recent of installed versions.


lmcuexport.sh
#!/bin/bash -ex
sed -i 's/","/"\t"/g' $1
sed -i 's/<br \/>/\n/g' $1
sed -i 's/\&amp;/\&/g' $1


ttltrick.sh
#!/bin/bash -x

iwconfig 2> /dev/null | grep --color=always "Power Management:"

TTLMOD=$(sudo iptables -t mangle -L POSTROUTING | grep TTL)

if [ -z "${TTLMOD}" ]; then
    sudo iptables -t mangle -A POSTROUTING -j TTL --ttl-set 65
fi

exit 0
sudo sed -i 's/wifi.powersave = 3/wifi.powersave = 2/' /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
nmcli connection add ifname enp0s25 con-name StewNAT type ethernet ipv4.method shared ipv4.addresses 10.42.0.1/24 ipv6.method shared
nmcli connection delete StewNAT

cpufreq.sh
#!/bin/bash -ex

# Found this trick at:
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/power_management_guide/tuning_cpufreq_policy_and_speed

cpupower frequency-info --policy
sudo cpupower frequency-set --max 2500000 --min 800000 --governor powersave
cpupower frequency-info --policy

xbacklight -set 25

# Seems like this is not necessary - no need to add processor.ignore_ppc=1 to kernel command line.

# Not sure if this is necessary: sudo apt install linux-tools-generic-hwe-16.04

# Probably not necessary:
# /etc/modprobe.d/lenovo-acpi.conf
# options thinkpad_acpi fan_control=1

# Other potentially relevant links:
# https://wiki.archlinux.org/index.php/CPU_frequency_scaling
# http://www.thinkwiki.org/wiki/Problem_with_CPU_frequency_scaling
# http://www.thinkwiki.org/wiki/How_to_use_cpufrequtils

install_atom.sh
curl -sL https://packagecloud.io/AtomEditor/atom/gpgkey | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] https://packagecloud.io/AtomEditor/atom/any/ any main" > /etc/apt/sources.list.d/atom.list'
sudo apt-get update

watchcpufreq.sh
#!/bin/bash
watch -n 0.2 'grep "cpu MHz" /proc/cpuinfo'
Comments