#! /bin/bash # Make sure the setup script is running from this directory ORIGDIR="$(pwd)" cd "$(dirname "$0")" # Ensure the spec submodule was cloned if [ ! -f spec/README.md ]; then echo "git submodule was not initialized before. Doing it now" git submodule init if ! git submodule update; then echo "Failed to download git submodule. Aborting setup!" exit 1 fi fi # Copy the translations to ~/.local/share/forgebuild FORGEBUILD_DATA=$HOME/.local/share/forgebuild if [ ! -d $FORGEBUILD_DATA ]; then if ! mkdir -p $FORGEBUILD_DATA; then echo "Failed to create folder $FORGEBUILD_DATA to store translations" exit 2 fi fi if ! cp -r spec/i18n $FORGEBUILD_DATA; then echo "Failed to copy translations to $FORGEBUILD_DATA" exit 3 else echo "Successfully updated translations in $FORGEBUILD_DATA" fi I18N_FOLDER=$FORGEBUILD_DATA/i18n # Check if forgebuild already exists in $PATH FORGEBUILD_BIN="$(command -v forgebuild)" if [ $? -eq 0 ]; then echo "forgebuild is already setup on this system. Performing an update." owner="$(ls -ld $FORGEBUILD_BIN | awk '{print $3}')" # Check ownership to ensure we can overwrite the file if [[ $owner = "$USER" ]]; then cp forgebuild.sh $FORGEBUILD_BIN || exit 3 echo "Successfully updated forgebuild" else # File is not ours, we need to escalate privileges if ! sudo cp forgebuild.sh $FORGEBUILD_BIN; then echo "Failed to escalate privileges to setup forgebuild. Are you sure sudo is configured properly?" exit 4 fi echo "Successfully updated forgebuild" fi else echo "forgebuild was not setup before. Installing it in the first writable folder in \$PATH." SETUP=0 while read -d ':' -r dir; do if [ -w $dir ]; then cp forgebuild.sh $dir/forgebuild echo "Successfully installed forgebuild to $dir" SETUP=1 break fi done <<< $PATH if [ $SETUP -eq 0 ]; then echo "No writable folder in \$PATH. Installing to /usr/local/bin (using sudo)" if ! sudo cp forgebuild.sh /usr/local/bin/forgebuild; then echo "Failed to escalate privileges to setup forgebuild. Are you sure sudo is configured properly?" exit 5 fi fi fi # Return to the folder the script was called from cd "$ORIGDIR"