Skip to content

KobeW50/linux-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linux Scripts

This repository contains my Linux scripts that are good enough for general use by others. The scripts in this README are arranged top-to-bottom from complex (high potential value) to very simple (you could easily write these on your own). Also check out my Nemo actions repository.

Note that I am new to Linux and scripting. Use these at your own risk.

Please open an issue if you found bugs, have questions, or want to contribute. Thanks :)


Scripts

This script is useful if you want to disable Tailscale when you connect to certain networks (ie: your home Wi-Fi) and enable Tailscale when connected to any other network. It can easily be modified to perform any command unrelated to Tailscale when these conditions occur.

The script should be stored in /etc/NetworkManager/dispatcher.d/. It is invoked by NetworkManager-dispatcher, which is a daemon that runs scripts in the directory when there are certain changes to the network connection. I suggest that you read more about NetworkManager-dispatcher on the Arch Wiki, especially if you plan to modify the script so that it functions beyond its intended use.

According to the NetworkManager-dispatcher documentation linked above, the script runs as root, should be owned by root, should be executable, and must not be writable by groups or others.

Using the script:

# The script depends on the following commands: ip, awk, grep, and tailscale

# You will need to modify the script in a text editor to specify the SSID/name of the Wi-Fi network.
# Read the comments in the script for more details about changes you may want to make.

# Enable the NetworkManager-dispatcher daemon
sudo systemctl enable NetworkManager-dispatcher.service

# Make root the owner of the script
sudo chown root:root 30-manage-tailscale.sh

# Give root write privileges and everyone else read and execute privileges
sudo chmod 755 30-manage-tailscale.sh

# Move script to correct directory
sudo mv 30-manage-tailscale.sh /etc/NetworkManager/dispatcher.d/

This script dynamically sets the power-profiles-daemon mode depending on whether or not the device is charging. It runs in the background and periodically checks if the charging/discharging state has changed. The script stops running if you manually change the power-profiles-daemon mode. By default, the script will always set power-profiles-daemon to 'balanced' mode when charging. Variables at the beginning of the script can be configured so that 'balanced' mode and/or 'performance' mode are used when charging after a specific battery percentage has been reached. One day I may simplify this script by using udev instead.

Note that this script's functionality is already implemented in newer releases of power-profiles-daemon. If you using an adequately up-to-date version, see the power-profiles-daemon README.md for information on how to make it behave dynamically.

Using the script:

# The script depends on the following commands: powerprofilesctl, upower, grep, and awk

# Read the comments in the script for more details about changes you may want to make.

# Start power-profiles-daemon
sudo systemctl enable --now power-profiles-daemon.service

# Make the script executable
chmod +x power-profiles.sh

# Make the script run on startup. This is beyond the scope of this guide.
# If you need help, open an issue in this repository or see https://wiki.archlinux.org/title/Autostarting

This script toggles a QEMU-based virtual machine on and off using virsh (ie: the libvirt command-line utility). When toggling on, it opens the virtual machine in virt-manager.

Using the script:

# You will need to modify the script in a text editor to specify the name of the virtual machine that it should toggle.

# Make the script executable
chmod +x toggle-vm.sh

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages