From 9b3a9e16b77688d042a02daedf55f16edcf13ebf Mon Sep 17 00:00:00 2001 From: root Date: Fri, 1 Sep 2017 14:42:07 -0700 Subject: [PATCH] Combine the tools for better compatibility... --- iscsi_fix.sh | 51 --------------- share_fix.sh | 89 ------------------------- share_lun_ui_fix.sh | 154 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 140 deletions(-) delete mode 100644 iscsi_fix.sh delete mode 100644 share_fix.sh create mode 100755 share_lun_ui_fix.sh diff --git a/iscsi_fix.sh b/iscsi_fix.sh deleted file mode 100644 index 20ec460..0000000 --- a/iscsi_fix.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -# iscsi share fix -# use this script to rebuild default configs for shares if the ._share becomes -# broken for whatever reason. -echo "Activating iSCSI share rebuilder" -echo "Querying readynasd for list of volumes..." -x=$(rn_nml -g volumes | grep "resource-id" | sed 's/^.*id="//;s/".*//;') -number=$(echo "$x" | wc -w) -echo "$number volume(s) found." -for volume in ${x} -do - echo -n "Investigating volume /$volume..." - for i in $(find /"$volume" -maxdepth 2 -type d -name ".iscsi" | sed "s/\/.iscsi//g;s/\/$volume\///g;") - do - found=1 - path="/$volume/._share/${i}" - echo "Found /$volume/${i}... recreating configs...". - mkdir -p "$path" - cat > "$path"/iscsi.conf << EOF -comment -alert_threshold 80 -EOF - cat > "$path"/custom_snapshot_management.conf << EOF -enabled = no -retention_rule = lifetime -lifetime = 2592000 -number = 30 -nonempty_snapshots = yes -prev_versions = no -EOF - cat > "$path"/custom_snapshot_schedule.conf << EOF -........................ -........................ -........................ -........................ -........................ -........................ -........................ -EOF - cat > "$path"/snapshot.conf << EOF -0 0 0 * 0 0 0 -EOF - echo " Done with /$volume/${i}." - done - echo " Done with /$volume" -done -if [[ $found ]] -then - echo "Restarting readynasd to finish changes..." - systemctl restart readynasd -fi diff --git a/share_fix.sh b/share_fix.sh deleted file mode 100644 index c6eda7b..0000000 --- a/share_fix.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/bin/bash -# share fix -# use this script to rebuild default configs for shares if the ._share becomes -# broken for whatever reason. - -echo "Activating Share rebuilder" -echo "Querying readynasd for list of volumes..." -x=$(rn_nml -g volumes | grep "resource-id" | sed 's/^.*id="//;s/".*//;') -number=$(echo "$x" | wc -w) -echo "$number volume(s) found." -for volume in $x -do - echo -n "Investigating volume /$volume..." - for i in $(find /"$volume"/ -mindepth 1 -maxdepth 2 -type d | egrep -v "\/$volume\/home|\/$volume\/.apps|\/$volume\/.vault|\/$volume\/.purge|\/$volume\/._share|\/$volume\/.timemachine|\/$volume\/.TemporaryItems|.iscsi" | sed "s/\/$volume\///g;s/\/.*//g" | sort | uniq) - do - found=1 - path="/$volume/._share/${i}" - echo "Found /$volume/${i}... recreating configs...". - mkdir -p "$path" - echo "share" > "$path"/datasettype.conf - echo "0,0" > "$path"/recycle.conf - echo "#dashboard:available=0 \"/$volume/$i\" 127.0.0.1(ro,insecure,insecure_locks,no_subtree_check,crossmnt,anongid=99,anonuid=99,root_squash,async)" > "$path"/nfs.conf - echo "" > "$path"/snapdir.conf - echo "0 0 0 * * * 0" > "$path"/snapshot.conf - cat > "$path"/afp.conf << EOF -[$i] - available = 1 - path = /$volume/$i - admin group = admin -EOF - cat > "$path"/custom_snapshot_management.conf << EOF -enabled = no -retention_rule = lifetime -lifetime = 2592000 -number = 30 -nonempty_snapshots = yes -prev_versions = no -EOF - cat > "$path"/custom_snapshot_schedule.conf << EOF -........................ -........................ -........................ -........................ -........................ -........................ -........................ -EOF - cat > "$path"/fs.conf << EOF -compression = 0 -bitrotprotection = 0 -refquota = 0 -EOF - cat > "$path"/ftp.conf << EOF -available 0 -default_access disabled -mask -fmask -dmask -user_rw -group_rw -host_rw -user_ro -group_ro -host_ro -EOF - cat > "$path"/samba.conf << EOF -[$i] - path = /$volume/$i - comment = "$i folder" - spotlight = 0 - guest ok = 1 - admin users = +admin - writeable = 1 - follow symlinks = 1 -EOF - echo -n "Fixing permissions on files..." - cd "$path" - chown root.root datasettype.conf recycle.conf snapdir.conf snapshot.conf - chown admin.admin afp.conf fs.conf ftp.conf nfs.conf samba.conf custom_snapshot_management.conf custom_snapshot_schedule.conf - echo " done!" - echo " Done with /$volume/${i}." - done - echo " Done with /$volume" -done -if [[ $found ]] -then - echo "Restarting readynasd to finish changes..." - systemctl restart readynasd -fi diff --git a/share_lun_ui_fix.sh b/share_lun_ui_fix.sh new file mode 100755 index 0000000..50ac010 --- /dev/null +++ b/share_lun_ui_fix.sh @@ -0,0 +1,154 @@ +#!/bin/bash +# share fix +# use this script to rebuild default configs for shares if the ._share becomes +# broken for whatever reason. +unset readynasd number x volume found iscsi shares +found=0 +shares=0 +iscsi=0 +share_create() { + found=$((found+1)) + share=$((share+1)) + path="/$volume/._share/$item" + echo -e "=== Found share at /$volume/$item... recreating share configs...". + mkdir -p "$path" + echo "share" > "$path"/datasettype.conf + echo "0,0" > "$path"/recycle.conf + echo "#dashboard:available=0 \"/$volume/$item\" 127.0.0.1(ro,insecure,insecure_locks,no_subtree_check,crossmnt,anongid=99,anonuid=99,root_squash,async)" > "$path"/nfs.conf + echo "" > "$path"/snapdir.conf + echo "0 0 0 * * * 0" > "$path"/snapshot.conf + cat > "$path"/afp.conf << EOF +[$item] + available = 1 + path = /$volume/$item + admin group = admin +EOF + cat > "$path"/custom_snapshot_management.conf << EOF +enabled = no +retention_rule = lifetime +lifetime = 2592000 +number = 30 +nonempty_snapshots = yes +prev_versions = no +EOF + cat > "$path"/custom_snapshot_schedule.conf << EOF +........................ +........................ +........................ +........................ +........................ +........................ +........................ +EOF + cat > "$path"/fs.conf << EOF +compression = 0 +bitrotprotection = 0 +refquota = 0 +EOF + cat > "$path"/ftp.conf << EOF +available 0 +default_access disabled +mask +fmask +dmask +user_rw +group_rw +host_rw +user_ro +group_ro +host_ro +EOF + cat > "$path"/samba.conf << EOF +[$item] + path = /$volume/$item + comment = "$item folder" + spotlight = 0 + guest ok = 1 + admin users = +admin + writeable = 1 + follow symlinks = 1 +EOF + cd "$path" + chown root.root datasettype.conf recycle.conf snapdir.conf snapshot.conf + chown admin.admin afp.conf fs.conf ftp.conf nfs.conf samba.conf custom_snapshot_management.conf custom_snapshot_schedule.conf + echo " Done with /$volume/$item." +} + +iscsi_create() { + iscsi=$((iscsi+1)) + found=$((found+1)) + path="/$volume/._share/$item" + echo -e "=== Found LUN at /$volume/$item... recreating iSCSI configs...". + mkdir -p "$path" + cat > "$path"/iscsi.conf << EOF +comment +alert_threshold 80 +EOF + cat > "$path"/custom_snapshot_management.conf << EOF +enabled = no +retention_rule = lifetime +lifetime = 2592000 +number = 30 +nonempty_snapshots = yes +prev_versions = no +EOF + cat > "$path"/custom_snapshot_schedule.conf << EOF +........................ +........................ +........................ +........................ +........................ +........................ +........................ +EOF + cat > "$path"/snapshot.conf << EOF +0 0 0 * 0 0 0 +EOF + echo " Done with /$volume/$item." + + +} + + +echo "===============================" +echo "Share and iSCSI Rebuild v6.8.0" +echo "===============================" +echo "Querying readynasd for list of volumes..." + +x=$(rn_nml -g volumes 2>/dev/null) # find if readynasd is running + +if [[ $? -eq 0 ]]; then # if readynasd was successful + x=$(echo "$x"| grep "resource-id" | sed 's/^.*id="//;s/".*//;') # then parse it + readynasd=1 +elif [[ $? -eq 1 ]] ; then # but if it wasn't + echo "readynasd not available; doing alternative lookup for shares" # inform intent + x=$(find / -maxdepth 2 -name "._share" | sed 's/^\///g;s/\/.*//') # create new list +fi + +number=$(echo "$x" | wc -w) +echo "$number volume(s) found." +echo -n "Beginning in 3..."; sleep 1; echo -n " 2..."; sleep 1; echo -n " 1..."; sleep 1 +echo "===============================" +echo "=== All right! Time to go! ===" +echo "===============================" +for volume in $x; do + echo "= Investigating volume /$volume..." + objects=$(ls -A /$volume | egrep -v "^.apps$|^home$|^.purge$|^._share$|^.timemachine$|^.vault$|^.TemporaryItems$") + echo "= Objects found:" $objects + for item in $objects; do + echo "== Reviewing $item" + if ls -QdA /$volume/$item/.iscsi >/dev/null 2>&1; then + iscsi_create + else + share_create + fi + done + echo "= done with /$volume=" +done + +if [[ $found -gt 0 ]] && [[ $readynasd ]] ; then + echo "Restarting readynasd to finish changes..." + systemctl restart readynasd +else + echo "Not starting readynasd because it returned a bad message earlier; restart manually." +fi