|
8 | 8 | # to /home.
|
9 | 9 | #
|
10 | 10 |
|
11 |
| -if ! mountpoint -q /export/home; then |
12 |
| - if [ ! -L /export/home ]; then |
13 |
| - echo 'Ensuring /export/home is a symlink to /home...' |
14 |
| - if [ -e /export/home ]; then |
15 |
| - echo 'Removing existing /export/home directory...' |
16 |
| - rm -rf /export/home |
17 |
| - fi |
18 |
| - if [ ! -d /export ]; then |
19 |
| - mkdir /export |
20 |
| - fi |
21 |
| - echo 'Creating symlink: /export/home -> /home' |
22 |
| - ln -s /home /export/home |
| 11 | +# If /export/home is already a symlink to /home, do nothing |
| 12 | +if [ -L /export/home ]; then |
| 13 | + echo '/export/home is already exists. Nothing to do.' |
| 14 | + exit 0 |
| 15 | +fi |
| 16 | + |
| 17 | +# If it's still a mount point, abort to avoid potential data loss |
| 18 | +if mountpoint -q /export/home; then |
| 19 | + echo '/export/home is still mounted. Aborting to avoid risk of data loss.' |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +# If /export/home exists as a directory, check if it is safe to remove |
| 24 | +if [ -e /export/home ]; then |
| 25 | + echo 'Found existing /export/home. Checking if it is safe to remove.' |
| 26 | + if rmdir /export/home 2>/dev/null; then |
| 27 | + echo '/export/home was empty and removed successfully.' |
| 28 | + else |
| 29 | + echo 'Error: /export/home is not empty. Aborting to avoid accidental deletion.' |
| 30 | + exit 1 |
23 | 31 | fi
|
24 | 32 | fi
|
| 33 | + |
| 34 | +# Ensure /export directory exists |
| 35 | +mkdir -p /export |
| 36 | + |
| 37 | +# Create symlink |
| 38 | +echo 'Creating symlink: /export/home -> /home' |
| 39 | +ln -s /home /export/home |
| 40 | +if [ $? -eq 0 ]; then |
| 41 | + echo 'Symlink created successfully.' |
| 42 | +else |
| 43 | + echo 'Failed to create symlink. Please check permissions and try again.' |
| 44 | + exit 1 |
| 45 | +fi |
0 commit comments