├── scripts └── rmhost ├── README.md └── install.sh /scripts/rmhost: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | host="$1" 4 | 5 | [ $# -eq 0 ] && { echo "Usage: rmhost HOSTNAME"; exit 1; } 6 | 7 | ips=$(host "$host" | awk -F'address' '{ print $2}' | sed -e 's/^ //g') 8 | ssh-keygen -R "$host" 9 | 10 | for ip in $ips; do 11 | ssh-keygen -R "$ip" 12 | done 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Script utilities 2 | ================ 3 | 4 | Script utilities to be used as system commands 5 | 6 | ## Usage 7 | 8 | ### Method one 9 | 10 | Download specific scripts from the ````scripts```` directory to your path. 11 | 12 | ### Method two 13 | 14 | Clone this repository and run ````./install.sh [-p PATH] [-b] [SCRIPT1 [SCRIPT2]]```` 15 | 16 | Don't pass any scriptname for installing all scripts 17 | 18 | Put ````source PATH/utilities.sh```` in your bash login script 19 | 20 | ````PATH```` is ````/usr/bin```` by default. -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script to install utilities 4 | # Author: Márk Sági-Kazár (sagikazarmark@gmail.com) 5 | # This script install all or specific utilities 6 | # 7 | # Version: 1.0 8 | 9 | DIR=$(cd `dirname $0` && pwd) 10 | path="${path:-/usr/bin}" 11 | BUILD=${BUILD:-0} 12 | 13 | # Echo colored text 14 | e() 15 | { 16 | local color="\033[${2:-34}m" 17 | echo -e "$color$1\033[0m" 18 | } 19 | 20 | ## Exit error 21 | ee() 22 | { 23 | local exit_code="${2:-1}" 24 | local color="${3:-31}" 25 | 26 | e "$1" "$color" 27 | exit $exit_code 28 | } 29 | 30 | ## Set path 31 | setpath() 32 | { 33 | [ -z "$1" ] || path="$1" 34 | 35 | if [ -d $path -a -w $path ]; then 36 | e "Path is set to $path" 37 | else 38 | ee "Please specify a valid and writable path" 39 | fi 40 | } 41 | 42 | # Checking root access 43 | if [ $EUID -ne 0 ]; then 44 | e "You are not running this script as root!" 31 45 | fi 46 | 47 | 48 | while getopts p:b option; do 49 | case "${option}" in 50 | p ) 51 | setpath ${OPTARG} 52 | ;; 53 | b ) 54 | BUILD=1 55 | ;; 56 | esac 57 | done 58 | 59 | shift $((OPTIND-1)) 60 | 61 | 62 | if [[ -z "$scripts" && $BUILD -eq 0 ]]; then 63 | e "Installing all scripts" 64 | scripts=("$DIR/scripts"/*) 65 | else 66 | IFS=' ' read -a scripts <<< "${scripts}" 67 | fi 68 | 69 | 70 | if [ $BUILD -eq 1 ]; then 71 | e "Compiling all scripts" 72 | BUILD="#!/bin/bash\n\n# Compiled script from several utilities.\n# Path: $path\n# Date: $(date +"%Y-%m-%d %H:%M:%S")\n" 73 | 74 | for script in "${scripts[@]}"; do 75 | script=`basename $script` 76 | if [[ -f "$DIR/scripts/$script" && -s "$DIR/scripts/$script" ]]; then 77 | e "\nCompiling $script" 78 | BUILD="$BUILD\n\n$script()\n{\n" 79 | 80 | while read line; do 81 | if [[ "$line" == \#* || "$line" == "" ]]; then 82 | continue 83 | fi 84 | 85 | line="${line//exit/return}" 86 | BUILD="$BUILD$line\n" 87 | done < "$DIR/scripts/$script" 88 | BUILD="$BUILD}" 89 | 90 | e "$script compiled" 32 91 | else 92 | e "\nScript $script not found or empty" 31 93 | fi 94 | done 95 | 96 | echo -e "$BUILD" > "$path/utilities.sh" 97 | 98 | if [ ! -x "$path/utilities.sh" ]; then 99 | e "\nAdding execute permission to $path/utilities.sh" 100 | chmod +x "$path/utilities.sh" || e "Cannot add execute permission to $path/utilities.sh" 31 101 | fi 102 | 103 | grep -R "[ -f $path/utilities.sh ] && source $path/utilities.sh" /etc/bash.bashrc &> /dev/null 104 | [ $? -eq 0 ] || echo -e "[ -f $path/utilities.sh ] && source $path/utilities.sh" >> /etc/bash.bashrc 105 | 106 | 107 | e "\nCompilation done." 32 108 | else 109 | for script in "${scripts[@]}"; do 110 | script=`basename $script` 111 | if [[ -f "$DIR/scripts/$script" && -s "$DIR/scripts/$script" ]]; then 112 | e "\nInstalling $script" 113 | cp -r "$DIR/scripts/$script" "$path" || e "Installing $script failed" 31 114 | 115 | if [ ! -x "$path/$script" ]; then 116 | e "Adding execute permission to $script" 117 | chmod +x "$script" || e "Cannot add execute permission to $script" 31 118 | fi 119 | e "$script installed" 32 120 | else 121 | e "\nScript $script not found" 31 122 | fi 123 | done 124 | e "\nInstallation done." 32 125 | fi 126 | --------------------------------------------------------------------------------