Browse Source

Add composer installer script

Robert Zollner 5 years ago
parent
commit
d0b1b0742b
1 changed files with 77 additions and 0 deletions
  1. 77 0
      bin/v-add-user-composer

+ 77 - 0
bin/v-add-user-composer

@@ -0,0 +1,77 @@
+#!/bin/bash
+# info: add composer (php dependency manager) for a user
+# options: USER
+#
+# The function adds support for composer (php dependency manager)
+# Homepage: https://getcomposer.org/
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+user=$1
+
+if [ -z "$HESTIA" ]; then
+    HESTIA="/usr/local/hestia"
+fi
+source $HESTIA/func/main.sh
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+check_args '1' "$#" 'USER'
+is_format_valid 'user'
+is_object_valid 'user' 'USER' "$user"
+is_object_unsuspended 'user' 'USER' "$user"
+
+[ -z "$HOMEDIR" ] && check_result $E_NOTEXIST "Hestia environment vars not present"
+
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+COMPOSER_DIR="$HOMEDIR/$user/.composer"
+COMPOSER_BIN="$COMPOSER_DIR/composer"
+
+if [ -f "$COMPOSER_BIN" ]; then
+    echo "Composer already available"
+    exit
+fi
+
+mkdir -p "$COMPOSER_DIR"
+chown $user: "$COMPOSER_DIR"
+
+COMPOSER_SETUP_FILE=$(mktemp)
+check_result $? "Create temp file"
+chown $user: "$COMPOSER_SETUP_FILE"
+
+signature="$(curl --silent --show-error https://composer.github.io/installer.sig)"
+check_result $? "Download signature"
+
+user_exec wget --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache https://getcomposer.org/installer --quiet -O "$COMPOSER_SETUP_FILE"
+check_result $? "Download composer installer"
+
+if [[ "$signature" != $(sha384sum $COMPOSER_SETUP_FILE | cut -f 1 -d " ") ]]; then
+    rm -f "$COMPOSER_SETUP_FILE"
+    check_result $E_INVALID "Composer signature does not match"
+fi
+
+COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php "$COMPOSER_SETUP_FILE" --quiet --install-dir="$COMPOSER_DIR" --filename=composer
+check_result $? "Composer install failed"
+
+[ -f "$COMPOSER_SETUP_FILE" ] && rm -f "$COMPOSER_SETUP_FILE"
+
+
+# Logging
+log_history "Enabled composer for user $user"
+log_event "$OK" "$ARGUMENTS"
+
+exit