88# to /home.
99#
1010
11-
1211# If /export/home is already a symlink to /home, do nothing
1312if [ -L /export/home ]; then
14- echo ' /export/home is already exists. Nothing to do.'
15- exit 0
13+ echo ' /export/home is already exists. Nothing to do.'
14+ exit 0
1615fi
1716
1817# if /export/home and /home both are mounted - Dont do anything
1918# Since during the next boot /export/home will not be mounted
2019# Since /export/home is there all tests will be passes
2120if mountpoint -q /export/home; then
22- echo ' /export/home is still mounted. Check if /home is also mounted'
23- if mountpoint -q /home; then
24- echo ' /home is also mounted. Since during the next boot /export/home will not be mounted, exiting safely.'
25- exit 0
26- else
27- echo ' /home is not mounted. Aborting!!'
28- exit 1
29- fi
21+ echo ' /export/home is still mounted. Check if /home is also mounted'
22+ if mountpoint -q /home; then
23+ echo ' /home is also mounted. Since during the next boot /export/home will not be mounted, exiting safely.'
24+ exit 0
25+ else
26+ echo ' /home is not mounted. Aborting!!'
27+ exit 1
28+ fi
3029fi
3130
3231# /export/home is not mounted, check if /home is mounted
33- # Check if /home is mounted
3432if mountpoint -q /home; then
35- echo " /home is mounted. Proceeding with /export/home cleanup."
36- # If /export/home exists
37- if [ -d /export/home ]; then
38- echo " /export/home exists. Attempting to remove it..."
39- rmdir /export/home 2> /dev/null
40- if [ $? -eq 0 ]; then
41- echo " /export/home directory removed successfully."
42- else
43- echo " /export/home is not empty. Please clean it manually before running this script."
44- exit 1
45- fi
46- fi
33+ echo " /home is mounted. Proceeding with /export/home cleanup."
34+ # If /export/home exists
35+ if [ -d /export/home ]; then
36+ echo " /export/home exists. Attempting to remove it..."
37+ rmdir /export/home 2> /dev/null
38+ if [ $? -eq 0 ]; then
39+ echo " /export/home directory removed successfully."
40+ else
41+ # If rmdir fails, it means /export/home is not empty
42+ # Move contents to a backup location for a seamless user experience.
43+ echo " /export/home is not empty. Moving contents to /export/home.backup before cleanup..."
44+ backup_dir=" /export/home.backup.$( date +%Y%m%d_%H%M%S) "
45+ mv /export/home " $backup_dir "
46+ if [ $? -ne 0 ]; then
47+ echo " Failed to move /export/home contents to backup. Manual intervention required."
48+ exit 1
49+ fi
50+ echo " Contents of /export/home moved successfully to: $backup_dir "
51+ fi
52+ fi
4753else
48- echo " /home is not mounted. Aborting to avoid risk of data loss."
49- exit 1
54+ echo " /home is not mounted. Aborting to avoid risk of data loss."
55+ exit 1
5056fi
5157
5258# Ensure /export exists
@@ -56,8 +62,8 @@ mkdir -p /export
5662echo " Creating symlink: /export/home -> /home"
5763ln -s /home /export/home
5864if [ $? -eq 0 ]; then
59- echo " Symlink created successfully."
65+ echo " Symlink created successfully."
6066else
61- echo " Failed to create symlink. Please check permissions and try again."
62- exit 1
67+ echo " Failed to create symlink. Please check permissions and try again."
68+ exit 1
6369fi
0 commit comments