From a793b23435567f2d4f49846196ceebcc47cd764c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Fri, 7 Apr 2017 14:56:22 +0200 Subject: Remove stuff not needed on server --- local/bin/asus-fan | 28 ----------- local/bin/email-unread | 34 ------------- local/bin/lxc-net | 42 ---------------- local/bin/mxrandr | 119 ---------------------------------------------- local/bin/sys-reboot | 2 - local/bin/sys-shutdown | 2 - local/bin/sys-suspend | 2 - local/bin/system-backup | 75 ----------------------------- local/bin/vim-project-gen | 4 -- local/sbin/newmail-notify | 23 --------- local/sbin/syncemail | 44 ----------------- 11 files changed, 375 deletions(-) delete mode 100755 local/bin/asus-fan delete mode 100755 local/bin/email-unread delete mode 100755 local/bin/lxc-net delete mode 100755 local/bin/mxrandr delete mode 100755 local/bin/sys-reboot delete mode 100755 local/bin/sys-shutdown delete mode 100755 local/bin/sys-suspend delete mode 100755 local/bin/system-backup delete mode 100755 local/bin/vim-project-gen delete mode 100755 local/sbin/newmail-notify delete mode 100755 local/sbin/syncemail (limited to 'local') diff --git a/local/bin/asus-fan b/local/bin/asus-fan deleted file mode 100755 index 09e54f1..0000000 --- a/local/bin/asus-fan +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -# TODO this probably should be auto detected, because hwmon number can change -HWMON=/sys/devices/platform/asus-nb-wmi/hwmon/hwmon1 - -if [ "$(whoami)" != "root" ]; then - echo "Run $0 only with root privileges" - exit -1 -fi - -case "$1" in - -h|--help) - echo "Usage: $0 -h|full|auto" - echo "This script controls asus hwmon" - echo " full - Full throttle" - echo " auto - Automatic hardware control" - ;; - full) - echo 1 > $HWMON/pwm1_enable - echo 255 > $HWMON/pwm1 - ;; - auto) - echo 0 > $HWMON/pwm1_enable - ;; - *) - echo "Unknown or no option given!" - exit -2 - ;; -esac diff --git a/local/bin/email-unread b/local/bin/email-unread deleted file mode 100755 index 3956f3b..0000000 --- a/local/bin/email-unread +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/perl -use strict; -use warnings; -use File::Find; - -use constant EMAIL => glob("~/.mail"); -my $IGNORE = "(Spam|trash|Important)"; - -my $V = (shift || "") eq "-s"; - -opendir(EDIR, EMAIL) or die $!; -while (readdir EDIR) { - next if /^\./ or not (-d EMAIL."/$_"); - our $count = 0; - - sub new_dir { - my $path = substr $File::Find::name, 1 + length EMAIL; - $path =~ s/\/new$//; - return if $_ ne "new" or $path =~ /$IGNORE/; - #print "ok: $path\n"; - my $cnt = 0; - opendir(NDIR, "$File::Find::name") or die $!; - while (readdir NDIR) { - $cnt += 1 unless /^\./; - } - closedir(NDIR); - print "$path: $cnt\n" if not $V and $cnt > 0; - $count += $cnt; - } - find(\&new_dir, EMAIL."/$_"); - - print "$_: $count\n" if $V and $count > 0; -} -closedir(EDIR); diff --git a/local/bin/lxc-net b/local/bin/lxc-net deleted file mode 100755 index a9f1d10..0000000 --- a/local/bin/lxc-net +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh -set -e - -if [ "$(id -u)" -ne 0 ]; then - echo "Root required for execution" >&2 - exit 1 -fi - -# What if we want to clean -if [ "$1" = "clean" ]; then - kill $(cat /tmp/lxc-dhcpd.pid) - rm -f /tmp/lxc-dhcpd.pid /tmp/lxc-dhcpd.conf - ip link del dev vbr0 - exit -fi - -# Setup bridge -ip link add name vbr0 type bridge -ip link set vbr0 up -ip addr add 192.168.30.1/24 dev vbr0 - -# Start dhcp server - -# This just takes first dns nameserver configured. Maybe we might want to be -# little bit more clever. -DNS_SERVER=$(cat /etc/resolv.conf |grep -i nameserver|head -n1|cut -d ' ' -f2) -echo "# DHCPD configuration generated by lxc-net script -authoritative; -default-lease-time 600; -max-lease-time 7200; -option subnet-mask 255.255.255.0; -option broadcast-address 192.168.30.255; -option routers 192.168.30.1; -option domain-name-servers $DNS_SERVER; -subnet 192.168.30.0 netmask 255.255.255.0 { - range 192.168.30.10 192.168.30.100; -}" > /tmp/lxc-dhcpd.conf -dhcpd -4 -pf /tmp/lxc-dhcpd.pid -cf /tmp/lxc-dhcpd.conf vbr0 - -# Setup network forwarding (TODO add -o ethX to iptable command) -sysctl net.ipv4.ip_forward=1 -iptables -t nat -A POSTROUTING -j MASQUERADE diff --git a/local/bin/mxrandr b/local/bin/mxrandr deleted file mode 100755 index 81ae511..0000000 --- a/local/bin/mxrandr +++ /dev/null @@ -1,119 +0,0 @@ -#!/bin/bash - -# get info from xrandr -connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") -activeOutput=$(xrandr | grep -E " connected (primary )?[1-9]+" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") -disconnectedOutputs=$(xrandr | grep -E " disconnected (primary )?[1-9]+" | awk '{print $1}') - -cmd="xrandr " -cmd_def=$cmd - -INTERNAL=eDP-1 -HDMI=HDMI-1 -VGA=VGA-1 - -for device in "$disconnectedOutputs"; do - if [ -n "$defice" ]; then - if [[ "$activeOutput" == *"$device"* ]]; then - cmd=$cmd" --output $device --off" - fi - fi -done - -function only_internal { - cmd=$cmd" --output $INTERNAL --auto --primary" - cmd=$cmd" --output $HDMI --off" - cmd=$cmd" --output $VGA --off" -} - -function internal_vga { - cmd=$cmd" --output $INTERNAL --auto --primary" - cmd=$cmd" --output $HDMI --off" - cmd=$cmd" --output $VGA --auto --right-of $INTERNAL" -} - -function internal_hdmi { - cmd=$cmd" --output $INTERNAL --auto --right-of $HDMI" - cmd=$cmd" --output $HDMI --auto --primary" - cmd=$cmd" --output $VGA --off" -} - -function internal_hdmi_vga { - cmd=$cmd" --output $INTERNAL --auto --right-of $HDMI" - cmd=$cmd" --output $HDMI --auto --primary" - cmd=$cmd" --output $VGA --auto --left-of $HDMI" -} - -function cmd_exec { - if [ "$cmd" != "$cmd_def" ]; then - echo $cmd - `$cmd` - fi -} - - -if [ $# -le 1 ]; then - if [[ "$connectedOutputs" == *"$HDMI"* ]]; then - if [[ "$connectedOutputs" == *"$VGA"* ]]; then - internal_hdmi_vga - else - internal_hdmi - fi - else - if [[ "$connectedOutputs" == *"$VGA"* ]]; then - internal_vga - else - only_internal - fi - fi - cmd_exec - exit -fi - -if [ "$2" != "mode" ]; then - if [[ "$connectedOutputs" != *"$2"* ]]; then - echo No $2 display known - exit - fi -fi - -case "$1" in - toggle) - case "$2" in - $INTERNAL) - if [[ "$activeOutput" == *"$INTERNAL"* ]]; then - cmd=$cmd" --output $INTERNAL --off" - else - if [[ "$activeOutput" == *"$HDMI"* ]]; then - cmd=$cmd" --output $INTERNAL --auto --right-of $HDMI" - else - cmd=$cmd" --output $INTERNAL --auto --primary" - fi - fi - ;; - $HDMI) - if [[ "$activeOutput" == *"$HDMI"* ]]; then - cmd=$cmd" --output $HDMI --off" - else - if [[ "$activeOutput" == *"$VGA"* ]]; then - cmd=$cmd" --output $HDMI --auto --primary" - else - cmd=$cmd" --output $HDMI --auto --right-of $INTERNAL" - fi - fi - ;; - $VGA) - if [[ "$activeOutput" == *"$VGA"* ]]; then - cmd=$cmd" --output $VGA --off" - else - if [[ "$activeOutput" == *"$HDMI"* ]]; then - cmd=$cmd" --output $VGA --auto --left-of $HDMI" - else - cmd=$cmd" --output $VGA --auto --right-of $INTERNAL" - fi - fi - ;; - esac - ;; -esac -cmd_exec diff --git a/local/bin/sys-reboot b/local/bin/sys-reboot deleted file mode 100755 index 24a024c..0000000 --- a/local/bin/sys-reboot +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart diff --git a/local/bin/sys-shutdown b/local/bin/sys-shutdown deleted file mode 100755 index bff9762..0000000 --- a/local/bin/sys-shutdown +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop diff --git a/local/bin/sys-suspend b/local/bin/sys-suspend deleted file mode 100755 index 49b4b2e..0000000 --- a/local/bin/sys-suspend +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Suspend boolean:true diff --git a/local/bin/system-backup b/local/bin/system-backup deleted file mode 100755 index dfa2c09..0000000 --- a/local/bin/system-backup +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash -# vim:ft=sh -# New line separated list of all directories to backup -DIRS="/etc -/home -/home_hdd" -# Name of the machine used in backup subvolumes -MNAME=asus -# Path where backup will be mounted -MPATH=/media/backup -# UUID of disk -UUID=b162ea95-38bb-42c6-b36a-1be98c65392c -# Mount additional arguments -MARGS="-o compress=lzo" -# If disk is encrypted -CRYPT=true -#################################################################### -# Check if running as root -if [ `id -u` -ne "0" ]; then - echo Please run this as root. - exit 1 -fi -set -e - -# Mount disk -PART=$(lsblk -fpl | grep "$UUID" | awk '{print $1}') -if [ -z "$PART" ]; then - echo Disk not detected. Exiting - exit -1 -fi -if $CRYPT; then - echo -e "\e[1;33mDecrypting filesystem\e[0m" - # TODO what if already opened - cryptsetup open "$PART" backup || (echo Decryption failed && exit -2) - PART=/dev/mapper/backup - echo $PART -fi -echo -e "\e[1;33mMounting\e[0m" -mkdir -p "$MPATH" -mount $MARGS "$PART" "$MPATH" || (echo Mount failed && exit -3) - -[ -d "$MPATH"/@"$MNAME" ] || (echo There seems to be no subvolume $MNAME && exit -4) - -# Do backup -while read -r DIR; do - echo -e "\e[1;33mBacking up: $DIR\e[0m" - rsync -aAxXS --delete --progress "$DIR" "$MPATH"/@"$MNAME"/ || [ $? -eq 24 ] - # We ignore exit code if rsync detects vanished source file -done <<< "$DIRS" - -# Do snapshot (read only) -(cd "$MPATH"; btrfs subvolume snapshot -r @asus @asus-$(date -u +%y%m%d)) - -# Remove snapshots older than 2 months -# TODO ensure that at least five stays -(cd "$MPATH" -for s in @"$MNAME"-*; do - if [ $(expr $(date +%s) - $(stat -c %Y "$s")) -gt 5529600 ]; then - btrfs subvolume delete "$s" - fi -done) - -# Unmount disk -sync -f "$MPATH"/@"$MNAME" -umount "$MPATH" || (echo Unmount failed. Unmount by hand. && exit -5) -if $CRYPT; then - cryptsetup close backup || (echo Encryption close failed. Do by hand. && exit -6) -fi - -# Store when we did last backup and update i3blocks status -date +"%s" > /home/cynerd/.backup_date -pkill -RTMIN+13 i3blocks - -echo -echo -e "\e[1;34mBackup finished\e[0m" diff --git a/local/bin/vim-project-gen b/local/bin/vim-project-gen deleted file mode 100755 index 6a50ba5..0000000 --- a/local/bin/vim-project-gen +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# Generates ctags and cscope files for project. -ctags -R -f .tags -#cscope -Rbq -f .cscope.out diff --git a/local/sbin/newmail-notify b/local/sbin/newmail-notify deleted file mode 100755 index 7c6b803..0000000 --- a/local/sbin/newmail-notify +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -cd ~/.mail - -if [ -f notify-notified ]; then - NOTIFIED=`cat notify-notified` - rm notify-notified -fi - -for account in `ls`; do - if cd "$account"/INBOX/new; then - for m in `ls`; do - echo $m - echo $m >> ~/.mail/notify-notified - if echo "$NOTIFIED" | grep "$m" >/dev/null; then continue; fi - FROM=`grep -E "^From: " "$m" | sed 's/^From: //' | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)'` - TO=`grep -E "^To: " "$m" | sed 's/^To: //' | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)'` - SUBJECT=`grep -E "^Subject: " "$m" | sed 's/^Subject: //' | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)'` - notify-send "$TO: $FROM" "$SUBJECT" - done - fi - cd ~/.mail -done diff --git a/local/sbin/syncemail b/local/sbin/syncemail deleted file mode 100755 index dfd56a3..0000000 --- a/local/sbin/syncemail +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/python2 -# This starts offlineimap, but first it requests passwords from pass -import os -import sys -import subprocess -import daemon -import lockfile -from offlineimap import OfflineImap - -pidfile = '/tmp/syncemail-%d.pid' % os.getuid() - -# Check if not already running -def check_running(): - if os.access(pidfile, os.F_OK): - with open(pidfile, "r") as f: - pid = f.readline() - if os.path.exists('/proc/%s' % pid): - sys.exit(0) -check_running() - - -accounts = [ - ["email", "mail/cynerd@email.cz"], - ] - -for acc in accounts: - pproc = subprocess.Popen("pass " + acc[1], - stdout=subprocess.PIPE, shell=True) - output = pproc.stdout.read().rstrip() - if pproc.wait() != 0: - print("Password receive failed.") - sys.exit(1) - sys.argv.append('-k') - sys.argv.append('Repository_' + acc[0] + '-remote:remotepass=' + output) - -sys.argv.append('-s') # output to syslog -sys.argv.append('-u') -sys.argv.append('syslog') - -with daemon.DaemonContext(): - check_running() - with open(pidfile, "w") as f: - f.write("%s" % os.getpid()) - OfflineImap().run() -- cgit v1.2.3