Compare commits
No commits in common. "main" and "v31" have entirely different histories.
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -63,7 +63,6 @@
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp",
|
||||
"format": "cpp",
|
||||
"__nullptr": "cpp",
|
||||
"codecvt": "cpp"
|
||||
"__nullptr": "cpp"
|
||||
}
|
||||
}
|
64
bb64.cpp
64
bb64.cpp
@ -36,41 +36,6 @@ constexpr unsigned int hash(const char *s, int off = 0)
|
||||
return !s[off] ? 5381 : (hash(s, off + 1) * 33) ^ s[off];
|
||||
}
|
||||
|
||||
std::string tidy(const std::string &str)
|
||||
{
|
||||
std::string result;
|
||||
bool in_whitespace = false;
|
||||
for (char c : str)
|
||||
{
|
||||
// Remove non-printable characters except for whitespace (space, tab, newline, carriage return)
|
||||
if ((static_cast<unsigned char>(c) < 32 && c != ' ' && c != '\t' && c != '\n' && c != '\r') || static_cast<unsigned char>(c) == 127)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
|
||||
{
|
||||
if (!in_whitespace)
|
||||
{
|
||||
result += ' ';
|
||||
in_whitespace = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result += c;
|
||||
in_whitespace = false;
|
||||
}
|
||||
}
|
||||
// Remove leading whitespace
|
||||
size_t start = result.find_first_not_of(' ');
|
||||
if (start == std::string::npos)
|
||||
return "";
|
||||
// Remove trailing whitespace
|
||||
size_t end = result.find_last_not_of(' ');
|
||||
return result.substr(start, end - start + 1);
|
||||
}
|
||||
|
||||
|
||||
std::string get_arch()
|
||||
{
|
||||
// determine the architecture of the system
|
||||
@ -143,14 +108,9 @@ int main(int argc, char *argv[])
|
||||
Usage:
|
||||
bb64 BASE64COMMAND Decodes and runs the command
|
||||
bb64 -[i|d] BASE64COMMAND Displays the decoded command
|
||||
|
||||
bb64 -e COMMAND Encodes the command and prints the base64 encoded result
|
||||
bb64 -e Encodes the command provided on stdin and prints the result
|
||||
|
||||
bb64 -e COMMAND Encodes the command and prints the result
|
||||
bb64 -u Updates bb64 to the latest version (uses docker)
|
||||
|
||||
bb64 -v Prints the version number
|
||||
|
||||
)" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
@ -161,30 +121,11 @@ Usage:
|
||||
{
|
||||
if (mode == "-u")
|
||||
return update_bb64();
|
||||
else if (mode == "-v")
|
||||
{
|
||||
std::cout << VERSION << std::endl;
|
||||
return 0;
|
||||
}
|
||||
else if (mode == "-e")
|
||||
{
|
||||
std::ostringstream oss;
|
||||
while (std::cin)
|
||||
{
|
||||
std::string line;
|
||||
std::getline(std::cin, line);
|
||||
oss << line << std::endl;
|
||||
}
|
||||
std::string tidier = tidy(oss.str());
|
||||
std::cout << base64_encode(tidier) << std::endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return decode_and_run(mode);
|
||||
}
|
||||
|
||||
std::ostringstream oss;
|
||||
std::string tidier;
|
||||
|
||||
switch (hash(mode.c_str()))
|
||||
{
|
||||
@ -197,8 +138,7 @@ Usage:
|
||||
case hash("-e"):
|
||||
for (int i = 2; i < argc; ++i)
|
||||
oss << (i > 2 ? " " : "") << argv[i];
|
||||
tidier = tidy(oss.str());
|
||||
std::cout << base64_encode(tidier) << std::endl;
|
||||
std::cout << base64_encode(oss.str()) << std::endl;
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Invalid mode: " << mode << std::endl;
|
||||
|
5
build.sh
5
build.sh
@ -8,7 +8,12 @@ mkdir -p "$OUTPUT_DIR"
|
||||
# Build for x86_64 with musl static linking
|
||||
if [[ $(uname -m) == "x86_64" ]]; then
|
||||
echo "Building for x86_64 (musl static)..."
|
||||
if command -v x86_64-linux-musl-g++ &>/dev/null; then
|
||||
x86_64-linux-musl-g++ -O2 -static -o "$OUTPUT_DIR/bb64.amd64" bb64.cpp b64ed.cpp
|
||||
else
|
||||
g++ -O2 -static -o "$OUTPUT_DIR/bb64.amd64" bb64.cpp b64ed.cpp -static-libgcc -static-libstdc++
|
||||
echo "Warning: musl-g++ not found, built with g++ static flags."
|
||||
fi
|
||||
echo "Built bb64.amd64 (x86_64, static)"
|
||||
fi
|
||||
|
||||
|
20
install.sh
20
install.sh
@ -20,12 +20,6 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
# 0. see if we were passed a user to chown to
|
||||
# -----------------------------------------------------------------------------
|
||||
CHOWN_USER="$2"
|
||||
if [[ -z "$CHOWN_USER" ]]; then
|
||||
CHOWN_USER=$(id -u)
|
||||
fi
|
||||
|
||||
# 1. Determine architecture
|
||||
# -----------------------------------------------------------------------------
|
||||
@ -55,15 +49,15 @@ chmod +x "$TMPDIR/bb64"
|
||||
|
||||
# 5. Move to /usr/local/bin
|
||||
# -----------------------------------------------------------------------------
|
||||
docker run --rm -v "$TMPDIR:/tmp" -v "$INSTALL_DIR:/target" alpine sh -c "cp /tmp/bb64 /target/bb64; chown $CHOWN_USER /target/bb64"
|
||||
docker run --rm -v "$TMPDIR:/tmp" -v "$INSTALL_DIR:/target" alpine sh -c "cp /tmp/bb64 /target/bb64"
|
||||
rm "$TMPDIR/bb64"
|
||||
|
||||
# 6. Print success message
|
||||
# -----------------------------------------------------------------------------
|
||||
echo "bb64 installed successfully to $INSTALL_DIR/bb64 (arch $ARCH)"
|
||||
# echo " "
|
||||
# echo "Update bb64 with:"
|
||||
# echo " bb64 -u"
|
||||
# echo " "
|
||||
# echo "try it out with:"
|
||||
# echo " bb64 ZWNobyAiSGVsbG8td29ybGQhIGJiNjQgaXMgd29ya2luZy4i"
|
||||
echo " "
|
||||
echo "Update bb64 with:"
|
||||
echo " bb64 -u"
|
||||
echo " "
|
||||
echo "try it out with:"
|
||||
echo " bb64 ZWNobyAiSGVsbG8td29ybGQhIGJiNjQgaXMgd29ya2luZy4i"
|
||||
|
@ -17,9 +17,8 @@ if [ ! -f version.h ]; then
|
||||
exit 1
|
||||
else
|
||||
v=$(cat version.h | grep -o 'static const char \*VERSION = "[0-9.]*";' | cut -d'"' -f2)
|
||||
oldv=$v
|
||||
v=$((v+1))
|
||||
echo "Incrementing version from $oldv to $v" >&2
|
||||
echo "Incrementing version from $v to $v" >&2
|
||||
echo "static const char *VERSION = \"$v\";" > version.h
|
||||
fi
|
||||
TAG="v$v"
|
||||
|
Loading…
x
Reference in New Issue
Block a user