Skip to content

Commit 8471662

Browse files
committed
fix: rollback on installation errors
1 parent 33b5664 commit 8471662

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

bin/fl-install

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
echo "Installing Flarum..."
44

5+
# Trap errors
6+
trap 'echo "An error occurred. Exiting..." && rollback && exit 1' ERR
7+
58
# Prepare installation inputs
69
cat <<EOF > install.yml
710
debug: true
@@ -34,6 +37,8 @@ if [ -d "../framework" ]; then
3437

3538
# Set minimum-stability to dev
3639
composer config minimum-stability dev
40+
# Set prefer-stable to true
41+
composer config prefer-stable true
3742
fi
3843

3944
# Download dependencies
@@ -47,3 +52,28 @@ rm install.yml
4752

4853
# Replace config.php with .config.php to always use the environment variables
4954
cp .config.php config.php
55+
56+
# Undo trap
57+
trap - ERR
58+
59+
echo "Flarum installed successfully!"
60+
61+
# A function to revert all changes made by this script
62+
function rollback() {
63+
# Move the config.php back
64+
mv config.php .config.php
65+
66+
# Undo composer install
67+
rm -rf vendor
68+
rm composer.lock
69+
70+
# Undo the workbench
71+
studio unload "../workbench/*"
72+
73+
# Undo the framework
74+
if [ -d "../framework" ]; then
75+
studio unload "../framework/framework/*"
76+
studio unload "../framework/extensions/*"
77+
studio unload "../framework/php-packages/*"
78+
fi
79+
}

0 commit comments

Comments
 (0)