This commit is contained in:
2022-09-05 14:34:31 +03:00
parent ab7b662756
commit 48f382f31c
7 changed files with 255 additions and 4 deletions
+7
View File
@@ -0,0 +1,7 @@
Each script helps you to install compiler
Example to use insert variable:
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/miscellaneous/insert_variable.sh) -n USERNAME -v "YOUR_NAME"
Speed test:
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/miscellaneous/spped_test/golang.sh) "df"
+127
View File
@@ -0,0 +1,127 @@
#!/bin/bash
# Default variables
name=""
value=""
type="export"
rename=""
delete_type="none"
# Options
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/colors.sh) --
option_value(){ echo "$1" | sed -e 's%^--[^=]*=%%g; s%^-[^=]*=%%g'; }
while test $# -gt 0; do
case "$1" in
-h|--help)
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/logo.sh)
echo
echo -e "${C_LGn}Functionality${RES}: the script inserts variable or alias to ${C_LGn}$HOME/.bash_profile${RES}"
echo
echo -e "${C_LGn}Usage${RES}: script ${C_LGn}[OPTIONS]${RES}"
echo
echo -e "${C_LGn}Options${RES}:"
echo -e " -h, --help show the help page"
echo -e " -n, --name NAME variable or alias NAME (mandatory)"
echo -e " -v, --value VALUE variable or alias VALUE (leave blank for manual input)"
echo -e " -a, --alias inserting an alias"
echo -e " -r, --rename NAME_2 rename NAME_2 to NAME"
echo -e " -d, --delete delete the first occurrence of a variable or alias by NAME"
echo -e " -da, --delete-all delete all occurrences of a variable or alias by NAME"
echo
echo -e "You can use either \"=\" or \" \" as an option and value ${C_LGn}delimiter${RES}"
echo
# echo -e "${C_LGn}Useful URLs${RES}:"
# echo -e "https://github.com/SecorD0/utils/blob/main/miscellaneous/insert_variable.sh - script URL"
# echo -e "https://t.me/letskynode — node Community"
echo
return 0 2>/dev/null; exit 0
;;
-n*|--name*)
if ! grep -q "=" <<< "$1"; then shift; fi
name=`option_value "$1"`
shift
;;
-v*|--value*)
if ! grep -q "=" <<< "$1"; then shift; fi
value=`option_value "$1"`
shift
;;
-a|--alias)
type="alias"
shift
;;
-r*|--rename*)
if ! grep -q "=" <<< "$1"; then shift; fi
rename=`option_value "$1"`
shift
;;
-d|--delete)
delete_type="delete"
shift
;;
-da|--delete-all)
delete_type="delete_all"
shift
;;
*|--)
break
;;
esac
done
# Functions
printf_n(){ printf "$1\n" "${@:2}"; }
# Actions
#touch $HOME/.bash_profile
if [ -f ~/.bash_profile ];
then
echo -e "${C_LGn}File bash_profile is exist${RES}"
else
if [ -f ~/.profile ];
then
echo -e "${C_LGn}Make necessary link to file bash_profile${RES}"
ln -s ~/.profile ~/.bash_profile
else
touch $HOME/.bash_profile
fi
fi
. $HOME/.bash_profile
if [ ! -n "$name" ]; then
printf_n "${C_R}You didn't specify a name via${RES} -n ${C_R}option!${RES}"
return 1 2>/dev/null; exit 1
fi
if [ "$delete_type" != "none" ]; then
if [ "$delete_type" = "delete" ]; then
sed -i "0,/ ${name}=/{/ ${name}=/d;}" $HOME/.bash_profile
elif [ "$delete_type" = "delete_all" ]; then
sed -i "/ ${name}=/d" $HOME/.bash_profile
fi
unset "$name"
unalias "$name" 2>/dev/null
else
if [ -n "$rename" ]; then
sed -i "s%${rename}%${name}%" $HOME/.bash_profile
unset "$rename"
unalias "$rename" 2>/dev/null
if [ ! -n "$value" ]; then
. $HOME/.bash_profile
return 0 2>/dev/null; exit 0
fi
fi
if [ ! -n "$value" ]; then
printf "${C_LGn}Enter the value:${RES} "
read -r value
fi
if ! cat $HOME/.bash_profile | grep -q " ${name}="; then
echo "${type} ${name}=\"${value}\"" >> $HOME/.bash_profile
elif ! cat $HOME/.bash_profile | grep -qF "${name}=\"${value}\""; then
sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $HOME/.bash_profile
fi
variable=`cat $HOME/.bash_profile | grep -qF "${name}=\"${value}\""`
if ! grep -q "${type}" <<< "$variable"; then
sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $HOME/.bash_profile
fi
fi
sed -i '/^$/d' $HOME/.bash_profile
. $HOME/.bash_profile
+58
View File
@@ -0,0 +1,58 @@
#!/bin/bash
# Options
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/colors.sh) --
option_value(){ echo "$1" | sed -e 's%^--[^=]*=%%g; s%^-[^=]*=%%g'; }
while test $# -gt 0; do
case "$1" in
-h|--help)
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/logo.sh)
echo
echo -e "${C_LGn}Functionality${RES}: the script opens specified ports"
echo
echo -e "${C_LGn}Usage${RES}: script ${C_LGn}[OPTIONS]${RES} ${C_LGn}[ARGUMENTS]${RES}"
echo
echo -e "${C_LGn}Options${RES}:"
echo -e " -h, --help show the help page"
echo
echo -e "${C_LGn}Arguments${RES} - any ports to open separated by spaces"
echo
# echo -e "${C_LGn}Useful URLs${RES}:"
# echo -e "https://github.com/SecorD0/utils/blob/main/miscellaneous/ports_opening.sh - script URL"
# echo -e "https://t.me/letskynode — node Community"
echo
return 0 2>/dev/null; exit 0
;;
*|--)
break
;;
esac
done
# Functions
main() {
echo -e "${C_LGn}Port(s) opening...${RES}"
if sudo ufw status | grep -q "Status: active"; then
sudo ufw allow 22
for open_this_port in "$@"; do
echo "$open_this_port"
sudo ufw allow "$open_this_port"
done
else
if ! dpkg --get-selections | grep -qP "(?<=iptables-persistent)([^de]+)(?=install)"; then
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
sudo apt install iptables-persistent -y
fi
for open_this_port in "$@"; do
echo "$open_this_port"
sudo iptables -I INPUT -p tcp --dport "$open_this_port" -j ACCEPT
done
sudo netfilter-persistent save
fi
unset open_this_port
echo -e "${C_LGn}Done!${RES}"
}
# Actions
main "$@"
+60
View File
@@ -0,0 +1,60 @@
#!/bin/bash
# Options
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/colors.sh) --
option_value(){ echo "$1" | sed -e 's%^--[^=]*=%%g; s%^-[^=]*=%%g'; }
while test $# -gt 0; do
case "$1" in
-h|--help)
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/logo.sh)
echo
echo -e "${C_LGn}Functionality${RES}: the script measures commands execution speed"
echo
echo -e "${C_LGn}Usage${RES}: script ${C_LGn}[OPTIONS]${RES} ${C_LGn}[ARGUMENTS]${RES}"
echo
echo -e "${C_LGn}Options${RES}:"
echo -e " -h, --help show the help page"
echo
echo -e "${C_LGn}Arguments${RES} - any commands as strings separated by spaces. For example: \"df\" 'ls -la'"
echo
# echo -e "${C_LGn}Useful URLs${RES}:"
# echo -e "https://github.com/SecorD0/utils/blob/main/miscellaneous/speed_test.sh - script URL"
# echo -e "https://t.me/letskynode — node Community"
echo
return 0 2>/dev/null; exit 0
;;
-t|--total)
total="true"
shift
;;
*|--)
break
;;
esac
done
# Functions
printf_n(){ printf "$1\n" "${@:2}"; }
main() {
sudo apt install bc -y &>/dev/null
local commands_l=()
local runtime_l=()
for command in "$@"; do
commands_l+=("$command")
done
for command in "$@"; do
local command_start=$(date +%s.%N)
eval $command
. $HOME/.bash_profile
runtime_l+=(`bc <<< "$(date +%s.%N)-$command_start"`)
done
printf_n "\n\n${C_LGn}Time taken (s)${RES}\t| Command\n------------------------------------"
local sum=0.00
for ((i = 0; i < "${#commands_l[@]}"; i++)); do
printf_n "${C_LGn}%f${RES}\t| ${commands_l[$i]}" "${runtime_l[$i]}"
local sum=`bc <<< "$sum+${runtime_l[$i]}"`
done
printf_n "${C_LGn}%f${RES}\t| Total" "$sum"
}
# Actions
main "$@"