Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/nextcloudpi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornachoparker <nacho@ownyourbits.com>2017-08-31 09:45:56 +0300
committernachoparker <nacho@ownyourbits.com>2017-09-02 00:32:16 +0300
commit009c82e6cfb82cc40c49a9e253fe41bbbf779b13 (patch)
tree8213b20f68cfbe2941013eef540ec95a379bfb02 /etc/library.sh
parentcfc759969a9f0afdde35689e7185d49533e6c78f (diff)
shellcheck style fixesv0.24.12
Diffstat (limited to 'etc/library.sh')
-rwxr-xr-xetc/library.sh90
1 files changed, 46 insertions, 44 deletions
diff --git a/etc/library.sh b/etc/library.sh
index b89bc76d..79d77d9f 100755
--- a/etc/library.sh
+++ b/etc/library.sh
@@ -9,8 +9,8 @@
#
-IMGNAME=$( basename $IMGFILE .img )_$( basename $INSTALL_SCRIPT .sh ).img
-CFGOUT=config_$( basename $INSTALL_SCRIPT .sh ).txt
+IMGNAME=$( basename "$IMGFILE" .img )_$( basename "$INSTALL_SCRIPT" .sh ).img
+CFGOUT=config_$( basename "$INSTALL_SCRIPT" .sh ).txt
DBG=x
# $IMGOUT will contain the name of the last step
@@ -19,23 +19,23 @@ function launch_install_qemu()
local IMG=$1
local IP=$2
[[ "$IP" == "" ]] && { echo "usage: launch_install_qemu <script> <img> <IP>"; return 1; }
- test -f $IMG || { echo "input file $IMG not found"; return 1; }
+ test -f "$IMG" || { echo "input file $IMG not found"; return 1; }
- local BASE=$( sed 's=-stage[[:digit:]]==' <<< $IMG )
- local NUM=$( sed 's=.*-stage\([[:digit:]]\)=\1=' <<< $IMG )
+ local BASE=$( sed 's=-stage[[:digit:]]==' <<< "$IMG" )
+ local NUM=$( sed 's=.*-stage\([[:digit:]]\)=\1=' <<< "$IMG" )
[[ "$BASE" == "$IMG" ]] && NUM=0
- local NUM_REBOOTS=$( grep -c reboot $INSTALL_SCRIPT )
+ local NUM_REBOOTS=$( grep -c reboot "$INSTALL_SCRIPT" )
while [[ $NUM_REBOOTS != -1 ]]; do
NUM=$(( NUM+1 ))
IMGOUT="$BASE-stage$NUM"
- cp -v $IMG $IMGOUT || return 1 # take a copy of the input image for processing ( append "-stage1" )
+ cp -v "$IMG" "$IMGOUT" || return 1 # take a copy of the input image for processing ( append "-stage1" )
pgrep qemu-system-arm &>/dev/null && { echo -e "QEMU instance already running. Abort..."; return 1; }
- launch_qemu $IMGOUT &
+ launch_qemu "$IMGOUT" &
sleep 10
- wait_SSH $IP
- launch_installation_qemu $IP || return 1
+ wait_SSH "$IP"
+ launch_installation_qemu "$IP" || return 1
wait
IMG="$IMGOUT"
NUM_REBOOTS=$(( NUM_REBOOTS-1 ))
@@ -46,12 +46,12 @@ function launch_install_qemu()
function launch_qemu()
{
local IMG=$1
- test -f $1 || { echo "Image $IMG not found"; return 1; }
+ test -f "$1" || { echo "Image $IMG not found"; return 1; }
test -d qemu-raspbian-network || git clone https://github.com/nachoparker/qemu-raspbian-network.git
sed -i '30s/NO_NETWORK=1/NO_NETWORK=0/' qemu-raspbian-network/qemu-pi.sh
sed -i '35s/NO_GRAPHIC=0/NO_GRAPHIC=1/' qemu-raspbian-network/qemu-pi.sh
echo "Starting QEMU image $IMG"
- ( cd qemu-raspbian-network && sudo ./qemu-pi.sh ../$IMG 2>/dev/null )
+ ( cd qemu-raspbian-network && sudo ./qemu-pi.sh ../"$IMG" 2>/dev/null )
}
function ssh_pi()
@@ -81,7 +81,7 @@ function wait_SSH()
local IP=$1
echo "Waiting for SSH to be up on $IP..."
while true; do
- ssh_pi $IP : && break
+ ssh_pi "$IP" : && break
sleep 1
done
echo "SSH is up"
@@ -98,7 +98,7 @@ sudo su
set -e$DBG
"
echo "Launching installation"
- echo -e "$PREINST_CODE\n$INSTALLATION_CODE\n$INSTALLATION_STEPS" | ssh_pi $IP || { echo "Installation to $IP failed" && return 1; }
+ echo -e "$PREINST_CODE\n$INSTALLATION_CODE\n$INSTALLATION_STEPS" | ssh_pi "$IP" || { echo "Installation to $IP failed" && return 1; }
echo "configuration saved to $CFGOUT"
}
@@ -114,7 +114,7 @@ $CFG_STEP
$CLEANUP_STEP
$HALT_STEP
"
- launch_installation $IP
+ launch_installation "$IP"
}
function launch_installation_online()
@@ -125,7 +125,7 @@ function launch_installation_online()
install
$CFG_STEP
"
- launch_installation $IP
+ launch_installation "$IP"
}
# Initializes $INSTALLATION_CODE
@@ -136,13 +136,13 @@ function config()
type dialog &>/dev/null || { echo "please, install dialog for interactive configuration"; return 1; }
- test -f "$INSTALL_SCRIPT" || { echo "file "$INSTALL_SCRIPT" not found"; return 1; }
+ test -f "$INSTALL_SCRIPT" || { echo "file $INSTALL_SCRIPT not found"; return 1; }
local VARS=( $( grep "^[[:alpha:]]\+_=" "$INSTALL_SCRIPT" | cut -d= -f1 | sed 's|_$||' ) )
local VALS=( $( grep "^[[:alpha:]]\+_=" "$INSTALL_SCRIPT" | cut -d= -f2 ) )
[[ "$NO_CONFIG" == "1" ]] || test ${#VARS[@]} -eq 0 && { INSTALLATION_CODE="$( cat "$INSTALL_SCRIPT" )"; return; }
- for i in `seq 1 1 ${#VARS[@]} `; do
+ for i in $( seq 1 1 ${#VARS[@]} ); do
local PARAM+="${VARS[$((i-1))]} $i 1 ${VALS[$((i-1))]} $i 15 60 0 "
done
@@ -167,7 +167,7 @@ function config()
;;
$DIALOG_OK)
local RET=( $value )
- for i in `seq 0 1 $(( ${#RET[@]} - 1 )) `; do
+ for i in $( seq 0 1 $(( ${#RET[@]} - 1 )) ); do
local SEDRULE+="s|^${VARS[$i]}_=.*|${VARS[$i]}_=${RET[$i]}|;"
local CONFIG+="${VARS[$i]}=${RET[$i]}\n"
done
@@ -188,7 +188,7 @@ function config()
esac
done
- INSTALLATION_CODE="$( sed $SEDRULE "$INSTALL_SCRIPT" )"
+ INSTALLATION_CODE="$( sed "$SEDRULE" "$INSTALL_SCRIPT" )"
[[ "$CFGOUT" != "" ]] && echo -e "$CONFIG" > "$CFGOUT"
}
@@ -196,8 +196,8 @@ function install_script()
{
(
local SCRIPT=$1
- source ./$SCRIPT
- echo -e "Installing $( basename $SCRIPT .sh )"
+ source ./"$SCRIPT"
+ echo -e "Installing $( basename "$SCRIPT" .sh )"
set +x
install
)
@@ -206,15 +206,15 @@ function install_script()
function activate_script()
{
local SCRIPT=$1
- echo -e "Activating $( basename $SCRIPT .sh )"
- launch_script $SCRIPT
+ echo -e "Activating $( basename "$SCRIPT" .sh )"
+ launch_script "$SCRIPT"
}
function launch_script()
{
(
local SCRIPT=$1
- source ./$SCRIPT
+ source ./"$SCRIPT"
set +x
configure
)
@@ -224,9 +224,9 @@ function info_script()
{
(
local SCRIPT=$1
- cd /usr/local/etc/nextcloudpi-config.d/
+ cd /usr/local/etc/nextcloudpi-config.d/ || return 1
unset show_info
- source ./$SCRIPT
+ source ./"$SCRIPT"
[[ $( type -t show_info ) == function ]] || return 0
[[ $( type -t show_info ) == function ]] && show_info
)
@@ -236,12 +236,12 @@ function configure_script()
{
(
local SCRIPT=$1
- cd /usr/local/etc/nextcloudpi-config.d/
- config $SCRIPT || return 1 # writes "$INSTALLATION_CODE"
- echo -e "$INSTALLATION_CODE" > $SCRIPT # save configuration
- source ./$SCRIPT # load configuration
- printf '\033[2J' && tput cup 0 0 # clear screen, don't clear scroll, cursor on top
- echo -e "Launching $( basename $SCRIPT .sh )"
+ cd /usr/local/etc/nextcloudpi-config.d/ || return 1
+ config "$SCRIPT" || return 1 # writes "$INSTALLATION_CODE"
+ echo -e "$INSTALLATION_CODE" > "$SCRIPT" # save configuration
+ source ./"$SCRIPT" # load configuration
+ printf '\033[2J' && tput cup 0 0 # clear screen, don't clear scroll, cursor on top
+ echo -e "Launching $( basename "$SCRIPT" .sh )"
set +x
configure
return 0
@@ -253,13 +253,15 @@ function copy_to_image()
local IMG=$1
local DST=$2
local SRC=${@: 3 }
- local SECTOR=$( fdisk -l $IMG | grep Linux | awk '{ print $2 }' )
- local OFFSET=$(( SECTOR * 512 ))
+ local SECTOR
+ local OFFSET
+ SECTOR=$( fdisk -l "$IMG" | grep Linux | awk '{ print $2 }' )
+ OFFSET=$(( SECTOR * 512 ))
[ -f "$IMG" ] || { echo "no image"; return 1; }
mkdir -p tmpmnt
- sudo mount $IMG -o offset=$OFFSET tmpmnt || return 1
- sudo cp -v $SRC tmpmnt/$DST || return 1
+ sudo mount "$IMG" -o offset="$OFFSET" tmpmnt || return 1
+ sudo cp -v "$SRC" tmpmnt/"$DST" || return 1
sudo umount -l tmpmnt
rmdir tmpmnt &>/dev/null
}
@@ -270,15 +272,15 @@ function download_resize_raspbian_img()
local IMGFILE=$2
local IMG=raspbian_lite_latest
- test -f $IMGFILE && \
+ test -f "$IMGFILE" && \
echo -e "INFO: $IMGFILE already exists. Skipping download ..." && return 0
test -f $IMG.zip || \
wget https://downloads.raspberrypi.org/$IMG -O $IMG.zip || return 1
unzip -o $IMG.zip && \
- mv *-raspbian-*.img $IMGFILE && \
- qemu-img resize -f raw $IMGFILE +$SIZE && \
+ mv *-raspbian-*.img "$IMGFILE" && \
+ qemu-img resize -f raw "$IMGFILE" +"$SIZE" && \
return 0
}
@@ -290,18 +292,18 @@ function pack_image()
echo "copying $IMGOUT → $IMGNAME"
cp "$IMGOUT" "$IMGNAME" || return 1
echo "packing $IMGNAME → $TARNAME"
- tar -I pbzip2 -cvf $TARNAME "$IMGNAME" &>/dev/null && \
+ tar -I pbzip2 -cvf "$TARNAME" "$IMGNAME" &>/dev/null && \
echo -e "$TARNAME packed successfully"
}
function create_torrent()
{
[[ "$1" == "" ]] && { echo "No directory specified"; exit 1; }
- test -d $1 || { echo "$1 not found or is not a directory" ; exit 1; }
+ test -d "$1" || { echo "$1 not found or is not a directory" ; exit 1; }
- md5sum $1/*.bz2 > $1/md5sum
+ md5sum "$1"/*.bz2 > "$1"/md5sum
- createtorrent -a udp://tracker.opentrackr.org -p 1337 -c "NextCloudPi. Nextcloud for Raspberry Pi image" $1 $1.torrent
+ createtorrent -a udp://tracker.opentrackr.org -p 1337 -c "NextCloudPi. Nextcloud for Raspberry Pi image" "$1" "$1".torrent
}
# License
#