feat refactor: make bugfixes and split part of the core script into new scripts

This commit is contained in:
prplwtf 2024-06-23 16:38:57 +02:00
parent 2898004ed5
commit 8500b8c489
11 changed files with 1766 additions and 1684 deletions

1
.gitignore vendored
View file

@ -41,3 +41,4 @@ docker-compose.yaml
# Ignore Blueprint internal folder and extensions # Ignore Blueprint internal folder and extensions
.blueprint/ .blueprint/
*.blueprint *.blueprint
!scripts/commands/misc

View file

@ -1,5 +1,6 @@
disable=SC1091 disable=SC1091
disable=SC2153 disable=SC2153
disable=SC2154 disable=SC2154
disable=SC2034
external-sources=true external-sources=true

File diff suppressed because it is too large Load diff

View file

@ -1,7 +0,0 @@
#!/bin/bash
#
# This script has been created as part of the Blueprint source code
# and uses the same license as the rest of the codebase.
_blueprint="-install -remove -init -build -export -wipe -version -help -info -debug -upgrade -rerun-install"
complete -W "${_blueprint}" 'blueprint'

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,354 @@
#!/bin/bash
RemoveCommand() {
# Check if the extension is installed.
FILE=$1
if [[ $FILE == *".blueprint" ]]; then FILE="${FILE::-10}"; fi
set -- "${@:1:2}" "$FILE" "${@:4}"
if [[ $(cat ".blueprint/extensions/blueprint/private/db/installed_extensions") != *"$1,"* ]]; then
PRINT FATAL "'$1' is not installed or detected."
exit 2
fi
if [[ -f ".blueprint/extensions/$1/private/.store/conf.yml" ]]; then
eval "$(parse_yaml ".blueprint/extensions/$1/private/.store/conf.yml" conf_)"
# Add aliases for config values to make working with them easier.
name="${conf_info_name//&/\\&}"
identifier="${conf_info_identifier//&/\\&}"
description="${conf_info_description//&/\\&}"
flags="${conf_info_flags//&/\\&}" #(optional)
version="${conf_info_version//&/\\&}"
target="${conf_info_target//&/\\&}"
author="${conf_info_author//&/\\&}" #(optional)
icon="${conf_info_icon//&/\\&}" #(optional)
website="${conf_info_website//&/\\&}"; #(optional)
admin_view="$conf_admin_view"
admin_controller="$conf_admin_controller"; #(optional)
admin_css="$conf_admin_css"; #(optional)
admin_wrapper="$conf_admin_wrapper"; #(optional)
dashboard_css="$conf_dashboard_css"; #(optional)
dashboard_wrapper="$conf_dashboard_wrapper"; #(optional)
dashboard_components="$conf_dashboard_components"; #(optional)
data_directory="$conf_data_directory"; #(optional)
data_public="$conf_data_public"; #(optional)
data_console="$conf_data_console"; #(optional)
requests_views="$conf_requests_views"; #(optional)
requests_controllers="$conf_requests_controllers"; #(optional)
requests_routers="$conf_requests_routers"; #(optional)
requests_routers_application="$conf_requests_routers_application"; #(optional)
requests_routers_client="$conf_requests_routers_client"; #(optional)
requests_routers_web="$conf_requests_routers_web"; #(optional)
database_migrations="$conf_database_migrations"; #(optional)
else
PRINT FATAL "Extension configuration file not found or detected."
exit 1
fi
if [[ $USER_CONFIRMED_REMOVAL != "yes" ]]; then
PRINT INPUT "Do you want to proceed with this transaction? Some files might not be removed properly. (y/N)"
read -r YN
if [[ ( ( ${YN} != "y"* ) && ( ${YN} != "Y"* ) ) || ( ( ${YN} == "" ) ) ]]; then PRINT INFO "Extension removal cancelled.";exit 1;fi
fi
export USER_CONFIRMED_REMOVAL="yes"
PRINT INFO "Searching and validating framework dependencies.."
depend
# Assign variables to extension flags.
PRINT INFO "Reading and assigning extension flags.."
assignflags
if $F_hasRemovalScript; then
PRINT WARNING "Extension uses a custom removal script, proceed with caution."
chmod +x ".blueprint/extensions/$identifier/private/remove.sh"
# Run script while also parsing some useful variables for the uninstall script to use.
su "$WEBUSER" -s "$USERSHELL" -c "
cd \"$FOLDER\";
EXTENSION_IDENTIFIER=\"$identifier\" \
EXTENSION_TARGET=\"$target\" \
EXTENSION_VERSION=\"$version\" \
PTERODACTYL_DIRECTORY=\"$FOLDER\" \
BLUEPRINT_VERSION=\"$VERSION\" \
bash .blueprint/extensions/$identifier/private/remove.sh
"
echo -e "\e[0m\x1b[0m\033[0m"
fi
# Remove admin button
PRINT INFO "Editing 'extensions' admin page.."
sed -n -i "/<!--@$identifier:s@-->/{p; :a; N; /<!--@$identifier:e@-->/!ba; s/.*\n//}; p" "resources/views/admin/extensions.blade.php"
sed -i \
-e "s~<!--@$identifier:s@-->~~g" \
-e "s~<!--@$identifier:e@-->~~g" \
"resources/views/admin/extensions.blade.php"
# Remove admin routes
PRINT INFO "Removing admin routes.."
sed -n -i "/\/\/ $identifier:start/{p; :a; N; /\/\/ $identifier:stop/!ba; s/.*\n//}; p" "routes/blueprint.php"
sed -i \
-e "s~// $identifier:start~~g" \
-e "s~// $identifier:stop~~g" \
"routes/blueprint.php"
# Remove admin view and controller
PRINT INFO "Removing admin view and controller.."
rm -r \
"resources/views/admin/extensions/$identifier" \
"app/Http/Controllers/Admin/Extensions/$identifier"
# Remove admin css
if [[ $admin_css != "" ]]; then
PRINT INFO "Removing and unlinking admin css.."
updateCacheReminder
sed -i "s~@import url(/assets/extensions/$identifier/admin.style.css);~~g" ".blueprint/extensions/blueprint/assets/admin.extensions.css"
fi
# Remove admin wrapper
if [[ $admin_wrapper != "" ]]; then
PRINT INFO "Removing and unlinking admin wrapper.."
rm "resources/views/blueprint/admin/wrappers/$identifier.blade.php";
fi
# Remove dashboard wrapper
if [[ $dashboard_wrapper != "" ]]; then
PRINT INFO "Removing and unlinking dashboard wrapper.."
rm "resources/views/blueprint/dashboard/wrappers/$identifier.blade.php";
fi
# Remove dashboard css
if [[ $dashboard_css != "" ]]; then
PRINT INFO "Removing and unlinking dashboard css.."
sed -i "s~@import url(./imported/$identifier.css);~~g" "resources/scripts/blueprint/css/extensions.css"
rm "resources/scripts/blueprint/css/imported/$identifier.css"
YARN="y"
fi
# Remove dashboard components
if [[ $dashboard_components != "" ]]; then
PRINT INFO "Removing and unlinking dashboard components.."
# fetch component config
eval "$(parse_yaml .blueprint/extensions/"$identifier"/components/Components.yml Components_)"
# define static variables to make stuff a bit easier
im="\/\* blueprint\/import \*\/"; re="{/\* blueprint\/react \*/}"; co="resources/scripts/blueprint/components"
s="import ${identifier^}Component from '"; e="';"
REMOVE_REACT() {
if [[ ! $1 == "" ]]; then
# remove components
sed -i \
-e "s~""${s}@/blueprint/extensions/${identifier}/$1${e}""~~g" \
-e "s~""<${identifier^}Component />""~~g" \
"$co"/"$2"
fi
}
# remove component items
# -> REMOVE_REACT "$Components_" "path/.tsx" "$OldComponents_"
# navigation
REMOVE_REACT "$Components_Navigation_NavigationBar_BeforeNavigation" "Navigation/NavigationBar/BeforeNavigation.tsx"
REMOVE_REACT "$Components_Navigation_NavigationBar_AdditionalItems" "Navigation/NavigationBar/AdditionalItems.tsx"
REMOVE_REACT "$Components_Navigation_NavigationBar_AfterNavigation" "Navigation/NavigationBar/AfterNavigation.tsx"
REMOVE_REACT "$Components_Navigation_SubNavigation_BeforeSubNavigation" "Navigation/SubNavigation/BeforeSubNavigation.tsx"
REMOVE_REACT "$Components_Navigation_SubNavigation_AdditionalServerItems" "Navigation/SubNavigation/AdditionalServerItems.tsx"
REMOVE_REACT "$Components_Navigation_SubNavigation_AdditionalAccountItems" "Navigation/SubNavigation/AdditionalAccountItems.tsx"
REMOVE_REACT "$Components_Navigation_SubNavigation_AfterSubNavigation" "Navigation/SubNavigation/AfterSubNavigation.tsx"
# dashboard
REMOVE_REACT "$Components_Dashboard_ServerRow_BeforeEntryName" "Dashboard/ServerRow/BeforeEntryName.tsx"
REMOVE_REACT "$Components_Dashboard_ServerRow_AfterEntryName" "Dashboard/ServerRow/AfterEntryName.tsx"
REMOVE_REACT "$Components_Dashboard_ServerRow_BeforeEntryDescription" "Dashboard/ServerRow/BeforeEntryDescription.tsx"
REMOVE_REACT "$Components_Dashboard_ServerRow_AfterEntryDescription" "Dashboard/ServerRow/AfterEntryDescription.tsx"
REMOVE_REACT "$Components_Dashboard_ServerRow_ResourceLimits" "Dashboard/ServerRow/ResourceLimits.tsx"
# authentication
REMOVE_REACT "$Components_Authentication_Container_BeforeContent" "Authentication/Container/BeforeContent.tsx"
REMOVE_REACT "$Components_Authentication_Container_AfterContent" "Authentication/Container/AfterContent.tsx"
# server
REMOVE_REACT "$Components_Server_Terminal_BeforeContent" "Server/Terminal/BeforeContent.tsx"
REMOVE_REACT "$Components_Server_Terminal_AdditionalPowerButtons" "Server/Terminal/AdditionalPowerButtons.tsx"
REMOVE_REACT "$Components_Server_Terminal_BeforeInformation" "Server/Terminal/BeforeInformation.tsx"
REMOVE_REACT "$Components_Server_Terminal_AfterInformation" "Server/Terminal/AfterInformation.tsx"
REMOVE_REACT "$Components_Server_Terminal_CommandRow" "Server/Terminal/CommandRow.tsx"
REMOVE_REACT "$Components_Server_Terminal_AfterContent" "Server/Terminal/AfterContent.tsx"
REMOVE_REACT "$Components_Server_Files_Browse_BeforeContent" "Server/Files/Browse/BeforeContent.tsx"
REMOVE_REACT "$Components_Server_Files_Browse_FileButtons" "Server/Files/Browse/FileButtons.tsx"
REMOVE_REACT "$Components_Server_Files_Browse_DropdownItems" "Server/Files/Browse/DropdownItems.tsx"
REMOVE_REACT "$Components_Server_Files_Browse_AfterContent" "Server/Files/Browse/AfterContent.tsx"
REMOVE_REACT "$Components_Server_Files_Edit_BeforeEdit" "Server/Files/Edit/BeforeEdit.tsx"
REMOVE_REACT "$Components_Server_Files_Edit_AfterEdit" "Server/Files/Edit/AfterEdit.tsx"
REMOVE_REACT "$Components_Server_Databases_BeforeContent" "Server/Databases/BeforeContent.tsx"
REMOVE_REACT "$Components_Server_Databases_AfterContent" "Server/Databases/AfterContent.tsx"
REMOVE_REACT "$Components_Server_Schedules_List_BeforeContent" "Server/Schedules/List/BeforeContent.tsx"
REMOVE_REACT "$Components_Server_Schedules_List_AfterContent" "Server/Schedules/List/AfterContent.tsx"
REMOVE_REACT "$Components_Server_Schedules_Edit_BeforeEdit" "Server/Schedules/Edit/BeforeEdit.tsx"
REMOVE_REACT "$Components_Server_Schedules_Edit_AfterEdit" "Server/Schedules/Edit/AfterEdit.tsx"
REMOVE_REACT "$Components_Server_Users_BeforeContent" "Server/Users/BeforeContent.tsx"
REMOVE_REACT "$Components_Server_Users_AfterContent" "Server/Users/AfterContent.tsx"
REMOVE_REACT "$Components_Server_Backups_BeforeContent" "Server/Backups/BeforeContent.tsx"
REMOVE_REACT "$Components_Server_Backups_DropdownItems" "Server/Backups/DropdownItems.tsx"
REMOVE_REACT "$Components_Server_Backups_AfterContent" "Server/Backups/AfterContent.tsx"
REMOVE_REACT "$Components_Server_Network_BeforeContent" "Server/Network/BeforeContent.tsx"
REMOVE_REACT "$Components_Server_Network_AfterContent" "Server/Network/AfterContent.tsx"
REMOVE_REACT "$Components_Server_Startup_BeforeContent" "Server/Startup/BeforeContent.tsx"
REMOVE_REACT "$Components_Server_Startup_AfterContent" "Server/Startup/AfterContent.tsx"
REMOVE_REACT "$Components_Server_Settings_BeforeContent" "Server/Settings/BeforeContent.tsx"
REMOVE_REACT "$Components_Server_Settings_AfterContent" "Server/Settings/AfterContent.tsx"
# account
REMOVE_REACT "$Components_Account_Overview_BeforeContent" "Account/Overview/BeforeContent.tsx"
REMOVE_REACT "$Components_Account_Overview_AfterContent" "Account/Overview/AfterContent.tsx"
REMOVE_REACT "$Components_Account_API_BeforeContent" "Account/API/BeforeContent.tsx"
REMOVE_REACT "$Components_Account_API_AfterContent" "Account/API/AfterContent.tsx"
REMOVE_REACT "$Components_Account_SSH_BeforeContent" "Account/SSH/BeforeContent.tsx"
REMOVE_REACT "$Components_Account_SSH_AfterContent" "Account/SSH/AfterContent.tsx"
rm -R \
".blueprint/extensions/$identifier/components" \
"resources/scripts/blueprint/extensions/$identifier"
YARN="y"
fi
# Remove custom routes
PRINT INFO "Unlinking navigation routes.."
sed -i \
-e "s/\/\* ${identifier^}ImportStart \*\/.*\/\* ${identifier^}ImportEnd \*\///" \
-e "s~/\* ${identifier^}ImportStart \*/~~g" \
-e "s~/\* ${identifier^}ImportEnd \*/~~g" \
\
-e "s/\/\* ${identifier^}AccountRouteStart \*\/.*\/\* ${identifier^}AccountRouteEnd \*\///" \
-e "s~/\* ${identifier^}AccountRouteStart \*~~g" \
-e "s~/\* ${identifier^}AccountRouteEnd \*~~g" \
\
-e "s/\/\* ${identifier^}ServerRouteStart \*\/.*\/\* ${identifier^}ServerRouteEnd \*\///" \
-e "s~/\* ${identifier^}ServerRouteStart \*~~g" \
-e "s~/\* ${identifier^}ServerRouteEnd \*~~g" \
\
"resources/scripts/blueprint/extends/routers/routes.ts"
# Remove views folder
if [[ $requests_views != "" ]]; then
PRINT INFO "Removing and unlinking views folder.."
rm -R \
".blueprint/extensions/$identifier/views" \
"resources/views/blueprint/extensions/$identifier"
fi
# Remove controllers folder
if [[ $requests_controllers != "" ]]; then
PRINT INFO "Removing and unlinking controllers folder.."
rm -R \
".blueprint/extensions/$identifier/controllers" \
"app/BlueprintFramework/Extensions/$identifier"
fi
# Remove router files
if [[ $requests_routers != "" ]] \
|| [[ $requests_routers_application != "" ]] \
|| [[ $requests_routers_client != "" ]] \
|| [[ $requests_routers_web != "" ]]; then
PRINT INFO "Removing and unlinking router files.."
rm -r \
".blueprint/extensions/$identifier/routers" \
"routes/blueprint/application/$identifier.php" \
"routes/blueprint/client/$identifier.php" \
"routes/blueprint/web/$identifier.php" \
&>> "$BLUEPRINT__DEBUG"
fi
# Remove console folder
if [[ $data_console != "" ]]; then # further expand on this if needed
PRINT INFO "Removing and unlinking console folder.."
rm -R \
".blueprint/extensions/$identifier/console" \
"app/Console/Commands/BlueprintFramework/Extensions/${identifier^}" \
"app/BlueprintFramework/Schedules/${identifier^}Schedules.php" \
2>> "$BLUEPRINT__DEBUG"
fi
# Remove private folder
PRINT INFO "Removing and unlinking private folder.."
rm -R ".blueprint/extensions/$identifier/private"
# Remove public folder
if [[ $data_public != "" ]]; then
PRINT INFO "Removing and unlinking public folder.."
rm -R \
".blueprint/extensions/$identifier/public" \
"public/extensions/$identifier"
fi
# Remove assets folder
PRINT INFO "Removing and unlinking assets folder.."
rm -R \
".blueprint/extensions/$identifier/assets" \
"public/assets/extensions/$identifier"
# Remove extension filesystem (ExtensionFS)
PRINT INFO "Removing and unlinking extension filesystem.."
rm -r \
".blueprint/extensions/$identifier/fs" \
"storage/extensions/$identifier"
sed -i \
-e "s/\/\* ${identifier^}Start \*\/.*\/\* ${identifier^}End \*\///" \
-e "s~/\* ${identifier^}Start \*/~~g" \
-e "s~/\* ${identifier^}End \*/~~g" \
"config/ExtensionFS.php"
# Remove extension directory
PRINT INFO "Removing extension folder.."
rm -R ".blueprint/extensions/$identifier"
# Rebuild panel
if [[ $YARN == "y" ]]; then
PRINT INFO "Rebuilding panel assets.."
yarn run build:production --progress
fi
# Link filesystems
PRINT INFO "Linking filesystems.."
php artisan storage:link &>> "$BLUEPRINT__DEBUG"
# Flush cache.
PRINT INFO "Flushing view, config and route cache.."
{
php artisan view:cache
php artisan config:cache
php artisan route:clear
php artisan cache:clear
} &>> "$BLUEPRINT__DEBUG"
# Make sure all files have correct permissions.
PRINT INFO "Changing Pterodactyl file ownership to '$OWNERSHIP'.."
find "$FOLDER/" \
-path "$FOLDER/node_modules" -prune \
-o -exec chown "$OWNERSHIP" {} + &>> "$BLUEPRINT__DEBUG"
# Remove from installed list
PRINT INFO "Removing '$identifier' from active extensions list.."
sed -i "s~$identifier,~~g" ".blueprint/extensions/blueprint/private/db/installed_extensions"
PRINT SUCCESS "'$identifier' has been removed."
sendTelemetry "FINISH_EXTENSION_REMOVAL" >> "$BLUEPRINT__DEBUG"
}

View file

@ -0,0 +1,39 @@
#!/bin/bash
HelpCommand() {
if dbValidate "blueprint.developerEnabled"; then
help_dev_status=""
help_dev_primary="\e[34;1m"
help_dev_secondary="\e[34m"
else
help_dev_status=" (disabled)"
help_dev_primary="\x1b[2;1m"
help_dev_secondary="\x1b[2m"
fi
echo -e "
\x1b[34;1mExtensions\x1b[0m\x1b[34m
-install [name] -add -i install/update a blueprint extension
-remove [name] -r remove a blueprint extension
\x1b[0m
${help_dev_primary}Developer${help_dev_status}\x1b[0m${help_dev_secondary}
-init -I initialize development files
-build -b install/update your development files
-export (expose) -e export/download your development files
-wipe -w remove your development files
\x1b[0m
\x1b[34;1mMisc\x1b[0m\x1b[34m
-version -v returns the blueprint version
-help -h displays this menu
-info -f show neofetch-like information about blueprint
-debug [lines] print given amount of debug lines
\x1b[0m
\x1b[34;1mAdvanced\x1b[0m\x1b[34m
-upgrade (remote <url>) update/reset to another release
-rerun-install rerun the blueprint installation script
\x1b[0m
"
}

View file

@ -16,10 +16,10 @@ dbRemove() { sed -i "s/* ${1};//g" $FLDR > /dev/null; }
# === TELEMETRY === # === TELEMETRY ===
sendTelemetry() { sendTelemetry() {
cd "${BLUEPRINT__FOLDER}" || exit cd "${BLUEPRINT__FOLDER}" || return
key=$(cat .blueprint/extensions/blueprint/private/db/telemetry_id) key=$(cat .blueprint/extensions/blueprint/private/db/telemetry_id)
if [[ $key == "KEY_NOT_UPDATED" ]]; then if [[ $key == "KEY_NOT_UPDATED" ]]; then
exit 1 return 0
fi fi
curl --location --silent --connect-timeout 3 "http://api.blueprint.zip:50000/send/$key/$1" & curl --location --silent --connect-timeout 3 "http://api.blueprint.zip:50000/send/$key/$1" &
} }
@ -27,7 +27,7 @@ sendTelemetry() {
# === CACHEREMINDER === # === CACHEREMINDER ===
updateCacheReminder() { updateCacheReminder() {
cd "${BLUEPRINT__FOLDER}" || exit cd "${BLUEPRINT__FOLDER}" || return
# Overwrite previous adminCacheReminderHider with the default one. # Overwrite previous adminCacheReminderHider with the default one.
oldClassName=$(cat .blueprint/extensions/blueprint/private/db/randomclassname) oldClassName=$(cat .blueprint/extensions/blueprint/private/db/randomclassname)
newClassName=$RANDOM$RANDOM$RANDOM$RANDOM newClassName=$RANDOM$RANDOM$RANDOM$RANDOM
@ -37,3 +37,14 @@ updateCacheReminder() {
sed -i "s~I0TWHOPKAB-$oldClassName~I0TWHOPKAB-$newClassName~g" .blueprint/extensions/blueprint/assets/misc/cacheOverlay-"${newClassName}".css sed -i "s~I0TWHOPKAB-$oldClassName~I0TWHOPKAB-$newClassName~g" .blueprint/extensions/blueprint/assets/misc/cacheOverlay-"${newClassName}".css
echo "$newClassName" > .blueprint/extensions/blueprint/private/db/randomclassname echo "$newClassName" > .blueprint/extensions/blueprint/private/db/randomclassname
} }
# === SHIFTARGS ===
shiftArgs() {
shift 2
args=""
for arg in "$@"; do
args+="$arg "
done
echo "$args"
}