Skip to main content

githubSetSSH.sh

0 likes • Sep 9, 2023 • 2 views
Shell
Loading...

More Shell Posts

upload_key.sh

0 likes • Jan 12, 2023 • 0 views
Shell
#!/bin/bash
#Originally made by Isaac Cook https://gist.github.com/icook/5400173
#Modified by Leif Messinger
#upload_key.sh [server_ip [server2_ip [...]]]
#To be run locally on a linux computer
if [ -e ~/.ssh/id_rsa.pub ];
then
echo "SSH Key already exists on local machine"
else
echo "Generating SSH key on local machine"
ssh-keygen -t rsa #generates id_rsa and id_rsa.pub
chmod -R 700 ~/.ssh #Sets permissions of ssh folder
ssh-add #Adds keys (and passwords?) to ssh_agent. (hopefully doesn't require password)
fi
echo "Loading client public key into memory"
pubKey=$(<~/.ssh/id_rsa.pub)
for server
do
echo "Adding client public key to $server remote server authorized keys"
#Idiot Isaac Cook didn't know about ssh-copy-id
#ssh-copy-id even checks if your key already exists
#In fairness, I didn't either until researching ssh-add
ssh-copy-id -i ~/.ssh/id_rsa.pub $server #In theory, this should prompt for a username
#ssh $server "mkdir -p ~/.ssh; #Make the folder if not already made
# echo \"$pubKey\" >> ~/.ssh/authorized_keys; #Append your public key to the server's authorized_keys
# chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys" #Set the correct permissions of those files
#echo "Adding server public key to local authorized keys"
#ssh $server "ssh-copy-id -i ~/.ssh/id_rsa.pub \$SSH_CLIENT" #this might need some awk, as $SSH_CLIENT spits out clientip portnumber
echo "Displaying server public key"
ssh $server "cat ~/.ssh/id_rsa.pub"
#Though, he did give me a good idea
echo "Displaying keys authorized on $server (you can paste them in your authorized_keys file)"
ssh $server "cat ~/.ssh/authorized_keys"
#echo "Appending keys authorized on $server to your local authorized_keys"
#ssh $server "cat ~/.ssh/authorized_keys" >> ~/.ssh/authorized_keys
done
echo "SSH keys schronized successfully!"

Update Prefixed Dependencies

CHS
0 likes • Oct 9, 2023 • 42 views
Shell
# Update all npm packages under the scope defined by the PREFIX variable ("foo").
PREFIX="foo"; npm ls | grep "$PREFIX" | awk -F/ '{print $NF}' | sed 's/@.*//' | xargs -I package npm update @"$PREFIX"/package

makefileMaker.sh

