Syncing state

This commit is contained in:
DarkFeather
2018-12-11 17:07:05 -06:00
parent 2398d69139
commit 30c6c5791b
10 changed files with 122 additions and 790 deletions

View File

@@ -1,6 +1,5 @@
LIST=bell bigorlittle compare-directories compress-all diff-args expand-all logged-shell standardize-folder whatismyip new-irssi-config replicate-ssh-profiles worktrack ssh-authorize-host
LOCATION=${pkgbuild}/usr/local/bin
INSTALLER != curl -s https://aninix.net/foundation/installer-test.bash | /bin/bash
LIST=bell bigorlittle compare-directories compress-all diff-args expand-all logged-shell standardize-folder sysinfo whatismyip worktrack
LOCATION=${pkgdir}/usr/local/bin
PERMISSION=0755
compile:
@echo Nothing to compile.
@@ -24,4 +23,3 @@ clean:
diff:
for i in ${LIST}; do diff ./$$i ${LOCATION}/$$i; done

View File

@@ -1,69 +0,0 @@
#!/bin/bash
function prompt-var() {
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Need a variable name (1) and a prompt string (2)"
return 1;
fi
unset $1
while [ "${!1}" == "" ]; do
printf "%s " "$2";
read $1;
done
return 0;
}
# This function will prompt the user for variable 1 with string 2 until it gets a nonempty answer.
function prompt-password() {
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Need a variable name (1) and a prompt string (2)"
return 1;
fi
unset $1
while [ "${!1}" == "" ]; do
printf "%s " "$2";
read -s $1;
echo
done
return 0;
}
#This function will prompt the user for a variable 1 with string 2 until it gets an answer between min 3 and max 4.
function prompt-num-var() {
if [ -z "$1" ] || [ -z "$2" ] || [ "$3" -ne "$3" ] || [ "$4" -le "$3" ]; then
echo "Need a variable name (1), prompt string (2), min (3), and max (4)";
echo 1: $1;
echo 2: $2;
echo 3: $3;
echo 4: $4;
return 1;
fi
unset $1
while [ "${!1}" == "" ] || [ "${!1}" -lt "$3" ] || [ "${!1}" -gt "$4" ]; do
printf "%s " "$2";
read $1;
done
return 0;
}
# Needed information
prompt-var NETWORKNAME "What is the network name? "
prompt-var IRCADDRESS "What is the IRC address? "
prompt-num-var IRCPORT "What port is listening? " 1 65535
prompt-var CHANNELNAME "What is the first channel to join? "
prompt-var USERNAME "What username do you use on this network? "
prompt-password NICKSERVPASS "What is your password to NickServ?"
prompt-password SERVERPASS "What is the server password? (Enter nopass if no password)"
# Create the config;
cp -r /etc/skel/.irssi ./.irssi-"$NETWORKNAME"
cd ./.irssi-"$NETWORKNAME"
if [ "$SERVERPASS" != "nopass" ]; then
sed -i "s@address = \"IRCADDRESS\";@address = \"IRCADDRESS\";\n password = \"$SERVERPASS\";@" config
fi
sed -i "s@NETWORKNAME@$NETWORKNAME@g" config
sed -i "s@IRCADDRESS@$IRCADDRESS@g" config
sed -i "s@IRCPORT@$IRCPORT@g" config
sed -i "s@CHANNELNAME@$CHANNELNAME@g" config
sed -i "s@USERNAME@$USERNAME@g" config
sed -i "s@REALNAME@$USERNAME@g" config
sed -i "s@NICKSERVPASS@$NICKSERVPASS@g" config
echo
echo "Run \"irssi --home=$PWD\" to start your new config."

View File

