You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
shownotes-w3m-rice/timecapsule-handler-account

100 lines
4.6 KiB
Bash

#!/usr/bin/env sh
### _ _ _ _
### __ _ ___ | |_| |__ | | ___| |_ _ _
### / _` |/ _ \| __| '_ \| |/ _ \ __| | | |
###| (_| | (_) | |_| |_) | | __/ |_| |_| |
### \__, |\___/ \__|_.__/|_|\___|\__|\__,_|
### |___/
### https://www.youtube.com/user/gotbletu
### https://lbry.tv/@gotbletu
### https://twitter.com/gotbletu
### https://github.com/gotbletu
###
### Author : gotbletu
### Name : timecapsule-handler-account
### Version : 0.2
### Date : 2020-05-13
### Description : toggle mount and unmount apple timecapsule with account setup
### Depends On : cifs-utils sudo grep util-linux coreutils
### Video Demo : https://youtu.be/CmFrqBrNCNM
### References : https://gist.github.com/dgraziotin/4487187
### : sudo mkdir -p /mnt/timecapsule && sudo mount.cifs //192.168.1.xxx/Data /mnt/timecapsule -o user=XXXXX,password=XXXXX,sec=ntlm,vers=1.0
# script requires root access
[ "$(whoami)" != "root" ] && exec sudo -- "$0" "$@"
Color_Off='\e[0m' # Text Reset
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
# Time Capsule Settings with Accounts:
# 01_airport_main.png https://i.imgur.com/XJXCEgd.png
# 02_airport_deviceinfo.png https://i.imgur.com/ktFEX3J.png
# 03_basestation_tab.png https://i.imgur.com/4kClCzf.png
# 04_internet_tab.png https://i.imgur.com/R6KK6b0.png
# 05_internet_tab_opts.png https://i.imgur.com/mjAGIM4.png
# 06_wireless_tab.png https://i.imgur.com/ThskCXp.png
# 07_network_tab.png https://i.imgur.com/LqT4hSw.png
# 08_disks_tab.png https://i.imgur.com/ATG8QQi.png
# 09_disks_tab_visitor_account.png https://i.imgur.com/gVdrucO.png
# 10_disks_tab_admin_account.png https://i.imgur.com/ihqpUlx.png
# ONLY CHANGE THIS SECTION
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# Use IP Address or Basestation Name (Recommended: IP Address)
# 03_basestation_tab.png https://i.imgur.com/4kClCzf.png
# CAPSULE_BASESTATION_NAME="TC2TB"
CAPSULE_BASESTATION_NAME="192.168.1.XXX"
# Name of Partition
# 08_disks_tab.png https://i.imgur.com/ATG8QQi.png
CAPSULE_PARTITION="Data"
# Time Capsule Account Password
# (Stick With Basic Letter And Numbers To Make It Easy , Else Use \ To Escape Special Characters)
# 09_disks_tab_visitor_account.png https://i.imgur.com/gVdrucO.png
# 10_disks_tab_admin_account.png https://i.imgur.com/ihqpUlx.png
ACCOUNT_USER="visitor"
ACCOUNT_PASS="0123456789"
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# Where To Mount Time Capsule (Dont Use Spaces In Path, It Will Auto Create Folder)
MOUNT_POINT_PARTITION="/mnt/${CAPSULE_BASESTATION_NAME}_${CAPSULE_PARTITION}"
MOUNT_POINT_USER="/mnt/${CAPSULE_BASESTATION_NAME}_${ACCOUNT_USER}"
# toggle mount and unmount of Time Capsule
IS_MOUNTED=$(mount 2> /dev/null | grep "$MOUNT_POINT_PARTITION" | cut -d' ' -f3)
if [ "$IS_MOUNTED" ]; then
umount "$MOUNT_POINT_PARTITION"
rmdir "$MOUNT_POINT_PARTITION"
umount "$MOUNT_POINT_USER"
rmdir "$MOUNT_POINT_USER"
else
mkdir -p "$MOUNT_POINT_PARTITION"
mkdir -p "$MOUNT_POINT_USER"
mount.cifs "//$CAPSULE_BASESTATION_NAME/$CAPSULE_PARTITION" "$MOUNT_POINT_PARTITION" -o user="$ACCOUNT_USER",pass="$ACCOUNT_PASS",file_mode=0777,dir_mode=0777,sec=ntlm,vers=1.0
mount.cifs "//$CAPSULE_BASESTATION_NAME/$ACCOUNT_USER" "$MOUNT_POINT_USER" -o user="$ACCOUNT_USER",pass="$ACCOUNT_PASS",file_mode=0777,dir_mode=0777,sec=ntlm,vers=1.0
fi
# check if mounted folders has files inside it (aka is NETWORK MOUNTED CORRECTLY)
# doesnt work if you have no files in your PARTITION folders
IS_MOUNTED_PARTITION=$(ls $MOUNT_POINT_PARTITION 2> /dev/null | wc -l)
if [ "$IS_MOUNTED_PARTITION" -gt 0 ]; then
printf "\033c"
printf "%b\n" ">>> ${Green}Your Apple Time Capsule Is Mounted at: ${Color_Off}"
printf "%b\n" "\t $MOUNT_POINT_PARTITION"
printf "%b\n" "\t $MOUNT_POINT_USER"
printf "%b\n" ">>> ${Yellow}Run Script Again If You Wish To Unmount${Color_Off}"
fi
# check if folder exist (aka IS NOT MOUNTED)
if [ ! -d "$MOUNT_POINT_USER" ]; then
printf "\033c"
printf "%b\n" ">>> ${Red}Your Apple Time Capsule Is Unmounted${Color_Off}"
printf "%b\n" ">>> ${Yellow}Run Script Again If You Wish To Mount${Color_Off}"
fi