|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +_fail () { |
| 4 | + echo $'Could not generate salt automatically.\nPlease enter a 16-64 length random alphanumerical string to "SteamIdHashSalt=" option in reunion.cfg.' |
| 5 | + return 1 |
| 6 | +} |
| 7 | + |
| 8 | +_success() { |
| 9 | + if grep -e ^"SteamIdHashSalt\s*=" reunion.cfg 2>&1 >/dev/null; then |
| 10 | + sed -i "s/SteamIdHashSalt\s*=.*/SteamIdHashSalt = $SALT/g" reunion.cfg 2>&1 >/dev/null |
| 11 | + else |
| 12 | + echo "SteamIdHashSalt = $SALT" >> reunion.cfg |
| 13 | + fi |
| 14 | + if ! grep ^"SteamIdHashSalt = $SALT" reunion.cfg 2>&1 >/dev/null; then |
| 15 | + echo [fail] |
| 16 | + _fail |
| 17 | + return 1 |
| 18 | + fi |
| 19 | + echo [ok] |
| 20 | + echo "Done. \"SteamIdHashSalt = $SALT\" generated successfully and written to reunion.cfg." |
| 21 | + return 0 |
| 22 | +} |
| 23 | + |
| 24 | +SALT= |
| 25 | + |
| 26 | +if [ ! -f reunion.cfg ]; then |
| 27 | + echo Error: reunion.cfg does not exist in the current directory! |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +echo -n "Testing for grep ... " |
| 32 | +if ! command -v grep 2>&1 >/dev/null; then |
| 33 | + echo [fail] |
| 34 | + _fail |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | +echo [ok] |
| 38 | + |
| 39 | +echo -n "Testing for wc ... " |
| 40 | +if ! command -v wc 2>&1 >/dev/null; then |
| 41 | + echo [fail] |
| 42 | + _fail |
| 43 | + exit 1 |
| 44 | +fi |
| 45 | +echo [ok] |
| 46 | + |
| 47 | +echo -n "Testing for sed ... " |
| 48 | +if ! command -v sed 2>&1 >/dev/null; then |
| 49 | + echo [fail] |
| 50 | + _fail |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | +echo [ok] |
| 54 | + |
| 55 | +echo -n "Testing for openssl ... " |
| 56 | +if command -v openssl 2>&1 >/dev/null; then |
| 57 | + echo [ok] |
| 58 | + echo -n "Generating salt ... " |
| 59 | + SALT="$(openssl rand -hex 16)" |
| 60 | + if [ "$(echo "$SALT" | wc -c)" -gt 31 ]; then |
| 61 | + _success |
| 62 | + exit $? |
| 63 | + else |
| 64 | + echo [fail] |
| 65 | + fi |
| 66 | +else |
| 67 | + echo [not found] |
| 68 | +fi |
| 69 | + |
| 70 | +echo -n "Testing for /dev/urandom ... " |
| 71 | +if [ ! -e /dev/urandom ]; then |
| 72 | + echo [fail] |
| 73 | + _fail |
| 74 | + exit 1 |
| 75 | +fi |
| 76 | +echo [ok] |
| 77 | + |
| 78 | +echo -n "Testing for hexdump ... " |
| 79 | +if command -v hexdump 2>&1 >/dev/null; then |
| 80 | + echo [ok] |
| 81 | + echo -n "Generating salt ... " |
| 82 | + SALT="$(hexdump -vn16 -e'4/4 "%08x"' /dev/urandom)" |
| 83 | + if [ "$(echo "$SALT" | wc -c)" -gt 31 ]; then |
| 84 | + _success |
| 85 | + exit $? |
| 86 | + else |
| 87 | + echo [fail] |
| 88 | + fi |
| 89 | +else |
| 90 | + echo [not found] |
| 91 | +fi |
| 92 | + |
| 93 | +echo -n "Testing for xxd ... " |
| 94 | +if command -v xxd 2>&1 >/dev/null; then |
| 95 | + echo [ok] |
| 96 | + echo -n "Generating salt ... " |
| 97 | + SALT="$(xxd -l 16 -p /dev/urandom)" |
| 98 | + if [ "$(echo "$SALT" | wc -c)" -gt 31 ]; then |
| 99 | + _success |
| 100 | + exit $? |
| 101 | + else |
| 102 | + echo [fail] |
| 103 | + fi |
| 104 | +else |
| 105 | + echo [not found] |
| 106 | +fi |
| 107 | + |
| 108 | +echo -n "Testing for tr ... " |
| 109 | +if command -v tr 2>&1 >/dev/null; then |
| 110 | + echo [ok] |
| 111 | + echo -n "Generating salt ... " |
| 112 | + SALT="$(tr -dc 'a-f0-9' < /dev/urandom | head -c32)" |
| 113 | + if [ "$(echo "$SALT" | wc -c)" -gt 31 ]; then |
| 114 | + _success |
| 115 | + exit $? |
| 116 | + else |
| 117 | + echo [fail] |
| 118 | + fi |
| 119 | +else |
| 120 | + echo [not found] |
| 121 | +fi |
| 122 | +_fail |
| 123 | +exit 1 |
| 124 | + |
0 commit comments