Created
March 4, 2019 11:10
-
-
Save jhsea3do/d6f4acafae1f595b183cd35ce2191a4d to your computer and use it in GitHub Desktop.
s3 init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo ${1:-"AccessKeyId:SecretAccessKey"} | tee /root/.passwd-s3fs | |
sudo sh s3init.sh "mybucket" "https://s3.wasabisys.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
S3BUKT=${1:-""} | |
S3SITE=${2:-""} | |
S3CRED=${3:-""} | |
S3PATH=/media/s3/$S3BUKT | |
S3TEMP=/tmp/s3fs | |
FSCONF=/etc/fstab | |
S3PWDF=/etc/passwd-s3fs | |
S3PWDT=$HOME/.passwd-s3fs | |
[ -z "$S3SITE" ] && echo '! please input s3 site url ' && exit 1 | |
[ -z "$S3BUKT" ] && echo '! please input s3 bucket name' && exit 1 | |
[ -z "$S3CRED" ] && [ -f "$S3PWDT" ] && S3CRED=$(cat $S3PWDT) | |
[ -z "$S3CRED" ] && echo '! please input s3 credential' && exit 1 | |
[ ! $(id -u) -eq 0 ] && echo '! please run as root' && exit 2 | |
[ -x "/usr/bin/yum" ] && yum install -y s3fs-fuse | |
[ -x "/usr/bin/apt" ] && apt install -y s3fs | |
if [ "$(cat $FSCONF | grep ^s3fs\#"${S3BUKT}" | wc -l )" -eq 0 ]; then | |
cat >>$FSCONF<<EOF | |
s3fs#${S3BUKT} ${S3PATH} fuse _netdev,allow_other,url=${S3SITE},use_cache=${S3TEMP} 0 0 | |
EOF | |
else | |
cat $FSCONF | grep ^s3fs\#${S3BUKT} | |
fi | |
if [ "$(cat $S3PWDF | grep ^"$S3CRED"$ | wc -l )" -eq 0 ]; then | |
cat >>$S3PWDF<<EOF | |
$S3CRED | |
EOF | |
else | |
cat $S3PWDF | grep $S3CRED | |
fi | |
chmod 600 $S3PWDF | |
umount $S3PATH || echo "! can not umount $S3PATH" | |
mount $S3PATH || echo "! can not mount $3PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment