Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

05 September 2016

shell script to import certificates into java cacerts

I am not the original author, I just some small enhancements



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /bin/bash

if [ $# -eq 0 ]; then
    echo -e "usage: $0 <host>\nexample: $0 abc.com"
    exit -1
fi

KEYTOOL=../../bin/keytool
HOST=$1
PORT=443
KEYSTOREFILE=cacerts
KEYSTOREFILE_BKUP=$KEYSTOREFILE.`date '+%Y%m%d%H%M'`.'original'
KEYSTOREPASS=changeit

if [ ! -f $KEYSTOREFILE ]; then
    echo -e "You must run this script from the directory jdk/jre/lib/security"
    exit -1
fi

#backup the cacerts file
echo -e "\n\n**** BAKCING UP THE $KEYSTOREFILE TO $KEYSTOREFILE_BKUP ****\n\n"
cp $KEYSTOREFILE $KEYSTOREFILE_BKUP


# get the SSL certificate
echo -e "\n\n**** SAVING THE CERTIFCATE TO ${HOST}.cert ****\n\n"
openssl s_client -connect ${HOST}:${PORT} </dev/null \
    | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ${HOST}.cert

echo -e "\n\n**** USING keytool AT $KEYTOOL ****\n\n"

# create a keystore and import certificate
echo -e "\n\n**** IMPORTING THE CERTIFICATE... ****\n\n"
"$KEYTOOL" -import -noprompt -trustcacerts \
    -alias ${HOST} -file ${HOST}.cert \
    -keystore ${KEYSTOREFILE} -storepass ${KEYSTOREPASS}

echo -e "\n\n**** PRINTING THE CERTIFICATE AFTER IMPORTED ... ****\n\n"
# verify we've got it.
"$KEYTOOL" -list -v -keystore ${KEYSTOREFILE} -storepass ${KEYSTOREPASS} -alias ${HOST} | grep --color=always $HOST

30 July 2016

Hide and Unhide Plex Media Servers Libraries

Plex media server is a famous media server, I use it at home to set local media server for myself and family.

However, to be able to hide some Libraries is not straightforward,  as it is not supported by the app itself, and there's a plugin that allows you to do so for 1 Library for free and pay for the others (It called Lock for Plex).

I used this extension and find out how it works, and I hacked it and be able to hide more than one Library.

How "Lock for Plex" work is by updating the database used by Plex.

It uses two bash files, one for lock and the other for unlock:


Plex Media Server/Plug-ins/Lock_for_Plex.bundle/Contents/Resources/lock_support/lock.sh

Plex Media Server/Plug-ins/Lock_for_Plex.bundle/Contents/Resources/lock_support/unlock.sh

Here's the content for myself after I've been modified on this file:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
cat lock.sh
#!/bin/bash


lockplex="UPDATE metadata_items SET metadata_type=20 WHERE library_section_id=2 and metadata_type=1; DELETE FROM library_sections WHERE id=2;"
lockplex2="UPDATE metadata_items SET metadata_type=4444 WHERE library_section_id=8 and metadata_type=4; DELETE FROM library_sections WHERE id=8;"

cd "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Lock_for_Plex.bundle/Contents/Resources/lock_support/"

./sqlite3 "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" "$lockplex" 
./sqlite3 "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" "$lockplex2" 

exit;
mhewedy@probook:~$ cat unlock.sh 
#!/bin/bash

unlockplex="UPDATE metadata_items SET metadata_type=1 WHERE library_section_id=2 and metadata_type=20; INSERT OR REPLACE INTO library_sections (id,name,section_type,language,agent,scanner,created_at,updated_at,scanned_at,user_fields,uuid) VALUES (2,'English Movies',1,'en','com.plexapp.agents.imdb','Plex Movie Scanner','2016-07-03 07:27:07','2016-07-03 08:35:21','2016-07-03 08:35:21','pr%3AenableCinemaTrailers=0&pr%3AincludeInGlobal=0','c07640f7-a137-4987-95ba-c3c5850383d3');"

unlockplex2="UPDATE metadata_items SET metadata_type=4 WHERE library_section_id=8 and metadata_type=4444; INSERT OR REPLACE INTO library_sections (id,name,section_type,language,agent,scanner,created_at,updated_at,scanned_at,user_fields,uuid) VALUES (8,'TV Shows',2,'en','com.plexapp.agents.thetvdb','Plex Movie Scanner','2016-07-07 03:45:33','2016-07-07 03:45:55','2016-07-13 21:03:02','pr%3AincludeInGlobal=0','0d670ea9-0da4-4639-8f52-2fcd64f3d8c8');"

cd "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Lock_for_Plex.bundle/Contents/Resources/lock_support/"

./sqlite3 "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" "$unlockplex" 
./sqlite3 "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" "$unlockplex2" 

exit;

One other way to achieve the same result is to have some other disk partition and mount it on-demond.


27 September 2014

Ifelse shortcut

if (testCondition() && executeMe() || executeMeOtherwise());

Origin come from bash, to execute if else on a single line:
[ $# == 0 ]  && echo 'invalid input' || processInput($*)
If no parameters passed, the echo 'Invalid input' else, start processing the input.


30 May 2014

continually monitor CPU usage for a command

cmd=[m]oviecrawler;while :; do echo -ne "CPU: `ps aux | grep $cmd | awk '{print $3}'`\\r" ;  sleep 1; done

10 May 2014

refactor (find and replace in files)

If you want to refactor (find and replace in files) , you could use the following script (on your own)

https://gist.github.com/MuhammadHewedy/dab0116aa288f67d05ba

29 April 2014

Periodically change the background of Linux desktop

I've wrote a script that periodically change the background of your Linux desktop.

The script and installation description are on github=> bg_cycle

Have fun!

26 April 2014

Convert Jar files to executables on Linux

After finished the image-downloader, I find it very funny to use it to crawl the site to download different backgrounds!

But I find it uncomfortable if I use it as Java jar, so I needed to either wrap it in some shell script (very easy), or convert it into some shell executable, so to forget about the JAR file at all.

I found this command to convert any JAR to shell executable (instead of just wrapping it):

(echo '#!/usr/bin/java -jar'; cat blahblah.jar) > blah
(echo '#!/usr/bin/java -jar'; cat ImageDDL.jar) > imageddl; chmod +x imageddl

It is very awesome!

BTW, You can download the Linux executable from here imageddl!

19 January 2014

jboss7_mod_util

Because the "modules" in jboss7 is the worst thing ever, it like manage maven dependencies by hand...

I decided to write some shell scripts to help me manipulate and organize the modules..

The first script is "mod_create", to create a module....
the second script is "mod_dependency_add", to add module dependency to existing module...

My plan is to add additional scripts for example ...

"mod_modify" to add jars to existing module

Any contributions are welcome .....

The project is on github at:

https://github.com/MuhammadHewedy/jboss7_mod_util

Thanks.

12 October 2010

Shell: a script file to search a directory of Jars about which jar cointains which file?

Hi folks,

Today I am coming with some shell script that is useful if you want to need to know from a group of Jars in certain directory which one of them contains a certain file (Java class)

#! /bin/sh

path=$1
segment=$2

if [ -z "$path" ] || [ -z "$segment" ]
then
echo "Usage: $0 <path> <segment>"
exit
fi

for jar in $path/*.jar ; do echo " *** $jar *** " ; jar tf $jar| grep --color=always $segment; done;