From ce8320ce2e0c42ee22cc0bfb79ef4d667d4c22b6 Mon Sep 17 00:00:00 2001 From: DarkFeather Date: Wed, 9 Nov 2016 22:25:00 -0600 Subject: [PATCH] Adding Admin and Shared scripts --- Admin/Makefile | 21 ++++++++++++++++ Admin/arch-update | 33 +++++++++++++++++++++++++ Admin/clean-exim | 4 ++++ Admin/clean-exim-input | 3 +++ Admin/close-guest | 4 ++++ Admin/fix-sound | 4 ++++ Admin/log-guest | 4 ++++ Admin/open-guest | 4 ++++ Admin/restart-service | 7 ++++++ Admin/silent-guardian | 49 ++++++++++++++++++++++++++++++++++++++ Shared/Makefile | 22 +++++++++++++++++ Shared/bell | 2 ++ Shared/bigorlittle | 3 +++ Shared/compare-directories | 3 +++ Shared/compress-all | 12 ++++++++++ Shared/diff-args | 6 +++++ Shared/expand-all | 8 +++++++ Shared/logged-shell | 7 ++++++ Shared/standardize-folder | 11 +++++++++ Shared/whatismyip | 4 ++++ 20 files changed, 211 insertions(+) create mode 100644 Admin/Makefile create mode 100755 Admin/arch-update create mode 100755 Admin/clean-exim create mode 100755 Admin/clean-exim-input create mode 100755 Admin/close-guest create mode 100755 Admin/fix-sound create mode 100755 Admin/log-guest create mode 100755 Admin/open-guest create mode 100755 Admin/restart-service create mode 100755 Admin/silent-guardian create mode 100644 Shared/Makefile create mode 100755 Shared/bell create mode 100755 Shared/bigorlittle create mode 100755 Shared/compare-directories create mode 100755 Shared/compress-all create mode 100755 Shared/diff-args create mode 100755 Shared/expand-all create mode 100755 Shared/logged-shell create mode 100755 Shared/standardize-folder create mode 100755 Shared/whatismyip diff --git a/Admin/Makefile b/Admin/Makefile new file mode 100644 index 0000000..938aee4 --- /dev/null +++ b/Admin/Makefile @@ -0,0 +1,21 @@ +LIST=arch-update clean-exim clean-exim-input close-guest fix-sound log-guest open-guest restart-service silent-guardian +LOCATION=/root/bin +PERMISSION=0700 +compile: + @echo Nothing to compile. + +install: compile + for i in ${LIST}; do cp ./$$i ${LOCATION} + make checkperm + +reverse: + for i in ${LIST}; do cp ${LOCATION}/$$i .; done + +test: ${LIST} + for i in ${LIST}; do [ "$$(grep -c '#/bin/bash' $$i)" -ne 1 ]; done + +checkperm: + for i in ${LIST}; do chown root:root ${LOCATION}/$$i; chmod ${PERMISSION} ${LOCATION}/$$i; done + +clean: + @echo Nothing to do. diff --git a/Admin/arch-update b/Admin/arch-update new file mode 100755 index 0000000..8977f28 --- /dev/null +++ b/Admin/arch-update @@ -0,0 +1,33 @@ +#!/bin/bash + +export LOGFILE="/var/log/sysupdate.log" +date > $LOGFILE + +# Update +echo == Updating Arch Packages == >> $LOGFILE +pacman -Syu --noconfirm 2>&1 >> $LOGFILE +echo >> $LOGFILE + +# Get AUR list of update candidates +echo == AUR Candidate List == >> $LOGFILE +cower -u >> $LOGFILE +echo >> $LOGFILE + +# Clean cache +echo == Cleaning Cache == >> $LOGFILE +paccache -r >> $LOGFILE +echo >> $LOGFILE + +# Generate list of installed packages +echo == Generated installed-packages list == >> $LOGFILE +pacman --color never -Qem > /var/log/installed-packages.txt +pacman --color never -Qen >> /var/log/installed-packages.txt + +# Generate list of orphaned packages +echo == Generated orphaned-packages list == >> $LOGFILE +pacman -Qdtq > /var/log/orphaned-packages.txt +echo >> $LOGFILE +date >> $LOGFILE +printf '\n\n' >> $LOGFILE + +cat $LOGFILE | mail -s "AniNIX::$(hostname) update log" sh1k0b4@gmail.com diff --git a/Admin/clean-exim b/Admin/clean-exim new file mode 100755 index 0000000..b46fa37 --- /dev/null +++ b/Admin/clean-exim @@ -0,0 +1,4 @@ +#!/bin/bash + +exim -bp | exiqgrep -i | xargs exim -Mrm + diff --git a/Admin/clean-exim-input b/Admin/clean-exim-input new file mode 100755 index 0000000..44db42c --- /dev/null +++ b/Admin/clean-exim-input @@ -0,0 +1,3 @@ +#!/bin/bash + +ls /var/spool/exim/input | cut -c1-16 | xargs exim -Mrm diff --git a/Admin/close-guest b/Admin/close-guest new file mode 100755 index 0000000..6f2bad2 --- /dev/null +++ b/Admin/close-guest @@ -0,0 +1,4 @@ +#!/bin/bash +usermod -G guest guest +chsh -s /usr/local/bin/noshell guest +passwd guest diff --git a/Admin/fix-sound b/Admin/fix-sound new file mode 100755 index 0000000..230d5cb --- /dev/null +++ b/Admin/fix-sound @@ -0,0 +1,4 @@ +#!/bin/bash +rmmod snd_hda_intel +modprobe snd_hda_intel +alsactl init \ No newline at end of file diff --git a/Admin/log-guest b/Admin/log-guest new file mode 100755 index 0000000..0bd88b8 --- /dev/null +++ b/Admin/log-guest @@ -0,0 +1,4 @@ +#!/bin/bash +chsh -s /usr/local/bin/logged-shell guest +usermod -a -G ssh_allow_grp guest +passwd guest diff --git a/Admin/open-guest b/Admin/open-guest new file mode 100755 index 0000000..0be76c4 --- /dev/null +++ b/Admin/open-guest @@ -0,0 +1,4 @@ +#!/bin/bash +chsh -s /bin/bash guest +usermod -a -G ssh_allow_grp guest +passwd guest \ No newline at end of file diff --git a/Admin/restart-service b/Admin/restart-service new file mode 100755 index 0000000..152d1ee --- /dev/null +++ b/Admin/restart-service @@ -0,0 +1,7 @@ +#!/bin/bash +if [ "$1" == "" ]; then echo Need a service name ; exit; fi + +systemctl daemon-reload +systemctl restart $1 +sleep 3 +systemctl status -l $1 diff --git a/Admin/silent-guardian b/Admin/silent-guardian new file mode 100755 index 0000000..56c09b7 --- /dev/null +++ b/Admin/silent-guardian @@ -0,0 +1,49 @@ +#!/bin/bash + +if [ ! -f /usr/local/src/SharedLibraries/Bash/header ]; then + echo This script requires the SharedLibraries package. + exit 1; +fi +source /usr/local/src/SharedLibraries/Bash/header +export logfile="/var/log/silent-guardian.log" + + +logstatement "Started $(date)" + +# Fix the Webserver permissions +chown -R cxford:http /srv/http/* +find /srv/http/* -type f -exec chmod 0640 {} \; +find /srv/http/* -type d -exec chmod 0750 {} \; + +# Fix the media permissions +chown -R cxford:http /srv/yggdrasil +find /srv/yggdrasil/ -type f -exec chmod 0440 {} \; +find /srv/yggdrasil/ -type d -exec chmod 0550 {} \; +chmod -R u+w /srv/yggdrasil/new_acquisition + +# fix the WolfPack results location +find /srv/WolfPackResults -type d -exec chmod 0755 {} \; +find /srv/WolfPackResults -type f -exec chmod 0644 {} \; + +# Seal the special directories. +for i in $(ls -a /srv/yggdrasil/Digital_Library/ | egrep '^\.[a-zA-Z0-9]+$'); do + chown cxford:cxford -R $i; + find $i -type f -exec chmod 0400 {} \; + find $i -type d -exec chmod 0500 {} \; +done + +# Guard root +chmod 0700 /root +chown -R root:root /root +find /root -type d -exec chmod 0700 {} \; + +# Guard home directories +chmod 0750 /home/* +chmod 0700 /home/.root-only/ + +# Guard API's +chmod 0750 /usr/local/bin/api-keys +chown root:api /usr/local/bin/api-keys + +logstatement "Ended $(date)" +logstatement " " diff --git a/Shared/Makefile b/Shared/Makefile new file mode 100644 index 0000000..9338206 --- /dev/null +++ b/Shared/Makefile @@ -0,0 +1,22 @@ +LIST=bell bigorlittle compare-directories compress-all diff-args expand-all logged-shell standardize-folder whatismyip +LOCATION=/usr/local/bin +PERMISSION=0755 +compile: + @echo Nothing to compile. + +install: compile + for i in ${LIST}; do cp ./$$i ${LOCATION} + make checkperm + +reverse: + for i in ${LIST}; do cp ${LOCATION}/$$i .; done + +test: ${LIST} + for i in ${LIST}; do [ "$$(grep -c '#/bin/bash' $$i)" -ne 1 ]; done + +checkperm: + for i in ${LIST}; do chown root:root ${LOCATION}/$$i; chmod ${PERMISSION} ${LOCATION}/$$i; done + +clean: + @echo Nothing to do. + diff --git a/Shared/bell b/Shared/bell new file mode 100755 index 0000000..8322383 --- /dev/null +++ b/Shared/bell @@ -0,0 +1,2 @@ +#!/bin/bash +echo -ne '\007' diff --git a/Shared/bigorlittle b/Shared/bigorlittle new file mode 100755 index 0000000..4dcaeee --- /dev/null +++ b/Shared/bigorlittle @@ -0,0 +1,3 @@ +#!/bin/bash +if [ $(echo -n I | od -to2 | head -n1 | cut -f2 -d" " | cut -c6) ]; then echo "Little endian"; else echo "Big endian"; fi + diff --git a/Shared/compare-directories b/Shared/compare-directories new file mode 100755 index 0000000..681d16d --- /dev/null +++ b/Shared/compare-directories @@ -0,0 +1,3 @@ +#!/bin/bash +if [ "$1" == "" -or "$2" == "" ]; then echo Need to supply two directories as arguments.; exit; fi; +diff -rcw "$1" "$2" | grep ^Only diff --git a/Shared/compress-all b/Shared/compress-all new file mode 100755 index 0000000..6e92cd9 --- /dev/null +++ b/Shared/compress-all @@ -0,0 +1,12 @@ +#!/bin/bash + +export IFS=" +" + +for i in $(find "$PWD" -type d); do + cd "$i"; + for j in $(find . -maxdepth 1 -type f); do + echo $i/$j + gzip "$j"; + done +done diff --git a/Shared/diff-args b/Shared/diff-args new file mode 100755 index 0000000..64bae3f --- /dev/null +++ b/Shared/diff-args @@ -0,0 +1,6 @@ +#!/bin/bash +if [ "$1" != "$2" ]; then + echo "These are different."; +else + echo "These are the same."; +fi \ No newline at end of file diff --git a/Shared/expand-all b/Shared/expand-all new file mode 100755 index 0000000..6d50e34 --- /dev/null +++ b/Shared/expand-all @@ -0,0 +1,8 @@ +#!/bin/bash + +for i in $(find "$PWD" -type d); do + cd $i; + for j in $(find . -maxdepth 1 -type f); do + gunzip $j; + done +done diff --git a/Shared/logged-shell b/Shared/logged-shell new file mode 100755 index 0000000..0009827 --- /dev/null +++ b/Shared/logged-shell @@ -0,0 +1,7 @@ +#!/bin/bash +export SHELL=/bin/bash +export LOGFILE="/var/log/guest_log/$(/usr/bin/whoami)-$(date +%F-%R).log" +env > $LOGFILE +exec /bin/sh -c "script -a -q -f $LOGFILE" +#/bin/bash -c "echo /usr/bin/logged-shell" +exit diff --git a/Shared/standardize-folder b/Shared/standardize-folder new file mode 100755 index 0000000..1c09cd4 --- /dev/null +++ b/Shared/standardize-folder @@ -0,0 +1,11 @@ +#!/bin/bash + +export IFS=" +" +export prefix="$(echo $PWD | rev | cut -f 1 -d '/' | rev)" +firstext="$(ls | head -n 1 | rev | cut -f 1 -d \. | rev)" +export count=1; +for i in $(ls -tr *."$firstext" | grep -v "$prefix"); do + mv "$i" "$prefix $count.$firstext" + export count=$(($count+1)) +done diff --git a/Shared/whatismyip b/Shared/whatismyip new file mode 100755 index 0000000..da65140 --- /dev/null +++ b/Shared/whatismyip @@ -0,0 +1,4 @@ +#!/bin/bash +echo Cloaked as $(/usr/bin/lynx --dump whatismyipaddress.com | grep '/ip/' | head -n 1 | cut -f 5 -d '/') + +