Skip to content

Instantly share code, notes, and snippets.

@erfanoabdi
Created June 18, 2020 13:31
Show Gist options
  • Save erfanoabdi/d831d71a763ba46e7648eaedb54a9204 to your computer and use it in GitHub Desktop.
Save erfanoabdi/d831d71a763ba46e7648eaedb54a9204 to your computer and use it in GitHub Desktop.
#!/bin/bash
FILE=$1
[ -f "$FILE" ] || {
echo "Provide a config file as argument"
exit
}
write=false
if [ "$2" = "-w" ]; then
write=true
fi
CONFIGS_ON="
CONFIG_POSIX_MQUEUE
CONFIG_POSIX_MQUEUE_SYSCTL
CONFIG_NET_CLS_CGROUP
CONFIG_CGROUP_NET_CLASSID
CONFIG_VETH
CONFIG_ANBOX
CONFIG_ANBOX_BINDER_IPC
CONFIG_SQUASHFS
CONFIG_SQUASHFS_DECOMP_SINGLE
CONFIG_SQUASHFS_ZLIB
CONFIG_SQUASHFS_XZ
CONFIG_XZ_DEC
CONFIG_XZ_DEC_X86
CONFIG_XZ_DEC_POWERPC
CONFIG_XZ_DEC_IA64
CONFIG_XZ_DEC_ARM
CONFIG_XZ_DEC_ARMTHUMB
CONFIG_XZ_DEC_SPARC
CONFIG_XZ_DEC_BCJ
"
CONFIGS_OFF="
CONFIG_ANBOX_BINDER_IPC_32BIT
"
ered() {
echo -e "\033[31m" $@
}
egreen() {
echo -e "\033[32m" $@
}
ewhite() {
echo -e "\033[37m" $@
}
echo -e "\n\nChecking config file for Halium specific config options.\n\n"
errors=0
fixes=0
for c in $CONFIGS_ON $CONFIGS_OFF;do
cnt=`grep -w -c $c $FILE`
if [ $cnt -gt 1 ];then
ered "$c appears more than once in the config file, fix this"
errors=$((errors+1))
fi
if [ $cnt -eq 0 ];then
if $write ; then
ewhite "Creating $c"
echo "# $c is not set" >> "$FILE"
fixes=$((fixes+1))
else
ered "$c is neither enabled nor disabled in the config file"
errors=$((errors+1))
fi
fi
done
for c in $CONFIGS_ON;do
if grep "$c=y\|$c=m" "$FILE" >/dev/null;then
egreen "$c is already set"
else
if $write ; then
ewhite "Setting $c"
gsed -i "s,# $c is not set,$c=y," "$FILE"
fixes=$((fixes+1))
else
ered "$c is not set, set it"
errors=$((errors+1))
fi
fi
done
for c in $CONFIGS_OFF;do
if grep "$c=y\|$c=m" "$FILE" >/dev/null;then
if $write ; then
ewhite "Unsetting $c"
gsed -i "s,$c=.*,# $c is not set," $FILE
fixes=$((fixes+1))
else
ered "$c is set, unset it"
errors=$((errors+1))
fi
else
egreen "$c is already unset"
fi
done
if [ $errors -eq 0 ];then
egreen "\n\nConfig file checked, found no errors.\n\n"
else
ered "\n\nConfig file checked, found $errors errors that I did not fix.\n\n"
fi
if [ $fixes -gt 0 ];then
egreen "Made $fixes fixes.\n\n"
fi
ewhite " "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment