Skip to content

Commit

Permalink
feat: add podman/fedora specific args to setup.sh; rename HIVE_CLI_PO…
Browse files Browse the repository at this point in the history
…RT to HIVE_PORT
  • Loading branch information
aleneum committed Dec 12, 2024
1 parent f17b117 commit 2b33dd3
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ func_def=$(cat <<EOF
function hive_cli() {
DOCKER_SOCKET=\${DOCKER_SOCKET:-/var/run/docker.sock}
DOCKER_AUTH=\${DOCKER_AUTH:-\$HOME/.docker/config.json}
HIVE_CLI_PORT=\${HIVE_CLI_PORT:-12121}
if [ -z \${DOCKER_EXTRA_ARGS} ]; then
if [ \$(grep -c "podman.sock" <<< "\$DOCKER_SOCKET") -eq 1 ]; then
DOCKER_EXTRA_ARGS="--userns=keep-id --security-opt label:type:container_runtime_t"
fi
fi
HIVE_PORT=\${HIVE_PORT:-12121}
if [ ! -f \${DOCKER_AUTH} ]; then
echo "❌ Could not find docker auth file at \${DOCKER_AUTH}."
echo "Please set the DOCKER_AUTH environment variable manually."
Expand All @@ -24,12 +29,14 @@ function hive_cli() {
docker login ghcr.io
docker volume create hive > /dev/null
docker run -ti --rm \\
-p \${HIVE_CLI_PORT}:443 \\
-p \${HIVE_PORT}:\${HIVE_PORT} \\
-v hive:/workspace/hive \\
-v \${DOCKER_SOCKET}:/var/run/docker.sock \\
-v \${DOCKER_AUTH}:/docker_config.json \\
-e UID=\$(id -u) \\
-e GID=\${DOCKER_SOCKET_GID} \\
-e HIVE_PORT=\${HIVE_PORT} \\
\${DOCKER_EXTRA_ARGS} \\
ghcr.io/caretech-owl/hive-cli
res_code=\$?
echo "Exited with code \${res_code}"
Expand All @@ -43,27 +50,37 @@ function hive_cli() {
EOF
)

hook_def=$(cat <<EOF
. \$HOME/.hive/cli.sh
EOF
)

echo "Create or override $HOME/.hive/cli.sh"
mkdir -p $HOME/.hive
echo "$func_def" > $HOME/.hive/cli.sh


if [ -f ~/.bashrc ]; then
if [ $(grep -c "function hive_cli()" ~/.bashrc) -eq 0 ]; then
echo "✅ Adding hive_cli function to .bashrc ..."
echo "$func_def" >> ~/.bashrc
if [ $(grep -c ".hive/cli.sh" ~/.bashrc) -eq 0 ]; then
echo "✅ Adding hive_cli hook to .bashrc ..."
echo "$hook_def" >> ~/.bashrc
else
echo "ℹ️ hive_cli function already exists in .bashrc"
echo "ℹ️ hive_cli hook already exists in .bashrc"
fi
elif [ -f ~/.bash_profile ]; then
if [ $(grep -c "function hive_cli()" ~/.bash_profile) -eq 0 ]; then
echo "✅ Adding hive_cli function to .bash_profile ..."
echo "$func_def" >> ~/.bash_profile
if [ $(grep -c ".hive/cli.sh" ~/.bash_profile) -eq 0 ]; then
echo "✅ Adding hive_cli hook to .bash_profile ..."
echo "$hook_def" >> ~/.bash_profile
else
echo "ℹ️ hive_cli function already exists in .bash_profile"
echo "ℹ️ hive_cli hook already exists in .bash_profile"
fi
fi
if [ -f ~/.zshrc ]; then
if [ $(grep -c "function hive_cli()" ~/.zshrc) -eq 0 ]; then
echo "✅ Adding hive_cli function to .zshrc ..."
echo "$func_def" >> ~/.zshrc
if [ $(grep -c ".hive/cli.sh" ~/.zshrc) -eq 0 ]; then
echo "✅ Adding hive_cli hook to .zshrc ..."
echo "$hook_def" >> ~/.zshrc
else
echo "ℹ️ hive_cli function already exists in .zshrc"
echo "ℹ️ hive_cli hook already exists in .zshrc"
fi
fi

Expand Down

0 comments on commit 2b33dd3

Please sign in to comment.