-
Notifications
You must be signed in to change notification settings - Fork 0
/
link-DATA-drive.sh
executable file
·204 lines (181 loc) · 4.78 KB
/
link-DATA-drive.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
set -e
[ "$UID" -eq 0 ] || exec sudo bash "$0" "$@"
################################################################################################
echo Script to mount DATA drive and symlink folders
################################################################################################
## Find correct partition
#blkid
lsblk -fs
read -p "Select the partition you want to mount (e.x. sdaX with X being the partition number): " part
PART_ID=$(blkid -o value -s UUID /dev/$part)
fs_type=$(blkid -o value -s TYPE /dev/$part)
# Prompt user for folder name
read -p "Enter desired folder name: " name
if [ ! -d /mnt/$name ]; then
mkdir /mnt/$name
name=$name
fi
read -p "Enter owner/user name: " user_name
echo Taking ownership of DATA partition
if [[ $(findmnt -M /mnt/$name) ]]; then
echo "Already mounted"
## see if this fixes permission issues when trying to run script again.
chown -R $user_name: /mnt/$name
else
mount /dev/$part /mnt/$name
chown -R $user_name: /mnt/$name
fi
echo "---------done---------"
echo "---------checking for existing folders"
#Desktop
if [ ! -d /mnt/$name/Desktop ]; then
mkdir /mnt/$name/Desktop
else
echo "Desktop folder exists"
fi
#Documents
if [ ! -d /mnt/$name/Documents ]; then
mkdir /mnt/$name/Documents
else
echo "Documents folder exists"
fi
#Downloads
if [ ! -d /mnt/$name/Downloads ]; then
mkdir /mnt/$name/Downloads
else
echo "Downloads folder exists"
fi
#Music
if [ ! -d /mnt/$name/Music ]; then
mkdir /mnt/$name/Music
else
echo "Music folder exists"
fi
#Pictures
if [ ! -d /mnt/$name/Pictures ]; then
mkdir /mnt/$name/Pictures
else
echo "Pictures folder exists"
fi
#Videos
if [ ! -d /mnt/$name/Videos ]; then
mkdir /mnt/$name/Videos
else
echo "Videos folder exists"
fi
#Git
if [ ! -d /mnt/$name/Nextcloud ]; then
mkdir /mnt/$name/Nextcloud
else
echo "Git folder exists"
fi
#Games
if [ ! -d /mnt/$name/Games ]; then
mkdir /mnt/$name/Games
else
echo "Games folder exists"
fi
#GameShortcuts
#if [ ! -d /mnt/$name/GameShortcuts ]; then
# mkdir /mnt/$name/GameShortcuts
#else
# echo "GameShortcuts folder exists"
#fi
#Applications
if [ ! -d /mnt/$name/Applications ]; then
mkdir /mnt/$name/Applications
else
echo "Applications folder exists"
fi
if [ ! -d /mnt/$name/.ssh ]; then
mkdir /mnt/$name/.ssh
else
echo ".ssh folder exists"
fi
echo "---------done---------"
#################################################
echo "Removing default home folders"
if [ ! -d /home/$user_name/Documents ]; then
echo "Documents removed"
else
rm -R /home/$user_name/Documents
fi
if [ ! -d /home/$user_name/Desktop ]; then
echo "Documents removed"
else
rm -R /home/$user_name/Desktop
fi
if [ ! -d /home/$user_name/Downloads ]; then
echo "Downloads removed"
else
rm -R /home/$user_name/Downloads
fi
if [ ! -d /home/$user_name/Music ]; then
echo "Music removed"
else
rm -R /home/$user_name/Music
fi
if [ ! -d /home/$user_name/Nextcloud ]; then
echo "Nextcloud removed"
else
rm -R /home/$user_name/Nextcloud
fi
if [ ! -d /home/$user_name/Pictures ]; then
echo "Pictures removed"
else
rm -R /home/$user_name/Pictures
fi
if [ ! -d /home/$user_name/Videos ]; then
echo "Videos removed"
else
rm -R /home/$user_name/Videos
fi
echo "---------done---------"
######################################################
echo "Symlinking DATA folders"
if [ ! -d /home/$user_name/Documents ]; then
ln -s /mnt/$name/Documents /home/$user_name
fi
if [ ! -d /home/$user_name/Desktop ]; then
ln -s /mnt/$name/Desktop /home/$user_name
fi
if [ ! -d /home/$user_name/Downloads ]; then
ln -s /mnt/$name/Downloads /home/$user_name
fi
if [ ! -d /home/$user_name/Games ]; then
ln -s /mnt/$name/Games /home/$user_name
fi
#if [ ! -d /home/$user_name/GameShortcuts ]; then
# ln -s /mnt/$name/GameShortcuts /home/$user_name
#fi
if [ ! -d /home/$user_name/Music ]; then
ln -s /mnt/$name/Music /home/$user_name
fi
if [ ! -d /home/$user_name/Pictures ]; then
ln -s /mnt/$name/Pictures /home/$user_name
fi
if [ ! -d /home/$user_name/Videos ]; then
ln -s /mnt/$name/Videos /home/$user_name
fi
if [ ! -d /home/$user_name/Nextcloud ]; then
ln -s /mnt/$name/Nextcloud /home/$user_name
fi
if [ ! -d /home/$user_name/Applications ]; then
ln -s /mnt/$name/Applications /home/$user_name
fi
if [ ! -d /home/$user_name/.ssh ]; then
ln -s /mnt/$name/.ssh /home/$user_name
fi
echo "---------done---------"
chown -R $user_name: /mnt/$name
###########################################################################################################
echo "adding DATA part UUID to fstab"
if grep -Fxq "UUID=$PART_ID /mnt/$name $fs_type defaults,noatime 0 2" /etc/fstab; then
echo "Already in fstab"
else
#name=DATA #removed hoping the change above in assigning #name to variable name will work
echo "UUID=$PART_ID /mnt/$name $fs_type defaults,noatime 0 2" >> /etc/fstab
fi
echo "---------done---------"
echo "DATA successfully linked"