Ich bekomme immer einen Fehler für meine erste Zeile, aber ich bin mir nicht sicher warum genau. Ich nehme an, dass sh Array nicht erlaubt, zumindest nicht in der aktuellen Form. Gibt es einen Workaround dafür? Mein gesamtes Skript hängt davon ab. Jede Hilfe und/oder Einsicht würde sehr geschätzt werden.Ein Array in sh für Android definieren
Hier ist mein Fehler, Linie 292 das erste Bit des Skripts ist:
/tmp/updater: line 297: syntax error: unexpected "("
Updater process ended with ERROR: 2
Script:
#!/sbin/sh
FILE_PATHS=(
"/main"
)
EXTRACT_DIR="/tmp/dax"
BACKUP_DIR="/data/local/tmp/dax"
CP_LOG="cp.log"
EXEMPT_LOG="exempt.log"
BACKUP_LOG="backup.log"
BUILD_VERSION=`grep "^ro\.build\.fingerprint" /system/build.prop`
FLASHABLE_VERSION="0.9.1"
EXCLUDE=(
"/system/addon.d"
"/system/app"
"/system/etc/init.d"
"/su.d"
)
BACKUP=true
if [[ -d $BACKUP_DIR ]] then
if [[ $BUILD_VERSION == `cat $BACKUP_DIR"rom_version.txt"` && $FLASHABLE_VERSION == `cat $BACKUP_DIR"flashable_version.txt"` ]] then
BACKUP=false
RESTORE=true
else
# Build Versions don't match, get rid of the backup and let it rebuild
rm -rf $BACKUP_DIR
fi
fi
function restoreBackup() {
while IFS= read -r line
do
if [[ -f $line ]] then
echo rm $line
if [[ $line == `grep "^$line$" $BACKUP_DIR$BACKUP_LOG` ]] then
cp_perm 0 0 0755 $BACKUP_DIR$line $line
fi
elif [[ -d $line ]] then
# This is where you would need to do mkdir and such
if [[ $line == `grep "^$line$" $BACKUP_DIR$BACKUP_LOG` ]] then
mkdir -p $line
cp_perm 0 0644 BACKUP_DIR$line $line
fi
fi
done < $1
}
if [[ $1 == "uninstall" ]] then
restoreBackup $BACKUP_DIR$CP_LOG
rm -rf $BACKUP_DIR
exit
fi
if [[ $RESTORE == 1 ]] then
restoreBackup $BACKUP_DIR$CP_LOG
fi
mkdir -p $BACKUP_DIR
function checkExclusions() {
if [[ -f $1 ]] then
DNAME=`dirname $1`
fi
exists=0
for match in "${EXCLUDE[@]}"
do
if [[ $1 == $match || $DNAME == $match ]] then
exists=1
fi
done
return $exists
}
function populateLog() {
for i in `find $1 -type d`; do
checkExclusions $i
if [[ $? == 0 ]] then
echo ${i#$EXTRACT_DIR} >> $CP_LOG
elif [[ $? == 1 ]] then
echo ${i#$EXTRACT_DIR} >> $EXEMPT_LOG
fi
done
for i in `find $1 -type f`; do
# Check that the file isn't in an exempt path
checkExclusions $i
if [[ $? == 0 ]] then
echo ${i#$EXTRACT_DIR} >> $CP_LOG
elif [[ $? == 1 ]] then
echo ${i#$EXTRACT_DIR} >> $EXEMPT_LOG
fi
done
}
function readLog() {
if [[ $BACKUP == true ]] then
echo $BUILD_VERSION > $BACKUP_DIR"rom_version.txt"
echo $FLASHABLE_VERSION > $BACKUP_DIR"flashable_version.txt"
fi
while IFS= read -r line
do
if [[ -f $EXTRACT_DIR$line ]] then
if [[ -f $EXTRACT_DIR$line && $BACKUP == true ]] then
# Backup the files if they exist. Permissions don't matter here.
cp $line $BACKUP_DIR$line
echo $line >> $BACKUP_LOG
fi
cp_perm 0 0 0755 $EXTRACT_DIR$line $line
elif [[ -d $EXTRACT_DIR$line ]] then
if [[ -d $line && $BACKUP == true ]] then
# Backup the Directories if they exist
mkdir -p $BACKUP_DIR$line
echo $line >> $BACKUP_LOG
fi
mkdir -p $line
cp_perm 0 0644 $EXTRACT_DIR$line $line
fi
done < $1
}
for mpath in "${FILE_PATHS[@]}"
do
populateLog $mpath
done
readLog $CP_LOG
# Backup the $CP_LOG so that we can remove files we added during an uninstall
sort -o $BACKUP_DIR$CP_LOG $CP_LOG
sort -o $BACKUP_DIR$EXEMPT_LOG $EXEMPT_LOG
sort -o $BACKUP_DIR$BACKUP_LOG $BACKUP_LOG
rm *.log