0 likes • Mar 7, 2021 • 1 view
Shell
#!/bin/bash
#makefileMaker.sh by Leif Messinger
#Needs getDependencies.sh
CC="gcc"
#I have no idea why it's called CXX when it's a c++ compiler
#I know that cpp is c pre processor, but still, why X?
CXX="g++"
CXXFLAGS="-std=c++17 -O2"
#CFLAGS="-std=c17"
LIBRARIES="$@"
#Vulkan Flags for me
#LIBRARIES="-lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi"
function compileAllFiles(){
#output: bruh.o yeet.o
# CXX $CXXFLAGS bruh.o yeet.o -o output $LIBRARIES
echo -n "output:"
if compgen -G "*.cpp" &> /dev/null; then
for f in *.cpp; do
echo -n " ${f%.cpp}.o"
done
fi
if compgen -G "*.c" &> /dev/null; then
for f in *.c; do
echo -n " ${f%.c}.o"
done
fi
echo ""
if compgen -G "*.cpp" &> /dev/null; then
echo -e -n "\t$CXX $CXXFLAGS "
else
echo -e -n "\t$CC $CFLAGS "
fi
if compgen -G "*.cpp" &> /dev/null; then
for f in *.cpp; do
echo -n " ${f%.cpp}.o"
done
fi
if compgen -G "*.c" &> /dev/null; then
for f in *.c; do
echo -n " ${f%.c}.o"
done
fi
echo " -o output $LIBRARIES"
echo ""
}
function compileAllObjectFiles(){
#bruh.o: bruh.cpp yeet.h
# CXX $CXXFLAGS -c bruh.cpp $LIBRARIES
if compgen -G "*.cpp" &> /dev/null; then
for f in *.cpp; do
echo -n "${f%.cpp}.o: $f"
getDependencies.sh < $f
echo ""
echo -e "\t$CXX $CXXFLAGS -c $f"
echo ""
done
fi
#yeet.o: yeet.c
# CC $CFLAGS -c yeet.c $LIBRARIES
if compgen -G "*.c" &> /dev/null; then
for f in *.c; do
echo -n "${f%.c}.o: $f"
getDependencies.sh < $f
echo ""
echo -e "\t$CC $CFLAGS -c $f"
echo ""
done
fi
}
compileAllFiles
compileAllObjectFiles
#does not work on windows
echo "clean:"
echo -e "\trm -f -v *.o output"
echo ""
echo "run:"
echo -e "\t./output"
echo ""
echo "debug:"
if compgen -G "*.cpp" &> /dev/null; then
echo -e -n "\t$CXX $CXXFLAGS -g "
else
echo -e -n "\t$CC $CFLAGS -g "
fi
if compgen -G "*.cpp" &> /dev/null; then
for f in *.cpp; do
echo -n " ${f}"
done
fi
if compgen -G "*.c" &> /dev/null; then
for f in *.c; do
echo -n " ${f}"
done
fi
echo " $LIBRARIES -o output"
echo ""

Search file with word list fast

0 likes • Feb 22, 2022 • 1 view
Shell
#Leif Messinger
#For when you want to search a lot of words in a file fast
#Arg 1 is the argument the list of words you want to search
#Arg 2 is the file you want to search
#-z means that it looks at the file as a whole, just treating newlines a characters.
#-r is regex. Needed for $, even tho the documentation says you don't need it. They are liars.
#First command replaces all . with \. and all - with \-
#Second command takes all newlines and replaces them with )|(
#Third command takes the trailing |( and deletes it
#Forth command puts a /( at the start
#Fith command puts /!d at the end. This tells it to not delete any lines that match the pattern.
#The second sed takes the output of the first sed as a command that searches any of the combined words
#-f - takes a command from the input
sed -z -r -e 's/\./\\\./g ; s/\-/\\\-/g' -e 's/\n/\)\|\(/g' -e 's/\|\($//' -e 'i/\(' -e 'a/!d' $1 | sed -r -f - $2

codecatch.sh

0 likes • Nov 14, 2021 • 0 views
Shell
#!/bin/bash
#Takes all the c and h files in the current directory and prints them
#Yup, it's that easy
for file in *.h *.hpp *.c *.cpp; do
#If it exists
if [ -f "$file" ]; then
echo "//===============$file==============="
cat $file
fi
done

pinger.sh

0 likes • Mar 21, 2021 • 0 views
Shell
#pinger.sh by Leif Messinger
#./pinger.sh [ADDRESS] to search
#./pinger.sh [ADDRESS] & to search in the background
#https://serverfault.com/a/42382
ping_cancelled=false # Keep track of whether the loop was cancelled, or succeeded
until ping -c1 "$1" >/dev/null 2>&1; do :; done & # The "&" backgrounds it
trap "kill $!; ping_cancelled=true" SIGINT
wait $! # Wait for the loop to exit, one way or another
trap - SIGINT # Remove the trap, now we're done with it
if [ "$ping_cancelled" == true ] #https://stackoverflow.com/a/21210966/10141528
then
printf "The pinger for $1 just closed bro.\n"
else
printf "$1 IS UP BROOO\a\n"
fi