Add shell scripts for use by nextgen generic driver

Change-Id: I96c10740f299ddc4bccdd7f538cf1417c8a09ea2
This commit is contained in:
Ben Swartzlander 2017-10-10 16:08:10 -04:00
parent 0aa0235af2
commit ec4efbe1bb
17 changed files with 197 additions and 0 deletions

View File

@ -0,0 +1,13 @@
#!/bin/sh -e
# manila-cifs-create <cookie>
NUM=$1
MNT_PATH=/shares/$NUM
SHARE=share_$NUM
net conf addshare $SHARE $MNT_PATH writeable=y guest_ok=y
net conf setparm $SHARE browseable yes
net conf setparm $SHARE "create mask" 0755
net conf setparm $SHARE "directory mask" 0755
echo $SHARE

View File

@ -0,0 +1,7 @@
#!/bin/sh -e
# manila-cifs-delete <cookie>
NUM=$1
SHARE=share_$NUM
net conf delshare $SHARE

View File

@ -0,0 +1,16 @@
#!/bin/sh -e
# manila-cifs-resume <cookie>
NUM=$1
MNT_PATH=/shares/$NUM
SHARE=share_$NUM
net conf addshare $SHARE $MNT_PATH writeable=y guest_ok=y
PARMS_FILE=/metadata/$NUM/offline.parms
cat $PARMS_FILE | while read line
do
PARAM=$(echo $line | sed 's/\([^=]*\)=.*/\1/' | awk '{$1=$1;print}')
VALUE=$(echo $line | sed 's/.*=\([^=]*\)/\1/' | awk '{$1=$1;print}')
net conf setparm $SHARE "$PARAM" "$VALUE"
done
rm $PARMS_FILE

View File

@ -0,0 +1,8 @@
#!/bin/sh -e
# manila-cifs-suspend <cookie>
NUM=$1
SHARE=share_$NUM
net conf showshare $SHARE | sed '/^\[/d' > /metadata/$NUM/offline.parms
net conf delshare $SHARE

View File

@ -0,0 +1,14 @@
#!/bin/sh -e
# manila-cifs-update <cookie> <parms-file>
NUM=$1
PARMS_FILE=$2
SHARE=share_$NUM
cat $PARMS_FILE | while read line
do
PARAM=$(echo $line | sed 's/\([^=]*\)=.*/\1/' | awk '{$1=$1;print}')
VALUE=$(echo $line | sed 's/.*=\([^=]*\)/\1/' | awk '{$1=$1;print}')
net conf setparm $SHARE "$PARAM" "$VALUE"
done
rm $PARMS_FILE

View File

@ -0,0 +1,7 @@
#!/bin/sh -e
# manila-init
if ! pdbedit -L | grep root
then
printf "root\nroot\n" | smbpasswd -a -s root
fi

View File

@ -0,0 +1,11 @@
#!/bin/sh -e
# manila-mkfs <device-path>
DEVICE=$1
while [ ! -b $DEVICE ]
do
sleep 1
done
mkfs.ext2 $DEVICE > /dev/null

View File

@ -0,0 +1,32 @@
#!/bin/sh -e
# manila-mount <device-path> <share-uuid>
DEVICE=$1
UUID=$2
tune2fs -U $UUID $DEVICE > /dev/null
mkdir -p /shares
chmod 775 /shares
while true
do
last=$(cd /shares ; ls | sort -n | tail -n 1)
NUM=$((last+1))
MNT_PATH=/shares/$NUM
if mkdir $MNT_PATH
then
break
else
sleep 1
fi
done
chmod 000 $MNT_PATH
mkdir -p /metadata/$NUM
echo $UUID > /metadata/$NUM/UUID
echo UUID=$UUID $MNT_PATH ext2 rw 0 2 >> /etc/fstab
mount -a
chmod 775 $MNT_PATH
echo $NUM

View File

@ -0,0 +1,11 @@
#!/bin/sh -e
# manila-nfs-create <cookie>
NUM=$1
mkdir -p /etc/exports.d
EXPORTS_FILE=/etc/exports.d/$NUM.exports
rm -f $EXPORTS_FILE
touch $EXPORTS_FILE
echo /shares/$NUM

View File

@ -0,0 +1,7 @@
#!/bin/sh -e
# manila-nfs-delete <cookie>
NUM=$1
rm -f /etc/exports.d/$NUM.exports
exportfs -r

View File

@ -0,0 +1,7 @@
#!/bin/sh -e
# manila-nfs-resume <cookie>
NUM=$1
mv /metadata/$NUM/offline.exports /etc/exports.d/$NUM.exports
exportfs -r

View File

@ -0,0 +1,7 @@
#!/bin/sh -e
# manila-nfs-suspend <cookie>
NUM=$1
mv /etc/exports.d/$NUM.exports /metadata/$NUM/offline.exports
exportfs -r

View File

@ -0,0 +1,9 @@
#!/bin/sh -e
# manila-nfs-update <cookie> <exports-file>
NUM=$1
EXPORTS_FILE=$2
EXPORTS_FILE2=/etc/exports.d/$NUM.exports
mv -f $EXPORTS_FILE $EXPORTS_FILE2
exportfs -r

View File

@ -0,0 +1,13 @@
#!/bin/sh -e
# manila-post-extend <cookie> <device-path>
NUM=$1
DEVICE=$2
e2fsck -pf $DEVICE
resize2fs $DEVICE
UUID=$(cat /metadata/$NUM/UUID)
MNT_PATH=/shares/$NUM
echo UUID=$UUID $MNT_PATH ext2 rw 0 2 >> /etc/fstab
mount -a

View File

@ -0,0 +1,10 @@
#!/bin/sh -e
# manila-pre-extend <cookie>
NUM=$1
UUID=$(cat /metadata/$NUM/UUID)
sed "/$UUID/d" -i /etc/fstab
MNT_PATH=/shares/$NUM
umount $MNT_PATH

View File

@ -0,0 +1,15 @@
#!/bin/sh -e
# manila-shrink <cookie> <device> <size-in-gb>
NUM=$1
DEVICE=$2
SIZE_GB=$3
UUID=$(cat /metadata/$NUM/UUID)
sed "/$UUID/d" -i /etc/fstab
MNT_PATH=/shares/$NUM
umount $MNT_PATH
e2fsck -pf $DEVICE
resize2fs $DEVICE ${SIZE_GB}G
echo UUID=$UUID $MNT_PATH ext2 rw 0 2 >> /etc/fstab
mount -a

View File

@ -0,0 +1,10 @@
#!/bin/sh -e
# manila-unmount <cookie>
NUM=$1
UUID=$(cat /metadata/$NUM/UUID)
MNT_PATH=$(grep $UUID /etc/fstab | awk '{print $2}')
sed /$UUID/d -i /etc/fstab
umount $MNT_PATH
rmdir $MNT_PATH