Cleaned up and merge other Linux snippit repo
Meged https://git.bprieshof.nl/brammp/linux into ./Linux
This commit is contained in:
54
Linux/Script-examples/CLI_Selector.sh
Normal file
54
Linux/Script-examples/CLI_Selector.sh
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
# Purpose: Demonstrate usage of select and case with toggleable flags to indicate choices
|
||||
# 2013-05-10 - Dennis Williamson
|
||||
|
||||
choice () {
|
||||
local choice=$1
|
||||
if [[ ${opts[choice]} ]] # toggle
|
||||
then
|
||||
opts[choice]=
|
||||
else
|
||||
opts[choice]=+
|
||||
fi
|
||||
}
|
||||
|
||||
PS3='Please enter your choice: '
|
||||
while :
|
||||
do
|
||||
clear
|
||||
options=("Option 1 ${opts[1]}" "Option 2 ${opts[2]}" "Option 3 ${opts[3]}" "Done")
|
||||
select opt in "${options[@]}"
|
||||
do
|
||||
case $opt in
|
||||
"Option 1 ${opts[1]}")
|
||||
choice 1
|
||||
break
|
||||
;;
|
||||
"Option 2 ${opts[2]}")
|
||||
choice 2
|
||||
break
|
||||
;;
|
||||
"Option 3 ${opts[3]}")
|
||||
choice 3
|
||||
break
|
||||
;;
|
||||
"Option 4 ${opts[4]}")
|
||||
choice 4
|
||||
break
|
||||
;;
|
||||
"Done")
|
||||
break 2
|
||||
;;
|
||||
*) printf '%s\n' 'invalid option';;
|
||||
esac
|
||||
done
|
||||
done
|
||||
|
||||
printf '%s\n' 'Options chosen:'
|
||||
for opt in "${!opts[@]}"
|
||||
do
|
||||
if [[ ${opts[opt]} ]]
|
||||
then
|
||||
printf '%s\n' "Option $opt"
|
||||
fi
|
||||
done
|
||||
15
Linux/Script-examples/DBUG-output.sh
Normal file
15
Linux/Script-examples/DBUG-output.sh
Normal file
@@ -0,0 +1,15 @@
|
||||
# Set debug flag as desired
|
||||
DEBUG=1
|
||||
# DEBUG=0
|
||||
|
||||
if [ "$DEBUG" -eq "1" ]; then
|
||||
OUT='/dev/tty'
|
||||
else
|
||||
OUT='/dev/null'
|
||||
fi
|
||||
|
||||
# actual script use commands like this
|
||||
command > $OUT 2>&1
|
||||
|
||||
# or like this if you need
|
||||
command 2> $OUT
|
||||
4
Linux/Script-examples/Options-AsVar_whiptail.sh
Normal file
4
Linux/Script-examples/Options-AsVar_whiptail.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
args=("Option 1:" "Option 1 Desription" OFF)
|
||||
args+=("Option 2: " "Option 2 Desription" OFF)
|
||||
args+=("Option 3: " "Option 3 Desription" OFF)
|
||||
option=$(whiptail --nocancel --title "Title" --checklist "Features" 11 110 5 "${args[@]}" 3>&1 1>&2 2>&3)
|
||||
72
Linux/Script-examples/PasswordQuest.sh
Normal file
72
Linux/Script-examples/PasswordQuest.sh
Normal file
@@ -0,0 +1,72 @@
|
||||
function PasswordQuest {
|
||||
passdiaone=$(whiptail --nocancel --passwordbox "Please enter your password (Requires 8 chars, uper & lower case, special and numerical)" 11 91 --title "Config" 3>&1 1>&2 2>&3)
|
||||
if [ -z $passdiaone ]; then PasswordQuest; fi
|
||||
if [[ ${#passdiaone} -ge 8 && "$passdiaone" == *[[:lower:]]* && "$passdiaone" == *[[:upper:]]* && "$passdiaone" == *[0-9]* && "$passdiaone" == *['!'@#%^\&*()_+]* ]]; then
|
||||
PasswordCheck
|
||||
else
|
||||
whiptail --ok-button Done --msgbox " Password is invalid!" 10 30
|
||||
unset passdiaone
|
||||
PasswordQuest
|
||||
fi
|
||||
}
|
||||
|
||||
function PasswordCheck {
|
||||
#Checking password
|
||||
passdiatwo=$(whiptail --nocancel --passwordbox " Please re-enter your password" 11 82 --title "Config" 3>&1 1>&2 2>&3)
|
||||
if [ -z $passdiatwo ]; then
|
||||
PasswordCheck
|
||||
else
|
||||
if [ $passdiaone != $passdiatwo ]; then
|
||||
whiptail --ok-button Done --msgbox " Password does not match!" 10 30
|
||||
PasswordQuest
|
||||
else
|
||||
echo "Pass okay"
|
||||
password="$passdiaone"
|
||||
unset passdiaone passdiatwo
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
function LegacyPasswordQuest {
|
||||
echo "Enter password (Requires: 8 chars, 1 capital and 1 num)"
|
||||
read -s passdiaone
|
||||
if [ -z $passdiaone ]; then LegacyPasswordQuest; fi
|
||||
if [[ ${#passdiaone} -ge 8 && "$passdiaone" == *[[:lower:]]* && "$passdiaone" == *[[:upper:]]* && "$passdiaone" == *[0-9]* && "$passdiaone" == *['!'@#%^\&*()_+]* ]]; then
|
||||
LegacyPasswordCheck
|
||||
else
|
||||
echo " Password is invalid!"
|
||||
unset passdiaone
|
||||
LegacyPasswordQuest
|
||||
fi
|
||||
}
|
||||
|
||||
function LegacyPasswordCheck {
|
||||
#Checking password
|
||||
echo "Please re-enter your password"
|
||||
read -s passdiatwo
|
||||
if [ -z $passdiatwo ]; then
|
||||
LegacyPasswordCheck
|
||||
else
|
||||
if [ $passdiaone != $passdiatwo ]; then
|
||||
echo "Password does not match!"
|
||||
LegacyPasswordQuest
|
||||
else
|
||||
echo "Pass okay"
|
||||
password="$passdiaone"
|
||||
unset passdiaone passdiatwo
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
##Uncomment for Legacy
|
||||
#LegacyPasswordQuest
|
||||
|
||||
##Uncomment for Whiptail
|
||||
#PasswordQuest
|
||||
|
||||
|
||||
#Retrun
|
||||
echo "$password"
|
||||
6
Linux/Script-examples/VarModifiers.sh
Normal file
6
Linux/Script-examples/VarModifiers.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
option="${option// /}" #Removes Spaces
|
||||
option="${option/:/ }" #First : to Space
|
||||
option="${option//:/ }" #All : to Space
|
||||
option="${option//:}" #Removes :
|
||||
option="${option,,}" #Removes LowerCase
|
||||
option="${option//'"'}" #Removes "
|
||||
17
Linux/Script-examples/bash-script-Flag.sh
Normal file
17
Linux/Script-examples/bash-script-Flag.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
if [ "$1" != "-l" ]; then
|
||||
echo "Normal mode"
|
||||
IMODE=n
|
||||
fi
|
||||
|
||||
if [ "$1" = "-l" ]; then
|
||||
echo "Legacy mode";
|
||||
IMODE=l
|
||||
fi
|
||||
|
||||
|
||||
|
||||
if [ $IMODE = n ]; then
|
||||
echo "New Menu"
|
||||
elif [ $IMODE = l ]; then
|
||||
echo "Legacy Menu"
|
||||
fi
|
||||
73
Linux/Script-examples/curl-Functions-authchecker.md
Normal file
73
Linux/Script-examples/curl-Functions-authchecker.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# Authchecker functions for curl
|
||||
## curl keeps asking for password until correct, and downloads file
|
||||
|
||||
```
|
||||
function getcurlsec {
|
||||
|
||||
local curlurl="$1"
|
||||
local curluser="$2"
|
||||
local curloutput="$3"
|
||||
|
||||
while true; do
|
||||
curl --fail --user "$curluser" "$curlurl" -o "$curloutput"
|
||||
local EC=$?
|
||||
if [ $EC -eq 0 ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
Syntax: `getcurlsec <url to download> <username> <output file>`
|
||||
|
||||
|
||||
## curl downloads file using given credentials
|
||||
|
||||
```
|
||||
function getcurlsecwpassword {
|
||||
|
||||
local curlurl="$1"
|
||||
local curluser="$2"
|
||||
local curlpassword="$3"
|
||||
local curloutput="$4"
|
||||
curl --fail --user "$curluser":"$curlpassword" "$curlurl" -o "$curloutput"
|
||||
local EC=$?
|
||||
if [ $EC -eq 0 ]; then
|
||||
echo "Password correct"
|
||||
else
|
||||
echo "Password incorrect"
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
Syntax: `getcurlsecwpassword <url to download> <username> <password> <output file>`
|
||||
|
||||
|
||||
## curl keeps asking for password until correct, and stores username and password as var
|
||||
|
||||
```
|
||||
function checkusercurl {
|
||||
|
||||
local curlurl="$1"
|
||||
curluser="$2"
|
||||
|
||||
while true; do
|
||||
read -s -p "Enter password for user $curluser: " curlpassword
|
||||
echo "";
|
||||
curl -s --fail --user "$curluser":"$curlpassword" "$curlurl" -o /dev/null
|
||||
local EC=$?
|
||||
if [ $EC -eq 0 ]; then
|
||||
echo "Password correct"
|
||||
break
|
||||
fi
|
||||
echo "Incorrect password"
|
||||
unset curlpassword
|
||||
done
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
Syntax: `checkusercurl <url to authenticate against> <username>`
|
||||
username wil become var: curluser
|
||||
password wil become var: $curlpassword
|
||||
Reference in New Issue
Block a user