@@ -1,58 +0,0 @@
#!/bin/bash
# Process CLI arguments to set up assumptions.
searchterm="$1"
if [ -z "$searchterm" ]; then searchterm="'*'"; fi
### <summary>
### Sets up key-based auth to remote hosts and replicate local .bashrc and .profile to them.
### Assumes that
### </summary>
### <param name="searchterm">(Assumed) term to search for as a prefix</param>
### <param name="system">(Assumed) system .ssh/config hostname</param>
### <param name="realname">(Assumed) system real hostname</param>
function push() {
tput setaf 2; tput bold; printf "$system ($realname) ... \n"; tput sgr0;
# Find the Private key to use.
privfile="$(grep IdentityFile $HOME/.ssh/config | grep `echo $system | cut -f 1 -d '-'` | head -n 1 | cut -f 2 -d ' ')"
if [ -z "$privfile" ]; then privfile="$HOME/.ssh/id_rsa"; fi
command='echo mkdir -p "$HOME/.ssh" &> /dev/null; mkdir -p "$HOME/.ssh"; chmod 0700 $HOME $HOME/.ssh; echo "'`cat $privfile.pub`'" >> $HOME/.ssh/authorized_keys; cp $HOME/.ssh/authorized_keys $HOME/.ssh/id_rsa.pub; chmod 0600 $HOME/.ssh/authorized_keys; chown -R `whoami` $HOME 2>/dev/null; mv $HOME/.profile $HOME/.profile.bak 2>/dev/null; mv $HOME/.bashrc $HOME/.bashrc.bak 2>/dev/null; printf "";'
# Make sure that we have the right host signature.
ssh-keygen -R "$realname"
if [ $? -ne 0 ]; then printf "FAILED\n\n"; return; fi
ssh-keyscan -H "$realname" >> ~/.ssh/known_hosts
if [ $? -ne 0 ]; then printf "FAILED\n\n"; return; fi
# Set up home folder and send public key.
ssh -t $system bash -c "$command"
if [ $? -ne 0 ]; then printf "FAILED\n\n"; return; fi
# Self-allow key-based auth
scp $privfile $system:.ssh/id_rsa
if [ $? -ne 0 ]; then printf "FAILED\n\n"; return; fi
# Pass profiles.
scp $HOME/.bashrc $system:.bashrc
if [ $? -ne 0 ]; then printf "FAILED\n\n"; return; fi
scp $HOME/.profile $system:.profile
if [ $? -ne 0 ]; then
printf "FAILED\n\n";
else
printf "DONE\n\n"
fi
}
### <summary>
### If the search term is in ~/.ssh/config, then replicate to all matching hosts.
### Otherwise, replicate to target specifically.
### </summary>
### <param name="searchterm">(Assumed) term to search for as a prefix</param>
if [ `grep -c "$searchterm" "$HOME/.ssh/config"` -gt 0 ]; then
for system in `egrep '^Host ' $HOME/.ssh/config | cut -f 2 -d ' ' | egrep $searchterm`; do
entry=$(cat -n $HOME/.ssh/config | grep $system | head -n 1 | xargs | cut -f 1 -d ' ')
linenum=$(( $entry + 1 ))
realname="$(cat -n $HOME/.ssh/config | grep " ${linenum}$(printf '\t')" | rev | cut -f 1 -d ' ' | rev)"
if [ -z "$realname" ]; then realname="$system"; fi
push;
done
else
system="$searchterm"
push;
fi

View File

@@ -1,41 +0,0 @@
#!/bin/bash
#--------------------------------------------------------------------#
#File: ssh-authorize-host
#
#Description: Add a public key to a remote SSH-capable host.
#
#Package: AniNIX::MiscScripts
#Copyright: WTFPL
#
#Author: DarkFeather
#Changelog by editor:
#--------------------------------------------------------------------#
# Show the usage for this script.
function usage {
echo "Usage: $0 host [ pubkeyfile ]"
}
# Create the initial SSH command.
function initialSSHCommand() {
echo 'mkdir -p ${HOME}/.ssh'
echo 'touch ${HOME}/.ssh/authorized_keys'
echo 'chmod 0700 ${HOME} ${HOME}/.ssh'
echo 'chmod 0600 ${HOME}/.ssh/authorized_keys'
echo 'chown -R `whoami`":" ${HOME}'
echo 'cat >> ${HOME}/.ssh/authorized_keys'
}
# Parse the CLI arguments.
host="$1"
if [ -z "$host" ]; then usage; exit 1; fi
pubkeyfile="$2"
if [ -z "$pubkeyfile" ] || [ ! -f "$pubkeyfile" ]; then
pubkeyfile="${HOME}/.ssh/id_rsa.pub"
fi
# Execute on the remote host.
(initialSSHCommand; cat "$pubkeyfile") | ssh "$host" /bin/bash

9
Shared/sysinfo Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
(printf "%s | %s | %s %s | %s \n" \
"$(uname -norm)" \
"$(uptime -s)" \
"$(grep -c processor /proc/cpuinfo)" \
"$(grep -m 1 model\ name /proc/cpuinfo | cut -f 2 -d ':')" \
"$(grep MemTotal /proc/meminfo)") \
| sed 's/\s\+/ /g'